Search in sources :

Example 1 with MethodNotFoundException

use of com.jopdesign.common.misc.MethodNotFoundException in project jop by jop-devel.

the class AppInfo method getMethodInfos.

/**
     * @param memberID at least a class name.
     * @return a set of all matching methods.
     * @throws MethodNotFoundException if the base class cannot be found
     */
public Collection<MethodInfo> getMethodInfos(MemberID memberID) throws MethodNotFoundException {
    String className = memberID.getClassName();
    ClassInfo classInfo = classes.get(className);
    if (classInfo == null) {
        throw new MethodNotFoundException("Could not find class for method " + memberID);
    }
    if (!memberID.hasMemberName()) {
        // We could filter out methods by descriptor if it is set
        return classInfo.getMethods();
    }
    return classInfo.getMethodInfos(memberID);
}
Also used : CallString(com.jopdesign.common.code.CallString) MethodNotFoundException(com.jopdesign.common.misc.MethodNotFoundException)

Example 2 with MethodNotFoundException

use of com.jopdesign.common.misc.MethodNotFoundException in project jop by jop-devel.

the class Config method parseMethodList.

/**
     * @param methodNames comma separated list of method names, either fully qualified with or without descriptor, or
     *        method names of methods in the main class.
     * @return the set of methods represented by these names
     * @throws BadConfigurationException if a name is not resolvable
     */
public static List<MethodInfo> parseMethodList(String methodNames) throws BadConfigurationException {
    List<String> names = splitStringList(methodNames);
    List<MethodInfo> methods = new ArrayList<MethodInfo>(names.size());
    for (String name : names) {
        MemberID id = MemberID.parse(name);
        if (!id.hasClassName()) {
            ClassInfo main = AppInfo.getSingleton().getMainMethod().getClassInfo();
            Set<MethodInfo> m = main.getMethodInfos(id);
            if (m.isEmpty()) {
                throw new BadConfigurationException("Cannot find method '" + name + "' in main class " + main);
            }
            methods.addAll(m);
        } else {
            try {
                Collection<MethodInfo> infos = AppInfo.getSingleton().getMethodInfos(id);
                if (infos.isEmpty()) {
                    throw new BadConfigurationException("Cannot find methods for " + name);
                }
                methods.addAll(infos);
            } catch (MethodNotFoundException e) {
                throw new BadConfigurationException("Cannot find class for " + name, e);
            }
        }
    }
    return methods;
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ArrayList(java.util.ArrayList) MethodInfo(com.jopdesign.common.MethodInfo) MethodNotFoundException(com.jopdesign.common.misc.MethodNotFoundException) ClassInfo(com.jopdesign.common.ClassInfo)

Example 3 with MethodNotFoundException

use of com.jopdesign.common.misc.MethodNotFoundException 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)

Aggregations

MethodNotFoundException (com.jopdesign.common.misc.MethodNotFoundException)3 MethodInfo (com.jopdesign.common.MethodInfo)2 MemberID (com.jopdesign.common.type.MemberID)2 ArrayList (java.util.ArrayList)2 ClassInfo (com.jopdesign.common.ClassInfo)1 CallString (com.jopdesign.common.code.CallString)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1