Java Code Examples for org.apache.bcel.classfile.JavaClass#getSuperClasses()

The following examples show how to use org.apache.bcel.classfile.JavaClass#getSuperClasses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiddenInheritedFieldCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void visitObject(Object aJavaClass)
{
    final JavaClass javaClass = (JavaClass) aJavaClass;
    final String className = javaClass.getClassName();
    final JavaClass[] superClasses = javaClass.getSuperClasses();
    final Field[] fields = javaClass.getFields();
    // Check all fields
    for (int i = 0; i < fields.length; i++) {
        final Field field = fields[i];
        // Go through all superclasses
        for (int j = 0; j < superClasses.length; j++) {
            final JavaClass superClass = superClasses[j];
            final String superClassName = superClass.getClassName();
            final Field[] superClassFields = superClass.getFields();
            // Go through the filds of the superclasses
            for (int k = 0; k < superClassFields.length; k++) {
                final Field superClassField = superClassFields[k];
                if (!superClassField.isPrivate() &&
                    superClassField.getName().equals(field.getName()) &&
                    !ignore(className, field)) {
                    log(
                        javaClass,
                        0,
                        "hidden.inherited.field",
                        new Object[] {fields[i], superClassName});
                }
            }
        }
    }
}
 
Example 2
Source File: HiddenInheritedFieldCheck.java    From contribution with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void visitObject(Object aJavaClass)
{
    final JavaClass javaClass = (JavaClass) aJavaClass;
    final String className = javaClass.getClassName();
    final JavaClass[] superClasses = javaClass.getSuperClasses();
    final Field[] fields = javaClass.getFields();
    // Check all fields
    for (int i = 0; i < fields.length; i++) {
        final Field field = fields[i];
        // Go through all superclasses
        for (int j = 0; j < superClasses.length; j++) {
            final JavaClass superClass = superClasses[j];
            final String superClassName = superClass.getClassName();
            final Field[] superClassFields = superClass.getFields();
            // Go through the filds of the superclasses
            for (int k = 0; k < superClassFields.length; k++) {
                final Field superClassField = superClassFields[k];
                if (!superClassField.isPrivate() &&
                    superClassField.getName().equals(field.getName()) &&
                    !ignore(className, field)) {
                    log(
                        javaClass,
                        0,
                        "hidden.inherited.field",
                        new Object[] {fields[i], superClassName});
                }
            }
        }
    }
}
 
Example 3
Source File: HiddenStaticMethodCheck.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void visitObject(Object aJavaClass)
{
    final JavaClass javaClass = (JavaClass) aJavaClass;
    final String className = javaClass.getClassName();
    final JavaClass[] superClasses = javaClass.getSuperClasses();
    final Method[] methods = javaClass.getMethods();
    // Check all methods
    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        // Check that the method is a possible match
        if (!method.isPrivate() && method.isStatic())  {
            // Go through all their superclasses
            for (int j = 0; j < superClasses.length; j++) {
                final JavaClass superClass = superClasses[j];
                final String superClassName = superClass.getClassName();
                final Method[] superClassMethods = superClass.getMethods();
                // Go through the methods of the superclasses
                for (int k = 0; k < superClassMethods.length; k++) {
                    final Method superClassMethod = superClassMethods[k];
                    if (superClassMethod.getName().equals(method.getName()) &&
                        !ignore(className, method)) {
                        Type[] methodTypes = method.getArgumentTypes();
                        Type[] superTypes = superClassMethod.
                            getArgumentTypes();
                        if (methodTypes.length == superTypes.length) {
                            boolean match = true;
                            for (int arg = 0; arg < methodTypes.length; arg++) {
                                if (!methodTypes[arg].equals(superTypes[arg])) {
                                    match = false;
                                }
                            }
                            // Same method parameters
                            if (match) {
                                log(
                                    javaClass,
                                    0,
                                    "hidden.static.method",
                                    new Object[] {method, superClassName});
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: HiddenStaticMethodCheck.java    From contribution with GNU Lesser General Public License v2.1 4 votes vote down vote up
/** @see com.puppycrawl.tools.checkstyle.bcel.IObjectSetVisitor */
public void visitObject(Object aJavaClass)
{
    final JavaClass javaClass = (JavaClass) aJavaClass;
    final String className = javaClass.getClassName();
    final JavaClass[] superClasses = javaClass.getSuperClasses();
    final Method[] methods = javaClass.getMethods();
    // Check all methods
    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        // Check that the method is a possible match
        if (!method.isPrivate() && method.isStatic())  {
            // Go through all their superclasses
            for (int j = 0; j < superClasses.length; j++) {
                final JavaClass superClass = superClasses[j];
                final String superClassName = superClass.getClassName();
                final Method[] superClassMethods = superClass.getMethods();
                // Go through the methods of the superclasses
                for (int k = 0; k < superClassMethods.length; k++) {
                    final Method superClassMethod = superClassMethods[k];
                    if (superClassMethod.getName().equals(method.getName()) &&
                        !ignore(className, method)) {
                        Type[] methodTypes = method.getArgumentTypes();
                        Type[] superTypes = superClassMethod.
                            getArgumentTypes();
                        if (methodTypes.length == superTypes.length) {
                            boolean match = true;
                            for (int arg = 0; arg < methodTypes.length; arg++) {
                                if (!methodTypes[arg].equals(superTypes[arg])) {
                                    match = false;
                                }
                            }
                            // Same method parameters
                            if (match) {
                                log(
                                    javaClass,
                                    0,
                                    "hidden.static.method",
                                    new Object[] {method, superClassName});
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 5
Source File: Repository.java    From ApkToolPlus with Apache License 2.0 2 votes vote down vote up
/**
 * @return list of super classes of clazz in ascending order, i.e.,
 * Object is always the last element
 */
public static JavaClass[] getSuperClasses(JavaClass clazz) {
  return clazz.getSuperClasses();
}
 
Example 6
Source File: Repository.java    From commons-bcel with Apache License 2.0 2 votes vote down vote up
/**
 * @return list of super classes of clazz in ascending order, i.e.,
 * Object is always the last element
 * @throws ClassNotFoundException if any of the superclasses can't be found
 */
public static JavaClass[] getSuperClasses( final JavaClass clazz ) throws ClassNotFoundException {
    return clazz.getSuperClasses();
}