本文整理汇总了Java中com.google.javascript.rhino.Token.NEW属性的典型用法代码示例。如果您正苦于以下问题:Java Token.NEW属性的具体用法?Java Token.NEW怎么用?Java Token.NEW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.NEW属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nodeTypeMayHaveSideEffects
/**
* Returns true if the current node's type implies side effects.
*
* This is a non-recursive version of the may have side effects
* check; used to check wherever the current node's type is one of
* the reason's why a subtree has side effects.
*/
static boolean nodeTypeMayHaveSideEffects(Node n) {
if (NodeUtil.isAssignmentOp(n)) {
return true;
}
switch(n.getType()) {
case Token.CALL:
case Token.DELPROP:
case Token.NEW:
case Token.DEC:
case Token.INC:
case Token.THROW:
return true;
case Token.NAME:
// A variable definition.
return n.hasChildren();
default:
return false;
}
}
示例2: hasNonLocalSideEffect
/**
* @return Whether the node may have non-local side-effects.
*/
private boolean hasNonLocalSideEffect(Node n) {
boolean sideEffect = false;
int type = n.getType();
// Note: Only care about changes to non-local names, specifically
// ignore VAR declaration assignments.
if (NodeUtil.isAssignmentOp(n)
|| type == Token.INC
|| type == Token.DEC) {
Node lhs = n.getFirstChild();
// Ignore changes to local names.
if (!isLocalName(lhs)) {
sideEffect = true;
}
} else if (type == Token.CALL) {
sideEffect = NodeUtil.functionCallHasSideEffects(n);
} else if (type == Token.NEW) {
sideEffect = NodeUtil.constructorCallHasSideEffects(n);
} else if (type == Token.DELPROP) {
sideEffect = true;
}
return sideEffect;
}
示例3: checkNameDeprecation
/**
* Checks the given NAME node to ensure that access restrictions are obeyed.
*/
private void checkNameDeprecation(NodeTraversal t, Node n, Node parent) {
// Don't bother checking definitions or constructors.
if (parent.getType() == Token.FUNCTION || parent.getType() == Token.VAR ||
parent.getType() == Token.NEW) {
return;
}
Scope.Var var = t.getScope().getVar(n.getString());
JSDocInfo docInfo = var == null ? null : var.getJSDocInfo();
if (docInfo != null && docInfo.isDeprecated() &&
shouldEmitDeprecationWarning(t, n, parent)) {
if (docInfo.getDeprecationReason() != null) {
compiler.report(
JSError.make(t, n, DEPRECATED_NAME_REASON, n.getString(),
docInfo.getDeprecationReason()));
} else {
compiler.report(
JSError.make(t, n, DEPRECATED_NAME, n.getString()));
}
}
}
示例4: shouldEmitDeprecationWarning
/**
* Determines whether a deprecation warning should be emitted.
* @param t The current traversal.
* @param n The node which we are checking.
* @param parent The parent of the node which we are checking.
*/
private boolean shouldEmitDeprecationWarning(
NodeTraversal t, Node n, Node parent) {
// In the global scope, there are only two kinds of accesses that should
// be flagged for warnings:
// 1) Calls of deprecated functions and methods.
// 2) Instantiations of deprecated classes.
// For now, we just let everything else by.
if (t.inGlobalScope()) {
if (!((parent.getType() == Token.CALL && parent.getFirstChild() == n) ||
n.getType() == Token.NEW)) {
return false;
}
}
// We can always assign to a deprecated property, to keep it up to date.
if (n.getType() == Token.GETPROP && n == parent.getFirstChild() &&
NodeUtil.isAssignmentOp(parent)) {
return false;
}
return !canAccessDeprecatedTypes(t);
}
示例5: 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;
}
示例6: definitionTypeContainsFunctionType
/**
* Determines if the type of the value of the rhs expression can
* be a function node.
*/
private static boolean definitionTypeContainsFunctionType(Definition def) {
Node rhs = def.getRValue();
if (rhs == null) {
return true;
}
switch (rhs.getType()) {
case Token.ASSIGN:
case Token.AND:
case Token.CALL:
case Token.GETPROP:
case Token.GETELEM:
case Token.FUNCTION:
case Token.HOOK:
case Token.NAME:
case Token.NEW:
case Token.OR:
return true;
default:
return false;
}
}
示例7: canBeSideEffected
/**
* @param knownConstants A set of names known to be constant value at
* node 'n' (such as locals that are last written before n can execute).
* @return Whether the tree can be affected by side-effects or
* has side-effects.
*/
static boolean canBeSideEffected(Node n, Set<String> knownConstants) {
switch (n.getType()) {
case Token.CALL:
case Token.NEW:
// Function calls or constructor can reference changed values.
// TODO(johnlenz): Add some mechanism for determining that functions
// are unaffected by side effects.
return true;
case Token.NAME:
// Non-constant names values may have been changed.
return !NodeUtil.isConstantName(n)
&& !knownConstants.contains(n.getString());
// Properties on constant NAMEs can still be side-effected.
case Token.GETPROP:
case Token.GETELEM:
return true;
}
for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
if (canBeSideEffected(c, knownConstants)) {
return true;
}
}
return false;
}
示例8: 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());
}
}
}
示例9: 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;
}
}
示例10: traverseEdge
public boolean traverseEdge(FunctionInformation callee,
Node callSite,
FunctionInformation caller) {
Preconditions.checkArgument(callSite.getType() == Token.CALL ||
callSite.getType() == Token.NEW);
boolean changed = false;
if (!caller.mutatesGlobalState() && callee.mutatesGlobalState()) {
caller.setTaintsGlobalState();
changed = true;
}
if (!caller.functionThrows() && callee.functionThrows()) {
caller.setFunctionThrows();
changed = true;
}
if (callee.mutatesThis()) {
// Side effects only propagate via regular calls.
// Calling a constructor that modifies "this" has no side effects.
if (callSite.getType() != Token.NEW) {
Node objectNode = getCallThisObject(callSite);
if (objectNode != null && NodeUtil.isThis(objectNode)) {
if (!caller.mutatesThis()) {
caller.setTaintsThis();
changed = true;
}
} else if (!caller.mutatesGlobalState()) {
caller.setTaintsGlobalState();
changed = true;
}
}
}
return changed;
}
示例11: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.NAME) {
String name = n.getString();
Scope.Var var = t.getScope().getVar(name);
// It's ok for var to be null since it won't be in any scope if it's
// an extern
if (var != null && var.isLocal()) {
return;
}
Property global = globals.get(name);
if (global != null) {
// If a global is being assigned to or otherwise modified, then we
// don't want to alias it.
// Using "new" with this global is not a mutator, but it's also
// something that we want to avoid when aliasing, since we may be
// dealing with external objects (e.g. ActiveXObject in MSIE)
if ((NodeUtil.isAssignmentOp(parent) &&
parent.getFirstChild() == n) ||
parent.getType() == Token.INC ||
parent.getType() == Token.DEC ||
parent.getType() == Token.NEW) {
global.recordMutator(t);
} else {
global.recordAccessor(t);
}
globalUses.add(n);
}
}
}
示例12: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() != Token.NEW) {
return;
}
Node objectName = n.getFirstChild();
if (!ObjectPropertyStringPreprocess.EXTERN_OBJECT_PROPERTY_STRING.equals(
objectName.getQualifiedName())) {
return;
}
Node firstArgument = objectName.getNext();
Node secondArgument = firstArgument.getNext();
int secondArgumentType = secondArgument.getType();
if (secondArgumentType == Token.GETPROP) {
// Rewrite "new goog.testing.ObjectPropertyString(window, foo.bar)"
// as "new goog.testing.ObjectPropertyString(foo, 'bar')".
Node newChild = secondArgument.getFirstChild();
secondArgument.removeChild(newChild);
n.replaceChild(firstArgument, newChild);
n.replaceChild(secondArgument,
Node.newString(secondArgument.getFirstChild().getString()));
} else if (secondArgumentType == Token.GETELEM) {
// Rewrite "new goog.testing.ObjectPropertyString(window, foo[bar])"
// as "new goog.testing.ObjectPropertyString(foo, bar)".
Node newFirstArgument = secondArgument.getFirstChild();
secondArgument.removeChild(newFirstArgument);
Node newSecondArgument = secondArgument.getLastChild();
secondArgument.removeChild(newSecondArgument);
n.replaceChild(firstArgument, newFirstArgument);
n.replaceChild(secondArgument, newSecondArgument);
} else {
// Rewrite "new goog.testing.ObjectPropertyString(window, foo)" as
// "new goog.testing.ObjectPropertyString(window, 'foo')"
n.replaceChild(secondArgument,
Node.newString(secondArgument.getString()));
}
compiler.reportCodeChange();
}
示例13: visit
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.NAME:
checkNameDeprecation(t, n, parent);
checkNameVisibility(t, n, parent);
break;
case Token.GETPROP:
checkPropertyDeprecation(t, n, parent);
checkPropertyVisibility(t, n, parent);
break;
case Token.NEW:
checkConstructorDeprecation(t, n, parent);
break;
}
}
示例14: checkPropertyDeprecation
/**
* Checks the given GETPROP node to ensure that access restrictions are
* obeyed.
*/
private void checkPropertyDeprecation(NodeTraversal t, Node n, Node parent) {
// Don't bother checking constructors.
if (parent.getType() == Token.NEW) {
return;
}
ObjectType objectType =
ObjectType.cast(dereference(n.getFirstChild().getJSType()));
String propertyName = n.getLastChild().getString();
if (objectType != null) {
String deprecationInfo
= getPropertyDeprecationInfo(objectType, propertyName);
if (deprecationInfo != null &&
shouldEmitDeprecationWarning(t, n, parent)) {
if (!deprecationInfo.isEmpty()) {
compiler.report(
JSError.make(t, n, DEPRECATED_PROP_REASON, propertyName,
validator.getReadableJSTypeName(n.getFirstChild(), true),
deprecationInfo));
} else {
compiler.report(
JSError.make(t, n, DEPRECATED_PROP, propertyName,
validator.getReadableJSTypeName(n.getFirstChild(), true)));
}
}
}
}
示例15: precedence
static int precedence(int type) {
switch (type) {
case Token.COMMA: return 0;
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:
case Token.ASSIGN: return 1;
case Token.HOOK: return 2; // ?: operator
case Token.OR: return 3;
case Token.AND: return 4;
case Token.BITOR: return 5;
case Token.BITXOR: return 6;
case Token.BITAND: return 7;
case Token.EQ:
case Token.NE:
case Token.SHEQ:
case Token.SHNE: return 8;
case Token.LT:
case Token.GT:
case Token.LE:
case Token.GE:
case Token.INSTANCEOF:
case Token.IN: return 9;
case Token.LSH:
case Token.RSH:
case Token.URSH: return 10;
case Token.SUB:
case Token.ADD: return 11;
case Token.MUL:
case Token.MOD:
case Token.DIV: return 12;
case Token.INC:
case Token.DEC:
case Token.NEW:
case Token.DELPROP:
case Token.TYPEOF:
case Token.VOID:
case Token.NOT:
case Token.BITNOT:
case Token.POS:
case Token.NEG: return 13;
case Token.ARRAYLIT:
case Token.CALL:
case Token.EMPTY:
case Token.FALSE:
case Token.FUNCTION:
case Token.GETELEM:
case Token.GETPROP:
case Token.GET_REF:
case Token.IF:
case Token.LP:
case Token.NAME:
case Token.NULL:
case Token.NUMBER:
case Token.OBJECTLIT:
case Token.REGEXP:
case Token.RETURN:
case Token.STRING:
case Token.THIS:
case Token.TRUE:
return 15;
default: throw new Error("Unknown precedence for " +
Node.tokenToName(type) +
" (type " + type + ")");
}
}