use of com.google.gwt.dev.jjs.impl.ControlFlowAnalyzer 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);
}
});
}
Aggregations