Java Code Examples for org.mozilla.javascript.ast.AstNode#getParent()
The following examples show how to use
org.mozilla.javascript.ast.AstNode#getParent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 6 votes |
@Override public boolean visit(AstNode node) { if (node instanceof PropertyGet){ PropertyGet pg = (PropertyGet)node; AstNode target = pg.getTarget(); String propName = pg.getProperty().getIdentifier(); if (target instanceof KeywordLiteral && ConstraintGenUtil.isThis(target)){ if (node.getParent() instanceof Assignment){ Assignment a = (Assignment)node.getParent(); if (a.getLeft() == node){ writtenProperties.add(propName); } else { readProperties.add(propName); } } else { readProperties.add(propName); } readProperties.removeAll(writtenProperties); // if something is read and written, it should only be in the written set } } else if (node instanceof FunctionNode) { // don't recurse into nested function body return false; } return true; }
Example 2
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 5 votes |
/** * find the function definition that immediately surrounds a given AST node. * Returns null if there is no surrounding function. * */ public static FunctionNode findEnclosingFunction(AstNode node) { AstNode current = node; while (current != null && !(current instanceof FunctionNode)){ current = current.getParent(); } FunctionNode fun = (FunctionNode)current; return fun; }
Example 3
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 5 votes |
public static Assignment findEnclosingAssignment(AstNode node) { AstNode current = node; while (current != null && !(current instanceof Assignment)){ current = current.getParent(); } Assignment a = (Assignment)current; return a; }
Example 4
Source File: ConstraintGenUtil.java From SJS with Apache License 2.0 | 5 votes |
@Override public boolean visit(AstNode node) { if (isThis(node)){ AstNode current = node; while (!(current instanceof FunctionNode)){ current = current.getParent(); } if (current == this.fun){ refersToThis = true; } } return true; }