Search in sources :

Example 1 with JavaClassDefinition

use of com.puppycrawl.tools.checkstyle.bcel.classfile.JavaClassDefinition in project contribution by checkstyle.

the class UnreadFieldCheck method leaveSet.

/**
 * @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor
 */
public void leaveSet(Set aJavaClasses) {
    final Iterator it = aJavaClasses.iterator();
    while (it.hasNext()) {
        final JavaClass javaClass = (JavaClass) it.next();
        final String className = javaClass.getClassName();
        final JavaClassDefinition classDef = findJavaClassDef(javaClass);
        final FieldDefinition[] fieldDefs = classDef.getFieldDefs();
        for (int i = 0; i < fieldDefs.length; i++) {
            if (fieldDefs[i].getReadReferenceCount() == 0) {
                final Field field = fieldDefs[i].getField();
                if (!field.isFinal() && (!ignore(className, field))) {
                    log(javaClass, 0, "unread.field", new Object[] { fieldDefs[i] });
                }
            }
        }
    }
}
Also used : Field(org.apache.bcel.classfile.Field) JavaClass(org.apache.bcel.classfile.JavaClass) FieldDefinition(com.puppycrawl.tools.checkstyle.bcel.classfile.FieldDefinition) Iterator(java.util.Iterator) JavaClassDefinition(com.puppycrawl.tools.checkstyle.bcel.classfile.JavaClassDefinition)

Example 2 with JavaClassDefinition

use of com.puppycrawl.tools.checkstyle.bcel.classfile.JavaClassDefinition in project contribution by checkstyle.

the class UnusedMethodCheck method leaveSet.

/**
 * @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor
 */
public void leaveSet(Set aJavaClasses) {
    final Iterator it = aJavaClasses.iterator();
    while (it.hasNext()) {
        final JavaClass javaClass = (JavaClass) it.next();
        final String className = javaClass.getClassName();
        final JavaClassDefinition classDef = findJavaClassDef(javaClass);
        final MethodDefinition[] methodDefs = classDef.getMethodDefs();
        for (int i = 0; i < methodDefs.length; i++) {
            if (!classDef.hasReference(methodDefs[i], getReferenceDAO())) {
                final Method method = methodDefs[i].getMethod();
                if (!ignore(className, method)) {
                    log(javaClass, 0, "unused.method", new Object[] { methodDefs[i] });
                }
            }
        }
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) MethodDefinition(com.puppycrawl.tools.checkstyle.bcel.classfile.MethodDefinition) Iterator(java.util.Iterator) JavaClassDefinition(com.puppycrawl.tools.checkstyle.bcel.classfile.JavaClassDefinition) Method(org.apache.bcel.classfile.Method)

Aggregations

JavaClassDefinition (com.puppycrawl.tools.checkstyle.bcel.classfile.JavaClassDefinition)2 Iterator (java.util.Iterator)2 JavaClass (org.apache.bcel.classfile.JavaClass)2 FieldDefinition (com.puppycrawl.tools.checkstyle.bcel.classfile.FieldDefinition)1 MethodDefinition (com.puppycrawl.tools.checkstyle.bcel.classfile.MethodDefinition)1 Field (org.apache.bcel.classfile.Field)1 Method (org.apache.bcel.classfile.Method)1