Search in sources :

Example 11 with MemberID

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

the class DFATool method getReceiverMethods.

public Set<MethodInfo> getReceiverMethods(InstructionHandle stmt, CallString cs) {
    Set<String> receivers = getReceivers(stmt, cs);
    Set<MethodInfo> methods = new LinkedHashSet<MethodInfo>(receivers.size());
    for (String rcv : receivers) {
        MemberID mID = MemberID.parse(rcv);
        methods.add(appInfo.getMethodInfoInherited(mID));
    }
    return methods;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberID(com.jopdesign.common.type.MemberID) MethodInfo(com.jopdesign.common.MethodInfo) CallString(com.jopdesign.common.code.CallString)

Example 12 with MemberID

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

the class SourceLineStorage method loadSourceInfos.

/**
     * Load all source file and -line annotations for all classes from the storage file.
     */
public void loadSourceInfos() {
    if (sourceLineMap == null) {
        try {
            readSourceInfos();
        } catch (IOException e) {
            logger.error("Error reading sourceline file " + storage, e);
        }
    }
    Map<MethodInfo, List<SourceLineEntry>> methodMap = new HashMap<MethodInfo, List<SourceLineEntry>>(sourceLineMap.size());
    for (MemberID mID : sourceLineMap.keySet()) {
        try {
            MethodInfo method = AppInfo.getSingleton().getMethodInfo(mID);
            methodMap.put(method, sourceLineMap.get(mID));
        } catch (MethodNotFoundException ignored) {
            logger.warn("No method for entry " + mID + " in " + storage + " found!");
        }
    }
    for (MethodInfo method : methodMap.keySet()) {
        try {
            if (AppInfo.getSingleton().getClassFile(method.getClassInfo()).getTime() > storage.lastModified()) {
                logger.error("One or more class files are newer than annotation file " + storage + ", not loading source line annotations!");
                return;
            }
        } catch (FileNotFoundException e) {
            logger.error("Could not get class file for class " + method.getClassInfo() + ", not loading source lines!", e);
            return;
        }
    }
    for (Map.Entry<MethodInfo, List<SourceLineEntry>> entry : methodMap.entrySet()) {
        MethodInfo method = entry.getKey();
        applySourceInfos(method, entry.getValue());
    }
}
Also used : MemberID(com.jopdesign.common.type.MemberID) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) MethodInfo(com.jopdesign.common.MethodInfo) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) MethodNotFoundException(com.jopdesign.common.misc.MethodNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with MemberID

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

the class SourceLineStorage method readSourceInfos.

private void readSourceInfos() throws IOException {
    BufferedReader reader = new BufferedReader(new FileReader(storage));
    sourceLineMap = new HashMap<MemberID, List<SourceLineEntry>>();
    String entry;
    List<SourceLineEntry> entries = null;
    //noinspection NestedAssignment
    while ((entry = reader.readLine()) != null) {
        entry = entry.trim();
        if (entry.startsWith("[")) {
            int p1 = entry.indexOf(']');
            String methodID = entry.substring(1, p1);
            entries = new ArrayList<SourceLineEntry>();
            MemberID id = MemberID.parse(methodID);
            sourceLineMap.put(id, entries);
        } else if (!"".equals(entry)) {
            assert entries != null;
            entries.add(SourceLineEntry.readEntry(entry));
        }
    }
    reader.close();
}
Also used : MemberID(com.jopdesign.common.type.MemberID) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with MemberID

use of com.jopdesign.common.type.MemberID 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)

Example 15 with MemberID

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

the class ProjectConfig method getTargetClass.

public String getTargetClass() {
    MemberID sig = MemberID.parse(getTargetMethodName(), true);
    String measureClass = sig.getClassName();
    if (measureClass == null)
        return getAppClassName();
    else
        return measureClass;
}
Also used : MemberID(com.jopdesign.common.type.MemberID)

Aggregations

MemberID (com.jopdesign.common.type.MemberID)15 MethodInfo (com.jopdesign.common.MethodInfo)7 ClassInfo (com.jopdesign.common.ClassInfo)4 ArrayList (java.util.ArrayList)3 BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)2 MethodNotFoundException (com.jopdesign.common.misc.MethodNotFoundException)2 MethodRef (com.jopdesign.common.type.MethodRef)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)2 ClassMemberInfo (com.jopdesign.common.ClassMemberInfo)1 FieldInfo (com.jopdesign.common.FieldInfo)1 CallString (com.jopdesign.common.code.CallString)1 BadConfigurationError (com.jopdesign.common.config.Config.BadConfigurationError)1 ClassHierarchyTraverser (com.jopdesign.common.graphutils.ClassHierarchyTraverser)1 ClassVisitor (com.jopdesign.common.graphutils.ClassVisitor)1 EmptyClassVisitor (com.jopdesign.common.graphutils.EmptyClassVisitor)1