本文整理汇总了Java中com.google.javascript.rhino.Token.OBJECTLIT属性的典型用法代码示例。如果您正苦于以下问题:Java Token.OBJECTLIT属性的具体用法?Java Token.OBJECTLIT怎么用?Java Token.OBJECTLIT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.OBJECTLIT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLiteralValue
/**
* Returns true if this is a literal value. We define a literal value
* as any node that evaluates to the same thing regardless of when or
* where it is evaluated. So /xyz/ and [3, 5] are literals, but
* function() { return a; } is not.
*/
static boolean isLiteralValue(Node n) {
// TODO(nicksantos): Refine this function to catch more literals.
switch (n.getType()) {
case Token.ARRAYLIT:
case Token.OBJECTLIT:
case Token.REGEXP:
// Return true only if all children are const.
for (Node child = n.getFirstChild(); child != null;
child = child.getNext()) {
if (!isLiteralValue(child)) {
return false;
}
}
return true;
default:
return isImmutableValue(n);
}
}
示例2: getObjectLiteralCast
@Override
public ObjectLiteralCast getObjectLiteralCast(NodeTraversal t,
Node callNode) {
Preconditions.checkArgument(callNode.getType() == Token.CALL);
Node callName = callNode.getFirstChild();
if (!"goog.reflect.object".equals(callName.getQualifiedName()) ||
callName.getChildCount() != 2) {
return null;
}
Node typeNode = callName.getNext();
if (!typeNode.isQualifiedName()) {
return null;
}
Node objectNode = typeNode.getNext();
if (objectNode.getType() != Token.OBJECTLIT) {
t.getCompiler().report(JSError.make(t.getSourceName(), callNode,
OBJECTLIT_EXPECTED));
return null;
}
return new ObjectLiteralCast(typeNode.getQualifiedName(),
typeNode.getNext());
}
示例3: isConstructorOrEnumDeclaration
/**
* Determines whether a set operation is a constructor or enumeration
* declaration. The set operation may either be an assignment to a name,
* a variable declaration, or an object literal key mapping.
*
* @param n The node that represents the name being set
* @param parent Parent node of {@code n} (an ASSIGN, VAR, or OBJLIT node)
* @return Whether the set operation is either a constructor or enum
* declaration
*/
private boolean isConstructorOrEnumDeclaration(Node n, Node parent) {
JSDocInfo info;
int valueNodeType;
switch (parent.getType()) {
case Token.ASSIGN:
info = parent.getJSDocInfo();
valueNodeType = n.getNext().getType();
break;
case Token.VAR:
info = n.getJSDocInfo();
if (info == null) {
info = parent.getJSDocInfo();
}
Node valueNode = n.getFirstChild();
valueNodeType = valueNode != null ? valueNode.getType() : Token.VOID;
break;
default:
return false;
}
// Heed the annotations only if they're sensibly used.
return info != null &&
(info.isConstructor() && valueNodeType == Token.FUNCTION ||
info.hasEnumParameterType() && valueNodeType == Token.OBJECTLIT);
}
示例4: visit
@Override public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.WITH) {
t.report(n, WITH_DISALLOWED);
} else if (n.getType() == Token.NAME) {
if (!NodeUtil.isLabelName(n) && !isDeclaration(n)) {
checkNameUse(t, n);
}
} else if (n.getType() == Token.ASSIGN) {
checkAssignment(t, n);
} else if (n.getType() == Token.DELPROP) {
checkDelete(t, n);
} else if (n.getType() == Token.OBJECTLIT) {
checkObjectLiteral(t, n);
} else if (n.getType() == Token.LABEL) {
checkLabel(t, n);
}
}
示例5: visit
/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.GETPROP:
Node dest = n.getFirstChild().getNext();
if (dest.getType() == Token.STRING) {
externedNames.add(dest.getString());
}
break;
case Token.OBJECTLIT:
for (Node child = n.getFirstChild();
child != null;
child = child.getNext().getNext()) {
if (child.getType() == Token.STRING) {
externedNames.add(child.getString());
}
}
break;
}
}
示例6: 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();
}
示例7: visit
/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.GETPROP:
Node dest = n.getFirstChild().getNext();
externedNames.add(dest.getString());
break;
case Token.OBJECTLIT:
for (Node child = n.getFirstChild();
child != null;
child = child.getNext().getNext()) {
if (child.getType() == Token.STRING) {
externedNames.add(child.getString());
}
}
break;
}
}
示例8: determineType
@Override
public TypeInfo determineType() {
if(node.getType() == Token.NUMBER) return new TypeInfo(this, JavaScriptDictionary.NUMBER);
else if(node.getType() == Token.STRING) return new TypeInfo(this, JavaScriptDictionary.STRING);
else if(node.getType() == Token.TRUE || node.getType() == Token.FALSE) return new TypeInfo(this, JavaScriptDictionary.BOOL);
else if(node.getType() == Token.THIS) {
// Is this "this" reference declared in a function declared in an object literal? If so, it's type info
// should include the scope of the object literal, so that functions called with respect to "this" first
// search the object literal for matching functions. Not infallible, but a good guess.
CFGFunction function = getFunction();
ScriptOrFnNode funNode = function.getFunctionNode();
if(funNode.getParent() != null && funNode.getParent().getType() == Token.OBJECTLIT) {
JavaScriptType type = getFunction().getFeedlack().getObjectLiteralType(funNode.getParent());
if(type != null)
return new TypeInfo(this, type);
}
return new TypeInfo(this, JavaScriptDictionary.NONE);
}
else return new TypeInfo(this, JavaScriptDictionary.NONE);
}
示例9: nameObjectLiteralMethods
private void nameObjectLiteralMethods(Node objectLiteral, String context) {
// Object literals are a list of key-value pairs. All object
// literals produced by the parser have an even number of
// children.
Preconditions.checkState(objectLiteral.getChildCount() % 2 == 0);
for (Node keyNode = objectLiteral.getFirstChild();
keyNode != null;
keyNode = keyNode.getNext().getNext()) { // skip 2 for next key
Node valueNode = keyNode.getNext();
// Object literal keys may be strings or numbers. Numbers are
// skipped because name tokens may not start with a number.
if (keyNode.getType() == Token.STRING) {
// concatenate the context and key name to get a new qualified name.
String name = namer.getCombinedName(context, namer.getName(keyNode));
int type = valueNode.getType();
if (type == Token.FUNCTION) {
// set name if function is anonymous
Node functionNameNode = valueNode.getFirstChild();
String functionName = functionNameNode.getString();
if (functionName.isEmpty()) {
namer.setFunctionName(name, valueNode);
}
} else if (type == Token.OBJECTLIT) {
// process nested object literal
nameObjectLiteralMethods(valueNode, name);
}
}
}
}
示例10: processObjectLiteral
@Override
Node processObjectLiteral(ObjectLiteral literalNode) {
if (literalNode.isDestructuring()) {
reportDestructuringAssign(literalNode);
}
Node node = new Node(Token.OBJECTLIT);
for (ObjectProperty el : literalNode.getElements()) {
node.addChildToBack(transformAsString(el.getLeft()));
node.addChildToBack(transform(el.getRight()));
}
return node;
}
示例11: updateObjLitOrFunctionDeclarationAtVarNode
/**
* Updates the first initialization (a.k.a "declaration") of a global name
* that occurs at a VAR node. See comment for
* {@link #updateObjLitOrFunctionDeclaration}.
*
* @param n An object representing a global name (e.g. "a")
*/
private void updateObjLitOrFunctionDeclarationAtVarNode(Name n) {
Ref ref = n.declaration;
String name = ref.node.getString();
Node rvalue = ref.node.getFirstChild();
Node varNode = ref.node.getParent();
Node gramps = varNode.getParent();
boolean isObjLit = rvalue.getType() == Token.OBJECTLIT;
int numChanges = 0;
if (isObjLit) {
boolean discardKeys = n.aliasingGets == 0;
numChanges += declareVarsForObjLitValues(
n, name, rvalue, varNode, gramps.getChildBefore(varNode),
gramps, discardKeys);
}
numChanges += addStubsForUndeclaredProperties(n, name, gramps, varNode);
if (isObjLit && n.canEliminate()) {
varNode.removeChild(ref.node);
if (!varNode.hasChildren()) {
gramps.removeChild(varNode);
}
numChanges++;
// Clear out the object reference, since we've eliminated it from the
// parse tree.
ref.node = null;
}
if (numChanges > 0) {
compiler.reportCodeChange();
}
}
示例12: canMoveValue
/**
* Determines whether the given value is eligible to be moved across modules.
*/
private boolean canMoveValue(Node n) {
// the value is only movable if it's
// a) nothing,
// b) a constant literal,
// c) a function, or
// d) an array/object literal of movable values.
// e) a function stub generated by CrossModuleMethodMotion.
if (n == null || NodeUtil.isLiteralValue(n) ||
n.getType() == Token.FUNCTION) {
return true;
} else if (n.getType() == Token.CALL) {
Node functionName = n.getFirstChild();
return functionName.getType() == Token.NAME &&
(functionName.getString().equals(
CrossModuleMethodMotion.STUB_METHOD_NAME) ||
functionName.getString().equals(
CrossModuleMethodMotion.UNSTUB_METHOD_NAME));
} else if (n.getType() == Token.ARRAYLIT ||
n.getType() == Token.OBJECTLIT) {
for (Node child = n.getFirstChild(); child != null;
child = child.getNext()) {
if (!canMoveValue(child)) {
return false;
}
}
return true;
}
return false;
}
示例13: visit
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.GETPROP:
case Token.GETELEM:
Node dest = n.getFirstChild().getNext();
if (dest.getType() == Token.STRING) {
if (dest.getString().equals("prototype")) {
processPrototypeParent(t, parent);
} else {
// Static methods of the form Foo.bar = function() {} or
// Static methods of the form Foo.bar = baz (where baz is a
// function name). Parse tree looks like:
// assign <- parent
// getprop <- n
// name Foo
// string bar
// function or name <- n.getNext()
if (parent.getType() == Token.ASSIGN &&
parent.getFirstChild() == n) {
addPossibleSignature(dest.getString(), n.getNext(), t);
}
}
}
break;
case Token.OBJECTLIT:
// assumes the object literal is well formed
// (has an even number of children)
for (Node key = n.getFirstChild();
key != null; key = key.getNext().getNext()) {
if (key.getType() == Token.STRING) {
Node value = key.getNext();
addPossibleSignature(key.getString(), value, t);
}
}
break;
}
}
示例14: checkEnumInitializer
/**
* <p>Checks the initializer of an enum. An enum can be initialized with an
* object literal whose values must be subtypes of the declared enum element
* type, or by copying another enum.</p>
*
* <p>In the case of an enum copy, we verify that the enum element type of the
* enum used for initialization is a subtype of the enum element type of
* the enum the value is being copied in.</p>
*
* <p>Examples:</p>
* <pre>var myEnum = {FOO: ..., BAR: ...};
* var myEnum = myOtherEnum;</pre>
*
* @param value the value used for initialization of the enum
* @param primitiveType The type of each element of the enum.
*/
private void checkEnumInitializer(
NodeTraversal t, Node value, JSType primitiveType) {
if (value.getType() == Token.OBJECTLIT) {
// re-using value as the value of the object literal and advancing twice
value = value.getFirstChild();
value = (value == null) ? null : value.getNext();
while (value != null) {
// the value's type must be assignable to the enum's primitive type
validator.expectCanAssignTo(t, value, getJSType(value), primitiveType,
"element type must match enum's type");
// advancing twice
value = value.getNext();
value = (value == null) ? null : value.getNext();
}
} else if (value.getJSType() instanceof EnumType) {
// TODO(user): Remove the instanceof check in favor
// of a type.isEnumType() predicate. Currently, not all enum types are
// implemented by the EnumClass, e.g. the unknown type and the any
// type. The types need to be defined by interfaces such that an
// implementation can implement multiple types interface.
EnumType valueEnumType = (EnumType) value.getJSType();
JSType valueEnumPrimitiveType =
valueEnumType.getElementsType().getPrimitiveType();
validator.expectCanAssignTo(t, value, valueEnumPrimitiveType,
primitiveType, "incompatible enum element types");
} else {
// The error condition is handled in TypedScopeCreator.
}
}
示例15: getLValue
@Override
public Node getLValue() {
// TODO(user) revisit: object literal definitions are an example
// of definitions whose lhs doesn't correspond to a node that
// exists in the AST. We will have to change the return type of
// getLValue sooner or later in order to provide this added
// flexibility.
return new Node(Token.GETPROP,
new Node(Token.OBJECTLIT),
name.cloneNode());
}