| Code with Finding: |
class CrossModuleCodeMotion {
/**
* Determines whether the given value is eligible to be moved across modules.
*/
private boolean canMoveValue(Node n) {
// the value is only movable if it's
// a) nothing,
// b) a constant literal,
// c) a function, or
// d) an array/object literal of movable values.
// e) a function stub generated by CrossModuleMethodMotion.
if (n == null || NodeUtil.isLiteralValue(n, true) ||
n.getType() == Token.FUNCTION) {
return true;
} else if (n.getType() == Token.CALL) {
Node functionName = n.getFirstChild();
return functionName.getType() == Token.NAME &&
(functionName.getString().equals(
CrossModuleMethodMotion.STUB_METHOD_NAME) ||
functionName.getString().equals(
CrossModuleMethodMotion.UNSTUB_METHOD_NAME));
} else if (n.getType() == Token.ARRAYLIT ||
n.getType() == Token.OBJECTLIT) {
boolean isObjectLit = n.getType() == Token.OBJECTLIT;
for (Node child = n.getFirstChild(); child != null;
child = child.getNext()) {
if (!canMoveValue(isObjectLit ? child.getFirstChild() : child)) {
return false;
}
}
return true;
}
return false;
}
}
|