Code with Finding: |
class InlineSimpleMethods.InlineTrivialAccessors {
@Override
void visit(NodeTraversal t, Node callNode, Node parent, String callName) {
if (externMethods.contains(callName) ||
nonMethodProperties.contains(callName)) {
return;
}
Collection<Node> definitions = methodDefinitions.get(callName);
if (definitions == null || definitions.size() == 0) {
return;
}
// Do check of arity, complexity, and consistency in what we think is
// the order from least to most complex
Node firstDefinition = definitions.iterator().next();
// Check any multiple definitions
if (definitions.size() == 1 || allDefinitionsEquivalent(definitions)) {
if (!argsMayHaveSideEffects(callNode)) {
// Verify this is a trivial return
Node returned = returnedExpression(firstDefinition);
if (returned != null) {
if (isPropertyTree(returned)) {
logger.fine("Inlining property accessor: " + callName);
inlinePropertyReturn(parent, callNode, returned);
} else if (NodeUtil.isLiteralValue(returned, false) &&
!NodeUtil.mayHaveSideEffects(callNode.getFirstChild())) {
logger.fine("Inlining constant accessor: " + callName);
inlineConstReturn(parent, callNode, returned);
}
} else if (isEmptyMethod(firstDefinition) &&
!NodeUtil.mayHaveSideEffects(callNode.getFirstChild())) {
logger.fine("Inlining empty method: " + callName);
inlineEmptyMethod(t, parent, callNode);
}
}
} else {
logger.fine("Method '" + callName + "' has conflicting definitions.");
}
}
}
|