KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > VariableNameClashesWithTypeNameRule


1 /*
2 @license.text
3  */

4 package org.hammurapi.inspectors;
5
6 import org.hammurapi.InspectorBase;
7
8 import com.pavelvlasov.jsel.TypeBody;
9 import com.pavelvlasov.jsel.TypeDefinition;
10 import com.pavelvlasov.jsel.VariableDefinition;
11
12
13 /**
14  * ER-200
15  * Instance variables and the declaring type shouldn't have same name
16  * @author Janos Czako
17  * @version $Revision: 1.2 $
18  */

19 public class VariableNameClashesWithTypeNameRule extends InspectorBase {
20     
21     /**
22      * Reviews the variable definitions, if they have clashing names
23      * with the class name.
24      *
25      * @param element the method definition to be reviewed.
26      */

27     public void visit(VariableDefinition element) {
28         
29         TypeBody enclosingType = element.getEnclosingType();
30         if (enclosingType instanceof TypeDefinition && ((TypeDefinition) enclosingType).getName().equals(element.getName())) {
31             context.reportViolation(element);
32         }
33     }
34     
35 }
36
Popular Tags