net.sourceforge.pmd.rules
Class CouplingBetweenObjectsRule

java.lang.Object
  extended bynet.sourceforge.pmd.ast.JavaParserVisitorAdapter
      extended bynet.sourceforge.pmd.AbstractRule
          extended bynet.sourceforge.pmd.rules.CouplingBetweenObjectsRule
All Implemented Interfaces:
JavaParserVisitor, Rule

public class CouplingBetweenObjectsRule
extends AbstractRule

CouplingBetweenObjectsRule attempts to capture all unique Class attributes, local variables, and return types to determine how many objects a class is coupled to. This is only a guage and isn't a hard and fast rule. The threshold value is configurable and should be determined accordingly

Since:
Feb 20, 2003
Author:
aglover

Field Summary
private  java.lang.String className
           
private  int couplingCount
           
private  java.util.Set typesFoundSoFar
           
 
Fields inherited from class net.sourceforge.pmd.AbstractRule
 
Fields inherited from interface net.sourceforge.pmd.Rule
LOWEST_PRIORITY, PRIORITIES
 
Constructor Summary
CouplingBetweenObjectsRule()
           
 
Method Summary
private  void checkVariableType(java.lang.String variableType)
          performs a check on the variable and updates the couter.
private  boolean filterPrimativesAndWrappers(java.lang.String variableType)
           
private  boolean filterTypes(java.lang.String variableType)
          Filters variable type - we don't want primatives, wrappers, strings, etc.
private  void handleASTTypeChildren(SimpleNode node)
          convience method to handle hiearchy.
 java.lang.Object visit(ASTClassDeclaration node, java.lang.Object data)
          handles class declaration.
 java.lang.Object visit(ASTCompilationUnit cu, java.lang.Object data)
          handles the source file
 java.lang.Object visit(ASTFieldDeclaration node, java.lang.Object data)
          handles a field declaration - i.e.
 java.lang.Object visit(ASTFormalParameter node, java.lang.Object data)
          handles a method parameter
 java.lang.Object visit(ASTLocalVariableDeclaration node, java.lang.Object data)
          handles a local variable found in a method block
 java.lang.Object visit(ASTResultType node, java.lang.Object data)
          handles a return type of a method
 
Methods inherited from class net.sourceforge.pmd.AbstractRule
addProperty, apply, createRuleViolation, createRuleViolation, equals, getBooleanProperty, getDescription, getDoubleProperty, getExample, getIntProperty, getMessage, getName, getPriority, getPriorityName, getProperties, getStringProperty, hashCode, hasProperty, include, setDescription, setExample, setInclude, setMessage, setName, setPriority, visitAll
 
Methods inherited from class net.sourceforge.pmd.ast.JavaParserVisitorAdapter
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

className

private java.lang.String className

couplingCount

private int couplingCount

typesFoundSoFar

private java.util.Set typesFoundSoFar
Constructor Detail

CouplingBetweenObjectsRule

public CouplingBetweenObjectsRule()
Method Detail

visit

public java.lang.Object visit(ASTCompilationUnit cu,
                              java.lang.Object data)
handles the source file

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class JavaParserVisitorAdapter
Returns:
Object

visit

public java.lang.Object visit(ASTClassDeclaration node,
                              java.lang.Object data)
handles class declaration. I need this to capture class name. I think there is probably a better way to capture it; however, I don't know the framework well enough yet...

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class JavaParserVisitorAdapter
Returns:
Object

visit

public java.lang.Object visit(ASTResultType node,
                              java.lang.Object data)
handles a return type of a method

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class JavaParserVisitorAdapter
Returns:
Object

visit

public java.lang.Object visit(ASTLocalVariableDeclaration node,
                              java.lang.Object data)
handles a local variable found in a method block

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class JavaParserVisitorAdapter
Returns:
Object

visit

public java.lang.Object visit(ASTFormalParameter node,
                              java.lang.Object data)
handles a method parameter

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class JavaParserVisitorAdapter
Returns:
Object

visit

public java.lang.Object visit(ASTFieldDeclaration node,
                              java.lang.Object data)
handles a field declaration - i.e. an instance variable. Method doesn't care if variable is public/private/etc

Specified by:
visit in interface JavaParserVisitor
Overrides:
visit in class JavaParserVisitorAdapter
Returns:
Object

handleASTTypeChildren

private void handleASTTypeChildren(SimpleNode node)
convience method to handle hiearchy. This is probably too much work and will go away once I figure out the framework


checkVariableType

private void checkVariableType(java.lang.String variableType)
performs a check on the variable and updates the couter. Counter is instance for a class and is reset upon new class scan.


filterTypes

private boolean filterTypes(java.lang.String variableType)
Filters variable type - we don't want primatives, wrappers, strings, etc. This needs more work. I'd like to filter out super types and perhaps interfaces

Returns:
boolean true if variableType is not what we care about

filterPrimativesAndWrappers

private boolean filterPrimativesAndWrappers(java.lang.String variableType)
Returns:
boolean true if variableType is a primative or wrapper