Search in sources :

Example 76 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.

the class TransitiveHull method add.

private void add(String class_name) {
    class_name = class_name.replace('/', '.');
    // }
    for (int i = 0; i < excluded.length; ++i) {
        if (excluded[i].equals(class_name)) {
            return;
        }
    }
    // we ignore array classes
    if (class_name.startsWith("[")) {
        return;
    }
    JavaClass clazz;
    try {
        clazz = Repository.lookupClass(class_name);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        throw new Error();
    }
    if (clazz == null) {
        System.out.println("lookupClass(" + class_name + ") failed in TransitiveHull");
        System.exit(1);
    }
    if (clazz != null && _set.add(clazz)) {
        _queue.enqueue(clazz);
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass)

Example 77 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.

the class TransitiveHull method main.

public static void main(String[] argv) {
    JavaClass java_class;
    try {
        if (argv.length == 0) {
            System.err.println("transitive: No input files specified");
        } else {
            java_class = Repository.lookupClass(argv[0]);
            TransitiveHull hull = new TransitiveHull(java_class);
            hull.start();
            System.out.println(Arrays.asList(hull.getClassNames()));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass)

Example 78 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.

the class OldAppInfo method iterate.

/**
 * Iterate over all classes and run the visitor.
 *
 * @param v
 */
public void iterate(Visitor v) {
    Iterator<? extends OldClassInfo> it = cliMap.values().iterator();
    while (it.hasNext()) {
        JavaClass clz = it.next().clazz;
        new DescendingVisitor(clz, v).visit();
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) DescendingVisitor(org.apache.bcel.classfile.DescendingVisitor)

Example 79 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.

the class OldClassInfo method genClassInfoMap.

/**
 * Create ClassInfos and the map from class names to ClassInfo
 * @param jc
 * @return
 */
Map<String, ? extends OldClassInfo> genClassInfoMap(JavaClass[] jc, OldAppInfo ai) {
    Map<String, OldClassInfo> map = new HashMap<String, OldClassInfo>();
    for (int i = 0; i < jc.length; ++i) {
        OldClassInfo cli = newClassInfo(jc[i], ai);
        map.put(cli.clazz.getClassName(), cli);
    }
    // second iteration over all class infos for additional information setting
    CliVisitor v = newCliVisitor(map);
    Iterator<? extends OldClassInfo> it = map.values().iterator();
    while (it.hasNext()) {
        JavaClass clz = it.next().clazz;
        new DescendingVisitor(clz, v).visit();
    }
    return map;
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) HashMap(java.util.HashMap) DescendingVisitor(org.apache.bcel.classfile.DescendingVisitor)

Example 80 with JavaClass

use of org.apache.bcel.classfile.JavaClass in project jop by jop-devel.

the class ConstantPoolReferenceFinder method findPoolReferences.

// //////////////////////////////////////////////////////////////
// Find/replace references, member names, Pool entries
// //////////////////////////////////////////////////////////////
public static Set<Integer> findPoolReferences(ClassInfo classInfo, boolean checkMembers) {
    JavaClass javaClass = classInfo.compile();
    Set<Integer> ids = findPoolReferences(classInfo, javaClass);
    if (checkMembers) {
        for (Field field : javaClass.getFields()) {
            FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
            ids.addAll(findPoolReferences(fieldInfo, field));
        }
        for (Method method : javaClass.getMethods()) {
            MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
            ids.addAll(findPoolReferences(methodInfo, method));
        }
    }
    return ids;
}
Also used : ConstantInteger(org.apache.bcel.classfile.ConstantInteger) Field(org.apache.bcel.classfile.Field) JavaClass(org.apache.bcel.classfile.JavaClass) MethodInfo(com.jopdesign.common.MethodInfo) ConstantMethodInfo(com.jopdesign.common.type.ConstantMethodInfo) Method(org.apache.bcel.classfile.Method) EnclosingMethod(com.jopdesign.common.bcel.EnclosingMethod) ConstantFieldInfo(com.jopdesign.common.type.ConstantFieldInfo) FieldInfo(com.jopdesign.common.FieldInfo)

Aggregations

JavaClass (org.apache.bcel.classfile.JavaClass)144 OpcodeStack (edu.umd.cs.findbugs.OpcodeStack)45 BugInstance (edu.umd.cs.findbugs.BugInstance)43 Method (org.apache.bcel.classfile.Method)28 ToString (com.mebigfatguy.fbcontrib.utils.ToString)27 Field (org.apache.bcel.classfile.Field)17 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)11 ClassParser (org.apache.bcel.classfile.ClassParser)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)8 ExceptionTable (org.apache.bcel.classfile.ExceptionTable)8 XField (edu.umd.cs.findbugs.ba.XField)7 Nullable (javax.annotation.Nullable)7 AnnotationEntry (org.apache.bcel.classfile.AnnotationEntry)7 Type (org.apache.bcel.generic.Type)7 Iterator (java.util.Iterator)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6