Code with Finding: |
class PureFunctionIdentifier {
@Override
public void process(Node externsAst, Node srcAst) {
if (externs != null || root != null) {
throw new IllegalStateException(
"It is illegal to call PureFunctionIdentifier.process " +
"twice the same instance. Please use a new " +
"PureFunctionIdentifier instance each time.");
}
externs = externsAst;
root = srcAst;
NodeTraversal.traverse(compiler, externs, new FunctionAnalyzer(true));
NodeTraversal.traverse(compiler, root, new FunctionAnalyzer(false));
propagateSideEffects();
markPureFunctionCalls();
}
}
class PureFunctionIdentifier.Driver {
@Override
public void process(Node externs, Node root) {
DefinitionProvider definitionProvider = null;
if (useNameReferenceGraph) {
NameReferenceGraphConstruction graphBuilder =
new NameReferenceGraphConstruction(compiler);
graphBuilder.process(externs, root);
definitionProvider = graphBuilder.getNameReferenceGraph();
} else {
SimpleDefinitionFinder defFinder = new SimpleDefinitionFinder(compiler);
defFinder.process(externs, root);
definitionProvider = defFinder;
}
PureFunctionIdentifier pureFunctionIdentifier =
new PureFunctionIdentifier(compiler, definitionProvider);
pureFunctionIdentifier.process(externs, root);
if (reportPath != null) {
try {
Files.write(pureFunctionIdentifier.getDebugReport(),
new File(reportPath),
Charsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
|