Search in sources :

Example 1 with JMethod

use of com.google.gwt.dev.jjs.ast.JMethod in project ovirt-engine by oVirt.

the class DontPrune method afterCreateLivenessAnalyzer.

/**
 * Right after constructing the liveness analyzer, make sure that all types
 * matched by the regular expression are marked as if they were referenced
 * by the GWT application code.
 */
@After("createLivenessAnalyzer(analyzer, program)")
public void afterCreateLivenessAnalyzer(ControlFlowAnalyzer analyzer, JProgram program) {
    // Get the regular expression and warn the user if it's empty:
    String dontPruneRe = System.getProperty(GWT_DONTPRUNE);
    if (dontPruneRe == null) {
        String error = "The system property '" + GWT_DONTPRUNE + "' that specifies the types not to be pruned wasn't set!";
        System.err.println(error);
        throw new RuntimeException(error);
    }
    // Compile the regular expression:
    Pattern dontPrunePattern = Pattern.compile(dontPruneRe);
    // Scan all the types and make sure that the ones matching the given regular
    // expression are not pruned:
    program.getDeclaredTypes().stream().filter(type -> dontPrunePattern.matcher(type.getName()).matches()).forEach(type -> {
        // Note: calling "analyzer.traverseFromInstantiationOf(type)"
        // may cause GWT compiler to crash on NPE; don't use that method:
        analyzer.traverseFromReferenceTo(type);
        // Make sure that all methods of the given type are not pruned:
        for (JMethod method : type.getMethods()) {
            analyzer.traverseFrom(method);
        }
    });
}
Also used : ControlFlowAnalyzer(com.google.gwt.dev.jjs.impl.ControlFlowAnalyzer) Aspect(org.aspectj.lang.annotation.Aspect) JProgram(com.google.gwt.dev.jjs.ast.JProgram) After(org.aspectj.lang.annotation.After) Pattern(java.util.regex.Pattern) Pointcut(org.aspectj.lang.annotation.Pointcut) JMethod(com.google.gwt.dev.jjs.ast.JMethod) Pattern(java.util.regex.Pattern) JMethod(com.google.gwt.dev.jjs.ast.JMethod) After(org.aspectj.lang.annotation.After)

Aggregations

JMethod (com.google.gwt.dev.jjs.ast.JMethod)1 JProgram (com.google.gwt.dev.jjs.ast.JProgram)1 ControlFlowAnalyzer (com.google.gwt.dev.jjs.impl.ControlFlowAnalyzer)1 Pattern (java.util.regex.Pattern)1 After (org.aspectj.lang.annotation.After)1 Aspect (org.aspectj.lang.annotation.Aspect)1 Pointcut (org.aspectj.lang.annotation.Pointcut)1