本文整理汇总了Java中com.google.javascript.rhino.Token.EXPR_RESULT属性的典型用法代码示例。如果您正苦于以下问题:Java Token.EXPR_RESULT属性的具体用法?Java Token.EXPR_RESULT怎么用?Java Token.EXPR_RESULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.EXPR_RESULT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isNamespacePlaceholder
/**
* @return Whether the node is namespace placeholder.
*/
private static boolean isNamespacePlaceholder(Node n) {
if (!n.getBooleanProp(Node.IS_NAMESPACE)) {
return false;
}
Node value = null;
if (n.getType() == Token.EXPR_RESULT) {
Node assign = n.getFirstChild();
value = assign.getLastChild();
} else if (n.getType() == Token.VAR) {
Node name = n.getFirstChild();
value = name.getFirstChild();
}
return value != null
&& value.getType() == Token.OBJECTLIT
&& !value.hasChildren();
}
示例2: handleCandidateProvideDefinition
/**
* Handles a candidate definition for a goog.provided name.
*/
private void handleCandidateProvideDefinition(
NodeTraversal t, Node n, Node parent) {
if (t.inGlobalScope()) {
String name = null;
if (n.getType() == Token.NAME && parent.getType() == Token.VAR) {
name = n.getString();
} else if (n.getType() == Token.ASSIGN &&
parent.getType() == Token.EXPR_RESULT) {
name = n.getFirstChild().getQualifiedName();
}
if (name != null) {
if (parent.getBooleanProp(Node.IS_NAMESPACE)) {
processProvideFromPreviousPass(t, name, parent);
} else {
ProvidedName pn = providedNames.get(name);
if (pn != null) {
pn.addDefinition(parent, t.getModule());
}
}
}
}
}
示例3: processProvideFromPreviousPass
/**
* Processes the output of processed-provide from a previous pass. This will
* update our data structures in the same manner as if the provide had been
* processed in this pass.
*/
private void processProvideFromPreviousPass(
NodeTraversal t, String name, Node parent) {
if (!providedNames.containsKey(name)) {
// Record this provide created on a previous pass, and create a dummy
// EXPR node as a placeholder to simulate an explicit provide.
Node expr = new Node(Token.EXPR_RESULT);
expr.copyInformationFromForTree(parent);
parent.getParent().addChildBefore(expr, parent);
compiler.reportCodeChange();
JSModule module = t.getModule();
registerAnyProvidedPrefixes(name, expr, module);
ProvidedName provided = new ProvidedName(name, expr, module, true);
providedNames.put(name, provided);
provided.addDefinition(parent, module);
} else {
// Remove this provide if it came from a previous pass since we have an
// replacement already.
if (isNamespacePlaceholder(parent)) {
parent.getParent().removeChild(parent);
compiler.reportCodeChange();
}
}
}
示例4: process
/**
* @param body body of function with id == this.functionId
*/
void process(Node body) {
NodeTraversal.traverse(compiler, body, this);
if (!allPathsReturn(body)) {
Node call = newReportFunctionExitNode();
Node expr = new Node(Token.EXPR_RESULT, call);
body.addChildToBack(expr);
compiler.reportCodeChange();
}
}
示例5: isDirective
private boolean isDirective(Node n) {
if (n == null) return false;
int nType = n.getType();
return (nType == Token.EXPR_RESULT || nType == Token.EXPR_VOID) &&
n.getFirstChild().getType() == Token.STRING &&
ALLOWED_DIRECTIVES.contains(n.getFirstChild().getString());
}
示例6: isInThrowExpression
/**
* Is the {@link Node} currently within a 'throw' expression?
*/
private static boolean isInThrowExpression(Node n) {
// Look up the traversal stack to find a THROW node
for (Node ancestor : n.getAncestors()) {
switch (ancestor.getType()) {
case Token.THROW:
return true;
case Token.IF:
case Token.WHILE:
case Token.DO:
case Token.FOR:
case Token.SWITCH:
case Token.CASE:
case Token.DEFAULT:
case Token.BLOCK:
case Token.SCRIPT:
case Token.FUNCTION:
case Token.TRY:
case Token.CATCH:
case Token.RETURN:
case Token.EXPR_RESULT:
// early exit - these nodes types can't be within a THROW
return false;
}
}
return false;
}
示例7: addMarker
private Node addMarker(
FunctionType funType,
Node nodeToInsertAfter,
@Nullable ObjectType interfaceType) {
String className = funType.getInstanceType().getReferenceName();
// This can happen with anonymous classes declared with the type
// {@code Function}.
if (className == null) {
return nodeToInsertAfter;
}
Node classNode = NodeUtil.newQualifiedNameNode(className, -1, -1);
Node marker = Node.newString(
interfaceType == null ?
"instance_of__" + className :
"implements__" + interfaceType.getReferenceName());
Node assign = new Node(Token.EXPR_RESULT, new Node(Token.ASSIGN,
new Node(Token.GETELEM,
new Node(Token.GETPROP,
classNode,
Node.newString("prototype")), marker),
new Node(Token.TRUE)));
nodeToInsertAfter.getParent().addChildAfter(assign, nodeToInsertAfter);
compiler.reportCodeChange();
nodeToInsertAfter = assign;
return nodeToInsertAfter;
}
示例8: visit
/**
* {@inheritDoc}
*/
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.VAR:
removeVarDeclarationsByNameOrRvalue(t, n, parent);
break;
case Token.NAME:
maybeRemoveReferenceToRemovedVariable(t, n, parent);
break;
case Token.ASSIGN:
case Token.ASSIGN_BITOR:
case Token.ASSIGN_BITXOR:
case Token.ASSIGN_BITAND:
case Token.ASSIGN_LSH:
case Token.ASSIGN_RSH:
case Token.ASSIGN_URSH:
case Token.ASSIGN_ADD:
case Token.ASSIGN_SUB:
case Token.ASSIGN_MUL:
case Token.ASSIGN_DIV:
case Token.ASSIGN_MOD:
maybeEliminateAssignmentByLvalueName(t, n, parent);
break;
case Token.CALL:
maybeRemoveCall(t, n, parent);
break;
case Token.OBJECTLIT:
eliminateKeysWithStripNamesFromObjLit(t, n);
break;
case Token.EXPR_RESULT:
maybeEliminateExpressionByName(t, n, parent);
break;
}
}
示例9: trySimplify
/**
* Attempts to replace the input node with a simpler but functionally
* equivalent set of nodes.
*/
private void trySimplify(Node parent, Node node) {
if (node.getType() != Token.EXPR_RESULT) {
return;
}
Node exprBody = node.getFirstChild();
if (!NodeUtil.nodeTypeMayHaveSideEffects(exprBody)) {
changeProxy.replaceWith(parent, node, getSideEffectNodes(exprBody));
}
}
示例10: 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);
}
示例11: exportTestFunction
private void exportTestFunction(String testFunctionName, Node node,
Node scriptNode) {
Node call = new Node(Token.CALL, NodeUtil.newQualifiedNameNode(
exportSymbolFunction, node, testFunctionName));
call.addChildToBack(Node.newString(testFunctionName));
call.addChildToBack(NodeUtil.newQualifiedNameNode(
testFunctionName, node, testFunctionName));
Node expression = new Node(Token.EXPR_RESULT, call);
scriptNode.addChildAfter(expression, node);
compiler.reportCodeChange();
}
示例12: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (parent != null && parent.getType() == Token.EXPR_RESULT) {
switch (n.getType()) {
case Token.ASSIGN:
maybeCollectMember(t, n.getFirstChild(), n);
break;
case Token.GETPROP:
maybeCollectMember(t, n, n);
break;
}
}
}
示例13: visit
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.IF:
handleIf(n);
return;
case Token.WHILE:
handleWhile(n);
return;
case Token.DO:
handleDo(n);
return;
case Token.FOR:
handleFor(n);
return;
case Token.SWITCH:
handleSwitch(n);
return;
case Token.CASE:
handleCase(n);
return;
case Token.DEFAULT:
handleDefault(n);
return;
case Token.BLOCK:
case Token.SCRIPT:
handleStmtList(n);
return;
case Token.FUNCTION:
handleFunction(n);
return;
case Token.EXPR_RESULT:
handleExpr(n);
return;
case Token.THROW:
handleThrow(n);
return;
case Token.TRY:
handleTry(n);
return;
case Token.CATCH:
handleCatch(n);
return;
case Token.BREAK:
handleBreak(n);
return;
case Token.CONTINUE:
handleContinue(n);
return;
case Token.RETURN:
handleReturn(n);
return;
case Token.WITH:
handleWith(n);
return;
case Token.LABEL:
return;
default:
handleStmt(n);
return;
}
}
示例14: isExpressionNode
static boolean isExpressionNode(Node n) {
return n.getType() == Token.EXPR_RESULT;
}
示例15: 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;
}