Search in sources :

Example 1 with DescendingClassTraverser

use of com.jopdesign.common.graphutils.DescendingClassTraverser in project jop by jop-devel.

the class ConstantPoolReferenceFinder method findPoolReferences.

private static Set<Integer> findPoolReferences(MethodInfo methodInfo, Method method) {
    ClassInfo classInfo = methodInfo.getClassInfo();
    IdFinderVisitor visitor = new IdFinderVisitor(classInfo);
    visitor.visitConstantUtf8(method.getNameIndex());
    visitor.visitConstantUtf8(method.getSignatureIndex());
    DescendingClassTraverser traverser = new DescendingClassTraverser(visitor);
    // Code is an attribute, since we visit Method, not MethodGen
    traverser.visitAttributes(methodInfo, method.getAttributes());
    return visitor.getIds();
}
Also used : DescendingClassTraverser(com.jopdesign.common.graphutils.DescendingClassTraverser) ClassInfo(com.jopdesign.common.ClassInfo)

Example 2 with DescendingClassTraverser

use of com.jopdesign.common.graphutils.DescendingClassTraverser in project jop by jop-devel.

the class ConstantPoolReferenceFinder method visitPoolReferences.

/**
     * Helper method which applies a visitor to all constants given by a set of ids.
     * @param classInfo the class containing the constant pool
     * @param visitor the visitor to apply
     * @param ids a set of ids of pool entries to visit
     */
private static void visitPoolReferences(ClassInfo classInfo, ClassElementVisitor visitor, Set<Integer> ids) {
    DescendingClassTraverser traverser = new DescendingClassTraverser(visitor);
    ConstantPoolGen cpg = classInfo.getConstantPoolGen();
    // iterate over the given pool entries, call the visitor
    for (Integer id : ids) {
        traverser.visitConstant(classInfo, cpg.getConstant(id));
    }
}
Also used : ConstantInteger(org.apache.bcel.classfile.ConstantInteger) ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) DescendingClassTraverser(com.jopdesign.common.graphutils.DescendingClassTraverser)

Example 3 with DescendingClassTraverser

use of com.jopdesign.common.graphutils.DescendingClassTraverser in project jop by jop-devel.

the class ConstantPoolReferenceFinder method findPoolReferences.

private static Set<Integer> findPoolReferences(FieldInfo fieldInfo, Field field) {
    ClassInfo classInfo = fieldInfo.getClassInfo();
    // we do not need to handle invoke sites here specially, since we do not visit code here
    IdFinderVisitor visitor = new IdFinderVisitor(classInfo);
    visitor.visitConstantUtf8(field.getNameIndex());
    visitor.visitConstantUtf8(field.getSignatureIndex());
    DescendingClassTraverser traverser = new DescendingClassTraverser(visitor);
    traverser.visitAttributes(fieldInfo, field.getAttributes());
    return visitor.getIds();
}
Also used : DescendingClassTraverser(com.jopdesign.common.graphutils.DescendingClassTraverser) ClassInfo(com.jopdesign.common.ClassInfo)

Example 4 with DescendingClassTraverser

use of com.jopdesign.common.graphutils.DescendingClassTraverser in project jop by jop-devel.

the class ConstantPoolReferenceFinder method findPoolReferences.

private static Set<Integer> findPoolReferences(ClassInfo classInfo, JavaClass javaClass) {
    // we do not need to handle invoke sites here specially, since we do not visit code here
    IdFinderVisitor visitor = new IdFinderVisitor(classInfo);
    // now, find *every* used constantpool index in the class, except for methods and fields
    visitor.visitConstantClass(javaClass.getClassNameIndex());
    visitor.visitConstantClass(javaClass.getSuperclassNameIndex());
    for (int index : javaClass.getInterfaceIndices()) {
        visitor.visitConstantClass(index);
    }
    DescendingClassTraverser traverser = new DescendingClassTraverser(visitor);
    traverser.visitAttributes(classInfo, javaClass.getAttributes());
    return visitor.getIds();
}
Also used : DescendingClassTraverser(com.jopdesign.common.graphutils.DescendingClassTraverser)

Example 5 with DescendingClassTraverser

use of com.jopdesign.common.graphutils.DescendingClassTraverser in project jop by jop-devel.

the class ConstantPoolReferenceFinder method findReferencedClasses.

/**
     * Get a set of all classes referenced by the given class, including superclasses, interfaces and
     * references from the code, from parameters and from attributes.
     *
     * @param classInfo the classInfo to search
     * @return a set of all fully qualified class names referenced by this class.
     */
public static Set<String> findReferencedClasses(ClassInfo classInfo) {
    final Set<String> names = new HashSet<String>();
    ClassNameVisitor visitor = new ClassNameVisitor(names);
    new DescendingClassTraverser(visitor).visitClass(classInfo);
    return names;
}
Also used : DescendingClassTraverser(com.jopdesign.common.graphutils.DescendingClassTraverser) ConstantString(org.apache.bcel.classfile.ConstantString) HashSet(java.util.HashSet)

Aggregations

DescendingClassTraverser (com.jopdesign.common.graphutils.DescendingClassTraverser)6 ClassInfo (com.jopdesign.common.ClassInfo)2 HashSet (java.util.HashSet)1 ConstantInteger (org.apache.bcel.classfile.ConstantInteger)1 ConstantString (org.apache.bcel.classfile.ConstantString)1 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)1