Search in sources :

Example 6 with FieldRef

use of com.jopdesign.common.type.FieldRef in project jop by jop-devel.

the class UsedCodeFinder method visitReferences.

private void visitReferences(Set<String> refs) {
    for (String id : refs) {
        // The member IDs returned by the reference finder use a syntax which is
        // always unique, so if in doubt, we need to interpret it as a classname, not a fieldname
        MemberID sig = MemberID.parse(id, false);
        // find/load the corresponding classInfo
        ClassInfo cls = getClassInfo(sig);
        // class has been excluded from loading, skip this class
        if (cls == null) {
            continue;
        }
        // referenced class is used, visit it if it has not yet been visited, but skip its class members
        // Note that this class might be different than the class containing the class member
        markUsedMembers(cls, false);
        // check if this id specifies a class member (or just a class, in this case we are done)
        if (sig.hasMethodSignature()) {
            // It's a method! mark the method as used (implementations are marked later)
            MethodRef ref = appInfo.getMethodRef(sig);
            MethodInfo method = ref.getMethodInfo();
            // we keep the declarations. We mark it without following it and make it abstract later.
            if (method != null) {
                setMark(method, false);
            }
        } else if (sig.hasMemberName()) {
            // It's a field! No need to look in subclasses, fields are not virtual
            FieldRef ref = appInfo.getFieldRef(sig);
            FieldInfo field = ref.getFieldInfo();
            if (field != null) {
                markUsedMembers(field);
            }
        }
    }
}
Also used : MemberID(com.jopdesign.common.type.MemberID) MethodRef(com.jopdesign.common.type.MethodRef) FieldRef(com.jopdesign.common.type.FieldRef) MethodInfo(com.jopdesign.common.MethodInfo) FieldInfo(com.jopdesign.common.FieldInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

FieldRef (com.jopdesign.common.type.FieldRef)6 MethodInfo (com.jopdesign.common.MethodInfo)4 MethodRef (com.jopdesign.common.type.MethodRef)4 FieldInfo (com.jopdesign.common.FieldInfo)3 Instruction (org.apache.bcel.generic.Instruction)3 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)3 ClassInfo (com.jopdesign.common.ClassInfo)2 MethodCode (com.jopdesign.common.MethodCode)2 InvokeSite (com.jopdesign.common.code.InvokeSite)2 AppInfoError (com.jopdesign.common.misc.AppInfoError)2 ConstantPushInstruction (org.apache.bcel.generic.ConstantPushInstruction)2 FieldInstruction (org.apache.bcel.generic.FieldInstruction)2 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 LocalVariableInstruction (org.apache.bcel.generic.LocalVariableInstruction)2 CallString (com.jopdesign.common.code.CallString)1 MissingClassError (com.jopdesign.common.misc.MissingClassError)1 ClassRef (com.jopdesign.common.type.ClassRef)1 MemberID (com.jopdesign.common.type.MemberID)1 DFATool (com.jopdesign.dfa.DFATool)1 Context (com.jopdesign.dfa.framework.Context)1