本文整理汇总了Java中com.google.javascript.rhino.Token.CALL属性的典型用法代码示例。如果您正苦于以下问题:Java Token.CALL属性的具体用法?Java Token.CALL怎么用?Java Token.CALL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.CALL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mayThrowException
/**
* Determines if the subtree might throw an exception.
*/
private static boolean mayThrowException(Node n) {
switch (n.getType()) {
case Token.CALL:
case Token.GETPROP:
case Token.GETELEM:
case Token.THROW:
case Token.NEW:
case Token.ASSIGN:
case Token.INC:
case Token.DEC:
case Token.INSTANCEOF:
return true;
case Token.FUNCTION:
return false;
}
for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
return true;
}
}
return false;
}
示例2: addSimplifiedExpression
private void addSimplifiedExpression(Node n, Node parent) {
if (parent.getType() == Token.VAR) {
Node value = n.getFirstChild();
if (value != null) {
addSimplifiedChildren(value);
}
} else if (n.getType() == Token.ASSIGN &&
(parent.getType() == Token.EXPR_RESULT ||
parent.getType() == Token.FOR ||
parent.getType() == Token.RETURN)) {
for (Node child : n.children()) {
addSimplifiedChildren(child);
}
} else if (n.getType() == Token.CALL &&
parent.getType() == Token.EXPR_RESULT) {
addSimplifiedChildren(n);
} else {
addAllChildren(n);
}
}
示例3: canReplaceWithGetProp
/**
* Logic for when a getprop can be replaced.
* Can't alias a call to eval per ECMA 262 spec section 15.1.2.1
* Can't be an assign -> no a.b = c;
* Can't be inc or dec -> no a.b++; or a.b--;
* Must be a GETPROP (NODE, A) where A is a reserved name
* @param propNameNode Property name node
* @param getPropNode GETPROP node
* @param parent parent node
* @return True if can be replaced
*/
private boolean canReplaceWithGetProp(Node propNameNode, Node getPropNode,
Node parent) {
boolean isCallTarget = (parent.getType() == Token.CALL)
&& (parent.getFirstChild() == getPropNode);
boolean isAssignTarget = NodeUtil.isAssignmentOp(parent)
&& (parent.getFirstChild() == getPropNode);
boolean isIncOrDec = (parent.getType() == Token.INC) ||
(parent.getType() == Token.DEC);
return (propNameNode.getType() == Token.STRING) && !isAssignTarget
&& (!isCallTarget || !"eval".equals(propNameNode.getString()))
&& !isIncOrDec
&& props.containsKey(propNameNode.getString());
}
示例4: createCheckTypeCallNode
/**
* Creates a function call to check that the given expression matches the
* given type at runtime.
*
* <p>For example, if the type is {@code (string|Foo)}, the function call is
* {@code checkType(expr, [valueChecker('string'), classChecker('Foo')])}.
*
* @return the function call node or {@code null} if the type is not checked
*/
private Node createCheckTypeCallNode(JSType type, Node expr) {
Node arrayNode = new Node(Token.ARRAYLIT);
Iterable<JSType> alternates = type.isUnionType()
? Sets.newTreeSet(ALPHA, ((UnionType) type).getAlternates())
: ImmutableList.of(type);
for (JSType alternate : alternates) {
Node checkerNode = createCheckerNode(alternate);
if (checkerNode == null) {
return null;
}
arrayNode.addChildToBack(checkerNode);
}
return new Node(Token.CALL, jsCode("checkType"), expr, arrayNode);
}
示例5: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.NEW) {
if (!NodeUtil.constructorCallHasSideEffects(n)) {
noSideEffectCalls.add(n.getFirstChild().getQualifiedName());
}
} else if (n.getType() == Token.CALL) {
if (!NodeUtil.functionCallHasSideEffects(n)) {
noSideEffectCalls.add(n.getFirstChild().getQualifiedName());
}
}
}
示例6: getImplicitActions
/**
* Returns any actions that are implicit in the given code. This can return
* null instead of an empty collection if none are found.
*/
private Collection<Action> getImplicitActions(Node n) {
switch (n.getType()) {
case Token.CALL:
// Functions passed to externs functions are considered called.
// E.g. window.setTimeout(callback, 100);
// TODO(user): support global extern function calls if necessary
// TODO(user): handle addEventListener for the case of an object
// implementing the EventListener interface.
Node receiver = n.getFirstChild();
if (!inExterns && receiver.getType() == Token.GETPROP) {
return getImplicitActionsFromCall(n, receiver.getJSType());
}
break;
case Token.ASSIGN:
Node lhs = n.getFirstChild();
// Functions assigned to externs properties are considered called.
// E.g. element.onclick = function handle(evt) {};
if (!inExterns && lhs.getType() == Token.GETPROP) {
return getImplicitActionsFromProp(lhs.getFirstChild().getJSType(),
lhs.getLastChild().getString(), n.getLastChild());
}
break;
}
return null;
}
示例7: visit
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.NEW:
case Token.CALL:
Node fn = n.getFirstChild();
if (fn.getType() == Token.NAME) {
String fnName = fn.getString();
// Lookup the function
Scope.Var v = t.getScope().getVar(fnName);
// VarCheck should have caught this undefined function
if (v == null) {
return;
}
Node fnDef = v.getInitialValue();
if (fnDef == null ||
fnDef.getType() != Token.FUNCTION) {
// It's a variable, can't check this.
return;
}
FunctionInfo f = getFunctionInfo(fnDef, v.getInputName());
checkCall(n, fnName, Collections.singletonList(f), t, level);
}
break;
}
}
示例8: aliasNode
@Override
/** {@inheritDoc} */
protected void aliasNode(Node throwNode, Node parent) {
Node name = NodeUtil.newName(getAliasName(), throwNode, getAliasName());
Node aliasCall = new Node(Token.CALL, name, throwNode.removeFirstChild());
Node exprResult = new Node(Token.EXPR_RESULT, aliasCall);
parent.replaceChild(throwNode, exprResult);
}
示例9: visit
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
// Function calls
case Token.CALL:
Node child = n.getFirstChild();
String name = null;
// NOTE: The normalization pass insures that local names do not
// collide with global names.
if (child.getType() == Token.NAME) {
name = child.getString();
} else if (child.getType() == Token.FUNCTION) {
name = anonFunctionMap.get(child);
} else if (NodeUtil.isFunctionObjectCall(n)) {
Preconditions.checkState(NodeUtil.isGet(child));
Node fnIdentifingNode = child.getFirstChild();
if (fnIdentifingNode.getType() == Token.NAME) {
name = fnIdentifingNode.getString();
} else if (fnIdentifingNode.getType() == Token.FUNCTION) {
name = anonFunctionMap.get(fnIdentifingNode);
}
}
if (name != null) {
FunctionState fs = functionMap.get(name);
// Only visit call-sites for functions that can be inlined.
if (fs != null) {
callback.visitCallSite(t, n, parent, fs);
}
}
break;
}
}
示例10: insideGetUniqueIdCall
/**
* Returns whether the node is an argument of a goog.events.getUniqueId
* call.
*/
private boolean insideGetUniqueIdCall(Node n, Node parent) {
return parent.getType() == Token.CALL &&
GET_UNIQUE_ID_FUNCTION.equals(
parent.getFirstChild().getQualifiedName());
}
示例11: determineGetTypeForHookOrBooleanExpr
/**
* Determines whether the result of a hook (x?y:z) or boolean expression
* (x||y) or (x&&y) is assigned to a specific global name.
*
* @param t The traversal
* @param parent The parent of the current node in the traversal. This node
* should already be known to be a HOOK, AND, or OR node.
* @param name A name that is already known to be global in the current
* scope (e.g. "a" or "a.b.c.d")
* @return The expression's get type, either {@link Ref.Type#DIRECT_GET} or
* {@link Ref.Type#ALIASING_GET}
*/
Ref.Type determineGetTypeForHookOrBooleanExpr(
NodeTraversal t, Node parent, String name) {
Node prev = parent;
for (Node anc : parent.getAncestors()) {
switch (anc.getType()) {
case Token.EXPR_RESULT:
case Token.VAR:
case Token.IF:
case Token.WHILE:
case Token.FOR:
case Token.TYPEOF:
case Token.VOID:
case Token.NOT:
case Token.BITNOT:
case Token.POS:
case Token.NEG:
return Ref.Type.DIRECT_GET;
case Token.HOOK:
if (anc.getFirstChild() == prev) {
return Ref.Type.DIRECT_GET;
}
break;
case Token.ASSIGN:
if (!name.equals(anc.getFirstChild().getQualifiedName())) {
return Ref.Type.ALIASING_GET;
}
break;
case Token.NAME: // a variable declaration
if (!name.equals(anc.getString())) {
return Ref.Type.ALIASING_GET;
}
break;
case Token.CALL:
if (anc.getFirstChild() != prev) {
return Ref.Type.ALIASING_GET;
}
break;
}
prev = anc;
}
return Ref.Type.ALIASING_GET;
}
示例12: visit
/**
* If the function call returns this and the next statement has the same
* target expression, record the call site.
*/
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (!NodeUtil.isExpressionNode(n)) {
return;
}
Node callNode = n.getFirstChild();
if (callNode.getType() != Token.CALL) {
return;
}
Node getPropNode = callNode.getFirstChild();
if (getPropNode.getType() != Token.GETPROP) {
return;
}
Node getPropFirstChildNode = getPropNode.getFirstChild();
Collection<Definition> definitions =
defFinder.getDefinitionsReferencedAt(getPropNode);
if (definitions == null) {
return;
}
for (Definition definition : definitions) {
Node rValue = definition.getRValue();
if (rValue == null) {
return;
}
if (badFunctionNodes.contains(rValue)) {
return;
}
if (!goodFunctionNodes.contains(rValue)) {
NodeTraversal.traverse(compiler, rValue, gatherFunctions);
if (badFunctionNodes.contains(rValue)) {
return;
}
}
}
Node nextNode = n.getNext();
if (nextNode == null ||
nextNode.getType() != Token.EXPR_RESULT) {
return;
}
Node nextCallNode = nextNode.getFirstChild();
if (nextCallNode.getType() != Token.CALL) {
return;
}
Node nextGetPropNode = nextCallNode.getFirstChild();
if (nextGetPropNode.getType() != Token.GETPROP) {
return;
}
Node nextGetPropFirstChildNode = nextGetPropNode.getFirstChild();
if (!compiler.areNodesEqualForInlining(
nextGetPropFirstChildNode, getPropFirstChildNode)) {
return;
}
if (NodeUtil.mayEffectMutableState(getPropFirstChildNode)) {
return;
}
// We can't chain immediately as it we wouldn't recognize further
// opportunities to chain.
callSites.add(new CallSite(parent, n, callNode, nextGetPropNode,
nextGetPropFirstChildNode));
}
示例13: maybeProcessDeclaration
/**
* Determines whether the given NAME node belongs to a delcaration that
* can be moved across modules. If it is, registers it properly.
*
* There are four types of movable declarations:
* 1) var NAME = [movable object];
* 2) function NAME() {}
* 3) NAME = [movable object];
* NAME.prop = [movable object];
* NAME.prop.prop2 = [movable object];
* etc.
* 4) Class-defining function calls, like "inherits" and "mixin".
* NAME.inherits([some other name]);
* where "movable object" is a literal or a function.
*/
private boolean maybeProcessDeclaration(NodeTraversal t, Node name,
Node parent, NamedInfo info) {
Node gramps = parent.getParent();
switch (parent.getType()) {
case Token.VAR:
if (canMoveValue(name.getFirstChild())) {
return info.addDeclaration(
new Declaration(t.getModule(), name, parent, gramps));
}
return false;
case Token.FUNCTION:
if (NodeUtil.isFunctionDeclaration(parent)) {
return info.addDeclaration(
new Declaration(t.getModule(), name, parent, gramps));
}
return false;
case Token.ASSIGN:
case Token.GETPROP:
Node child = name;
// Look for assignment expressions where the name is the root
// of a qualified name on the left hand side of the assignment.
for (Node current : name.getAncestors()) {
if (current.getType() == Token.GETPROP) {
// fallthrough
} else if (current.getType() == Token.ASSIGN &&
current.getFirstChild() == child) {
Node currentParent = current.getParent();
if (NodeUtil.isExpressionNode(currentParent) &&
canMoveValue(current.getLastChild())) {
return info.addDeclaration(
new Declaration(t.getModule(), current, currentParent,
currentParent.getParent()));
}
} else {
return false;
}
child = current;
}
return false;
case Token.CALL:
if (NodeUtil.isExprCall(gramps)) {
SubclassRelationship relationship =
compiler.getCodingConvention().getClassesDefinedByCall(parent);
if (relationship != null &&
name.getString().equals(relationship.subclassName)) {
return info.addDeclaration(
new Declaration(t.getModule(), parent, gramps,
gramps.getParent()));
}
}
return false;
default:
return false;
}
}
示例14: visit
public void visit(NodeTraversal t, Node n, Node parent) {
// VOID nodes appear when there are extra semicolons at the BLOCK level.
// I've been unable to think of any cases where this indicates a bug,
// and apparently some people like keeping these semicolons around,
// so we'll allow it.
if (n.getType() == Token.EMPTY ||
n.getType() == Token.COMMA) {
return;
}
if (parent == null)
return;
int pt = parent.getType();
if (pt == Token.COMMA) {
Node gramps = parent.getParent();
if (gramps.getType() == Token.CALL &&
parent == gramps.getFirstChild()) {
// Semantically, a direct call to eval is different from an indirect
// call to an eval. See Ecma-262 S15.1.2.1. So it's ok for the first
// expression to a comma to be a no-op if it's used to indirect
// an eval.
if (n == parent.getFirstChild() &&
parent.getChildCount() == 2 &&
n.getNext().getType() == Token.NAME &&
"eval".equals(n.getNext().getString())) {
return;
}
}
if (n == parent.getLastChild()) {
for (Node an : parent.getAncestors()) {
int ancestorType = an.getType();
if (ancestorType == Token.COMMA)
continue;
if (ancestorType != Token.EXPR_RESULT &&
ancestorType != Token.BLOCK)
return;
else
break;
}
}
} else if (pt != Token.EXPR_RESULT && pt != Token.BLOCK) {
if (pt == Token.FOR && parent.getChildCount() == 4 &&
(n == parent.getFirstChild() ||
n == parent.getFirstChild().getNext().getNext())) {
// Fall through and look for warnings for the 1st and 3rd child
// of a for.
} else {
return; // it might be ok to not have a side-effect
}
}
if (NodeUtil.isSimpleOperatorType(n.getType()) ||
!NodeUtil.mayHaveSideEffects(n)) {
if (n.isQualifiedName() && n.getJSDocInfo() != null) {
// This no-op statement was there so that JSDoc information could
// be attached to the name. This check should not complain about it.
return;
} else if (NodeUtil.isExpressionNode(n)) {
// we already reported the problem when we visited the child.
return;
}
String msg = "This code lacks side-effects. Is there a bug?";
if (n.getType() == Token.STRING) {
msg = "Is there a missing '+' on the previous line?";
}
t.getCompiler().report(
JSError.make(t, n, level, USELESS_CODE_ERROR, msg));
}
}
示例15: newReportFunctionExitNode
private Node newReportFunctionExitNode() {
return new Node(Token.CALL,
Node.newString(Token.NAME, reportFunctionExitName),
Node.newNumber(functionId));
}