1 4 package com.puppycrawl.tools.checkstyle.bcel.checks; 5 6 import java.util.Iterator ; 7 import java.util.Set ; 8 9 import org.apache.bcel.classfile.Field; 10 import org.apache.bcel.classfile.JavaClass; 11 12 import com.puppycrawl.tools.checkstyle.api.Scope; 13 import com.puppycrawl.tools.checkstyle.bcel.ReferenceVisitor; 14 import com.puppycrawl.tools.checkstyle.bcel.classfile.FieldDefinition; 15 import com.puppycrawl.tools.checkstyle.bcel.classfile.JavaClassDefinition; 16 17 21 public class UnreadFieldCheck 22 extends AbstractReferenceCheck 23 { 24 25 public void setScope(String aFrom) 26 { 27 super.setScope(aFrom); 28 ((ReferenceVisitor) getVisitor()).addFieldScope( 29 Scope.getInstance(aFrom)); 30 } 31 32 33 public void leaveSet(Set aJavaClasses) 34 { 35 final Iterator it = aJavaClasses.iterator(); 36 while (it.hasNext()) { 37 final JavaClass javaClass = (JavaClass) it.next(); 38 final String className = javaClass.getClassName(); 39 final JavaClassDefinition classDef = findJavaClassDef(javaClass); 40 final FieldDefinition[] fieldDefs = classDef.getFieldDefs(); 41 for (int i = 0; i < fieldDefs.length; i++) { 42 if (fieldDefs[i].getReadReferenceCount() == 0) { 43 final Field field = fieldDefs[i].getField(); 44 if (!field.isFinal() 45 && (!ignore(className, field)) 46 ) 47 { 48 log( 49 javaClass, 50 0, 51 "unread.field", 52 new Object [] {fieldDefs[i]}); 53 } 54 } 55 } 56 } 57 } 58 } 59 | Popular Tags |