Search in sources :

Example 1 with ParserException

use of soot.jimple.parser.parser.ParserException in project soot by Sable.

the class JimpleClassSource method resolve.

public Dependencies resolve(SootClass sc) {
    if (Options.v().verbose())
        logger.debug("resolving [from .jimple]: " + className);
    InputStream classFile = null;
    try {
        // Parse jimple file
        classFile = foundFile.inputStream();
        soot.jimple.parser.JimpleAST jimpAST = new soot.jimple.parser.JimpleAST(classFile);
        jimpAST.getSkeleton(sc);
        // Set method source for all methods
        JimpleMethodSource mtdSrc = new JimpleMethodSource(jimpAST);
        Iterator<SootMethod> mtdIt = sc.methodIterator();
        while (mtdIt.hasNext()) {
            SootMethod sm = mtdIt.next();
            sm.setSource(mtdSrc);
        }
        // set outer class if not set (which it should not be) and class name contains outer class indicator
        String outerClassName = null;
        String className = sc.getName();
        if (!sc.hasOuterClass() && className.contains("$")) {
            if (className.contains("$-")) {
                /* This is a special case for generated lambda classes of jack and jill compiler.
					 * Generated lambda classes may contain '$' which do not indicate an inner/outer 
					 * class separator if the '$' occurs after a inner class with a name starting with
					 * '-'. Thus we search for '$-' and anything after it including '-' is the inner
					 * classes name and anything before it is the outer classes name.
					 */
                outerClassName = className.substring(0, className.indexOf("$-"));
            } else {
                outerClassName = className.substring(0, className.lastIndexOf('$'));
            }
            sc.setOuterClass(SootResolver.v().makeClassRef(outerClassName));
        }
        // Construct the type dependencies of the class
        Dependencies deps = new Dependencies();
        // The method documentation states it returns RefTypes only, so this is a transformation safe
        for (String t : jimpAST.getCstPool()) {
            deps.typesToSignature.add(RefType.v(t));
        }
        if (outerClassName != null)
            deps.typesToSignature.add(RefType.v(outerClassName));
        return deps;
    } catch (IOException e) {
        throw new RuntimeException("Error: Failed to create JimpleAST from source input stream for class " + className + ".", e);
    } catch (ParserException e) {
        throw new RuntimeException("Error: Failed when parsing class " + className + ".", e);
    } catch (LexerException e) {
        throw new RuntimeException("Error: Failed when lexing class " + className + ".", e);
    } finally {
        try {
            if (classFile != null) {
                classFile.close();
                classFile = null;
            }
        } catch (IOException e) {
            throw new RuntimeException("Error: Failed to close source input stream.", e);
        } finally {
            close();
        }
    }
}
Also used : ParserException(soot.jimple.parser.parser.ParserException) soot.jimple(soot.jimple) Dependencies(soot.javaToJimple.IInitialResolver.Dependencies) LexerException(soot.jimple.parser.lexer.LexerException)

Aggregations

Dependencies (soot.javaToJimple.IInitialResolver.Dependencies)1 soot.jimple (soot.jimple)1 LexerException (soot.jimple.parser.lexer.LexerException)1 ParserException (soot.jimple.parser.parser.ParserException)1