本文整理汇总了Java中com.google.javascript.rhino.Token.ASSIGN属性的典型用法代码示例。如果您正苦于以下问题:Java Token.ASSIGN属性的具体用法?Java Token.ASSIGN怎么用?Java Token.ASSIGN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.ASSIGN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
@Override
void add(Node n, Context context) {
Node parent = n.getParent();
if (parent.getType() == Token.BLOCK || parent.getType() == Token.SCRIPT) {
if (n.getType() == Token.FUNCTION) {
add(getFunctionAnnotation(n));
} else if (n.getType() == Token.EXPR_RESULT
&& n.getFirstChild().getType() == Token.ASSIGN) {
Node rhs = n.getFirstChild().getFirstChild();
add(getTypeAnnotation(rhs));
} else if (n.getType() == Token.VAR
&& n.getFirstChild().getFirstChild() != null
&& n.getFirstChild().getFirstChild().getType() == Token.FUNCTION) {
add(getFunctionAnnotation(n.getFirstChild().getFirstChild()));
}
}
super.add(n, context);
}
示例2: replaceWithRhs
/**
* Replace n with a simpler expression, while preserving program
* behavior.
*
* If the n's value is used, replace it with its rhs; otherwise
* replace it with the subexpressions that have side effects.
*/
private void replaceWithRhs(Node parent, Node n) {
if (valueConsumedByParent(n, parent)) {
// parent reads from n directly; replace it with n's rhs + lhs
// subexpressions with side effects.
List<Node> replacements = getRhsSubexpressions(n);
List<Node> newReplacements = Lists.newArrayList();
for (int i = 0; i < replacements.size() - 1; i++) {
newReplacements.addAll(getSideEffectNodes(replacements.get(i)));
}
Node valueExpr = replacements.get(replacements.size() - 1);
valueExpr.detachFromParent();
newReplacements.add(valueExpr);
changeProxy.replaceWith(
parent, n, collapseReplacements(newReplacements));
} else if (n.getType() == Token.ASSIGN && parent.getType() != Token.FOR) {
// assignment appears in a RHS expression. we have already
// considered names in the assignment's RHS as being referenced;
// replace the assignment with its RHS.
// TODO(user) make the pass smarter about these cases and/or run
// this pass and RemoveConstantExpressions together in a loop.
Node replacement = n.getLastChild();
replacement.detachFromParent();
changeProxy.replaceWith(parent, n, replacement);
} else {
replaceTopLevelExpressionWithRhs(parent, n);
}
}
示例3: updateObjLitOrFunctionDeclaration
/**
* Updates the first initialization (a.k.a "declaration") of a global name.
* This involves flattening the global name (if it's not just a global
* variable name already), collapsing object literal keys into global
* variables, declaring stub global variables for properties added later
* in a local scope, and eliminating the global name entirely (if possible).
*
* @param n An object representing a global name (e.g. "a", "a.b.c")
* @param alias The flattened name for {@code n} (e.g. "a", "a$b$c")
*/
private void updateObjLitOrFunctionDeclaration(Name n, String alias) {
switch (n.declaration.node.getParent().getType()) {
case Token.ASSIGN:
updateObjLitOrFunctionDeclarationAtAssignNode(n, alias);
break;
case Token.VAR:
updateObjLitOrFunctionDeclarationAtVarNode(n);
break;
case Token.FUNCTION:
updateFunctionDeclarationAtFunctionNode(n);
break;
}
}
示例4: shouldTraverse
/**
* Since this pass reports errors only when a global {@code this} keyword
* is encountered, there is no reason to traverse non global contexts.
*/
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.FUNCTION) {
// Don't traverse functions that are constructors or have the @this
// annotation.
JSDocInfo jsDoc = getFunctionJsDocInfo(n);
if (jsDoc != null && (jsDoc.isConstructor() || jsDoc.hasThisType())) {
return false;
}
}
if (parent != null && parent.getType() == Token.ASSIGN) {
Node lhs = parent.getFirstChild();
Node rhs = lhs.getNext();
if (n == lhs) {
// Always traverse the left side of the assignment. To handle
// nested assignments properly (e.g., (a = this).property = c;),
// assignLhsChild should not be overridden.
if (assignLhsChild == null) {
assignLhsChild = lhs;
}
} else {
// Only traverse the right side if it's not an assignment to a prototype
// property or subproperty.
if (lhs.getType() == Token.GETPROP) {
if (lhs.getLastChild().getString().equals("prototype")) {
return false;
}
String leftName = lhs.getQualifiedName();
if (leftName != null && leftName.contains(".prototype.")) {
return false;
}
}
}
}
return true;
}
示例5: createAssignStatementNode
/**
* Create a valid statement Node containing an assignment to name of the
* given expression.
*/
private static Node createAssignStatementNode(String name, Node expression) {
// Create 'name = result-expression;' statement.
// EXPR (ASSIGN (NAME, EXPRESSION))
Node nameNode = Node.newString(Token.NAME, name);
Node assign = new Node(Token.ASSIGN, nameNode, expression);
return NodeUtil.newExpr(assign);
}
示例6: canAccessDeprecatedTypes
/**
* Returns whether it's currently ok to access deprecated names and
* properties.
*
* There are 3 exceptions when we're allowed to use a deprecated
* type or property:
* 1) When we're in a deprecated function.
* 2) When we're in a deprecated class.
* 3) When we're in a static method of a deprecated class.
*/
private boolean canAccessDeprecatedTypes(NodeTraversal t) {
Node scopeRoot = t.getScopeRoot();
Node scopeRootParent = scopeRoot.getParent();
return
// Case #1
(deprecatedDepth > 0) ||
// Case #2
(getTypeDeprecationInfo(t.getScope().getTypeOfThis()) != null) ||
// Case #3
(scopeRootParent != null && scopeRootParent.getType() == Token.ASSIGN &&
getTypeDeprecationInfo(
getClassOfMethod(scopeRoot, scopeRootParent)) != null);
}
示例7: removeVarDeclaration
/**
* Tries to remove variable declaration if the variable has been coalesced
* with another variable that has already been declared.
*/
private void removeVarDeclaration(Node name) {
Node var = name.getParent();
Node parent = var.getParent();
// Special case when we are in FOR-IN loop.
if (NodeUtil.isForIn(parent)) {
var.removeChild(name);
parent.replaceChild(var, name);
} else if (var.getChildCount() == 1) {
// The removal is easy when there is only one variable in the VAR node.
if (name.hasChildren()) {
Node value = name.removeFirstChild();
var.removeChild(name);
Node assign = new Node(Token.ASSIGN, name, value);
// We don't need to wrapped it with EXPR node if it is within a FOR.
if (parent.getType() != Token.FOR) {
assign = NodeUtil.newExpr(assign);
}
parent.replaceChild(var, assign);
} else {
// In a FOR( ; ; ) node, we must replace it with an EMPTY or else it
// becomes a FOR-IN node.
NodeUtil.removeChild(parent, var);
}
} else {
if (!name.hasChildren()) {
var.removeChild(name);
}
// We are going to leave duplicated declaration otherwise.
}
}
示例8: makeAssignmentExprNode
/**
* Creates a dotted namespace assignment expression
* (e.g. <code>foo.bar = {};</code>).
*
* @param namespace A dotted namespace
* @param node A node from which to copy source info.
*/
private Node makeAssignmentExprNode(String namespace, Node node) {
Node decl = new Node(Token.EXPR_RESULT,
new Node(Token.ASSIGN,
NodeUtil.newQualifiedNameNode(namespace, node, namespace),
new Node(Token.OBJECTLIT)));
decl.putBooleanProp(Node.IS_NAMESPACE, true);
Preconditions.checkState(isNamespacePlaceholder(decl));
decl.copyInformationFromForTree(node);
return decl;
}
示例9: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.ASSIGN) {
Node nameNode = n.getFirstChild();
Node valueNode = n.getLastChild();
if (nameNode.isQualifiedName() &&
valueNode.isQualifiedName() &&
ABSTRACT_METHOD_NAME.equals(valueNode.getQualifiedName())) {
abstractMethodAssignmentNodes.add(new RemovableAssignment(
n.getFirstChild(), n, t));
}
}
}
示例10: 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;
}
示例11: getSideEffectsAndNode
private Node getSideEffectsAndNode() {
Node andNode = new Node(Token.AND);
Node assign = new Node(Token.ASSIGN);
assign.addChildToBack(Node.newString(Token.NAME, "bar"));
assign.addChildToBack(Node.newNumber(0));
andNode.addChildToBack(Node.newString(Token.NAME, "foo"));
andNode.addChildToBack(assign);
return andNode;
}
示例12: processPrototypeParent
/**
* Processes the parent of a GETPROP prototype, which can either be
* another GETPROP (in the case of Foo.prototype.bar), or can be
* an assignment (in the case of Foo.prototype = ...).
*/
private void processPrototypeParent(Node n, CompilerInput input) {
switch (n.getType()) {
// Foo.prototype.getBar = function() { ... }
case Token.GETPROP:
case Token.GETELEM:
Node dest = n.getFirstChild().getNext();
if (dest.getType() == Token.STRING) {
markPrototypePropertyCandidate(dest, input);
}
break;
// Foo.prototype = { "getBar" : function() { ... } }
case Token.ASSIGN:
case Token.CALL:
Node map;
if (n.getType() == Token.ASSIGN) {
map = n.getFirstChild().getNext();
} else {
map = n.getLastChild();
}
if (map.getType() == Token.OBJECTLIT) {
// Remember this node so that we can avoid processing it again when
// the traversal reaches it.
prototypeObjLits.add(map);
// assumes the object literal is well formed
// (has an even number of children)
for (Node key = map.getFirstChild();
key != null; key = key.getNext().getNext()) {
if (key.getType() == Token.STRING) {
markPrototypePropertyCandidate(key, input);
}
}
}
break;
}
}
示例13: processPrototypeParent
/**
* Processes the parent of a GETPROP prototype, which can either be
* another GETPROP (in the case of Foo.prototype.bar), or can be
* an assignment (in the case of Foo.prototype = ...).
*/
private void processPrototypeParent(NodeTraversal t, Node n) {
switch (n.getType()) {
// Foo.prototype.getBar = function() { ... } or
// Foo.prototype.getBar = getBaz (where getBaz is a function)
// parse tree looks like:
// assign <- parent
// getprop <- n
// getprop
// name Foo
// string prototype
// string getBar
// function or name <- assignee
case Token.GETPROP:
case Token.GETELEM:
Node dest = n.getFirstChild().getNext();
Node parent = n.getParent().getParent();
if (dest.getType() == Token.STRING &&
parent.getType() == Token.ASSIGN) {
Node assignee = parent.getFirstChild().getNext();
addPossibleSignature(dest.getString(), assignee, t);
}
break;
}
}
示例14: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.GETPROP) {
String propName = n.getFirstChild().getNext().getString();
if (propName.equals("prototype")) {
processPrototypeParent(t, parent);
} else if (compiler.getCodingConvention().isExported(propName)) {
addGlobalUseOfSymbol(propName, t.getModule(), PROPERTY);
} else {
addSymbolUse(propName, t.getModule(), PROPERTY);
}
} else if (n.getType() == Token.OBJECTLIT &&
// Make sure that we're not handling object literals being
// assigned to a prototype, as in:
// Foo.prototype = {bar: 3, baz: 5};
!(parent.getType() == Token.ASSIGN &&
parent.getFirstChild().getType() == Token.GETPROP &&
parent.getFirstChild().getLastChild().getString().equals(
"prototype"))) {
// var x = {a: 1, b: 2}
// should count as a use of property a and b.
for (Node propNameNode = n.getFirstChild(); propNameNode != null;
propNameNode = propNameNode.getNext().getNext()) {
if (propNameNode.getType() == Token.STRING &&
!propNameNode.isQuotedString()) {
addSymbolUse(propNameNode.getString(), t.getModule(), PROPERTY);
}
}
} else if (n.getType() == Token.NAME) {
String name = n.getString();
// Only process global functions.
Var var = t.getScope().getVar(name);
if (var != null && var.isGlobal() &&
var.getInitialValue() != null &&
var.getInitialValue().getType() == Token.FUNCTION) {
if (t.inGlobalScope()) {
if (!processGlobalFunctionDeclaration(t, n, parent,
parent.getParent())) {
addGlobalUseOfSymbol(name, t.getModule(), VAR);
}
} else {
addSymbolUse(name, t.getModule(), VAR);
}
}
}
if (isPrototypePropertyAssign(n) ||
isGlobalFunctionDeclaration(t, n, parent)) {
symbolStack.pop();
}
}
示例15: advanceLookAhead
private void advanceLookAhead(boolean atStart) {
if (!atStart) {
if (lookAhead == null) {
return;
}
// Don't advance past a refrence to the variable that we're trying
// to inline.
Node curNode = iterator.current();
if (curNode.getType() == Token.NAME &&
varName.equals(curNode.getString())) {
lookAhead = null;
return;
}
}
if (!iterator.hasNext()) {
lookAhead = null;
return;
}
Node nextNode = iterator.next();
Node nextParent = iterator.currentParent();
int type = nextNode.getType();
if (valueHasSideEffects) {
// Reject anything that might read state, i.e. any NAME that is not
// newly redeclared or an assignment to a simple name.
if (type == Token.NAME && !varName.equals(nextNode.getString())) {
boolean blocked = false;
if (nextParent == null) {
blocked = true;
} else {
boolean assignsName = (nextParent.getType() == Token.ASSIGN
&& nextNode == nextParent.getFirstChild());
boolean isVarDeclaration = (nextParent.getType() == Token.VAR);
if (!assignsName && !isVarDeclaration) {
blocked = true;
}
}
if (blocked) {
lookAhead = null;
return;
}
}
}
// Reject anything that might modify relevant state. We assume that
// nobody relies on variables being undeclared, which will break
// constructions like:
// var a = b;
// var b = 3;
// alert(a);
if (NodeUtil.nodeTypeMayHaveSideEffects(nextNode) && type != Token.NAME
|| type == Token.NAME && nextParent.getType() == Token.CATCH) {
lookAhead = null;
return;
}
lookAhead = nextNode;
}