本文整理汇总了Java中com.google.javascript.rhino.Token.STRING属性的典型用法代码示例。如果您正苦于以下问题:Java Token.STRING属性的具体用法?Java Token.STRING怎么用?Java Token.STRING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.STRING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
/** {@inheritDoc} */
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.GETELEM:
Node left = n.getFirstChild();
Node right = left.getNext();
if (right.getType() == Token.STRING &&
NodeUtil.isValidPropertyName(right.getString())) {
n.removeChild(left);
n.removeChild(right);
parent.replaceChild(n, new Node(Token.GETPROP, left, right));
compiler.reportCodeChange();
}
break;
}
}
示例2: countCallCandidates
/**
* Counts references to property names that occur in a special function
* call.
*
* @param callNode The CALL node for a property
* @param t The traversal
*/
private void countCallCandidates(NodeTraversal t, Node callNode) {
Node firstArg = callNode.getFirstChild().getNext();
if (firstArg.getType() != Token.STRING) {
t.report(callNode, BAD_CALL);
return;
}
for (String name : firstArg.getString().split("[.]")) {
if (!TokenStream.isJSIdentifier(name)) {
t.report(callNode, BAD_ARG, name);
continue;
}
if (!externedNames.contains(name)) {
countPropertyOccurrence(name, t);
}
}
}
示例3: identifyTypeDeclarationCall
@Override
public List<String> identifyTypeDeclarationCall(Node n) {
Node callName = n.getFirstChild();
if ("goog.addDependency".equals(callName.getQualifiedName()) &&
n.getChildCount() >= 3) {
Node typeArray = callName.getNext().getNext();
if (typeArray.getType() == Token.ARRAYLIT) {
List<String> typeNames = Lists.newArrayList();
for (Node name = typeArray.getFirstChild(); name != null;
name = name.getNext()) {
if (name.getType() == Token.STRING) {
typeNames.add(name.getString());
}
}
return typeNames;
}
}
return null;
}
示例4: reduce
@Override
public Node reduce(Node node) {
if (!NodeUtil.isAnonymousFunction(node)) {
return node;
}
Node propName = getGetPropertyName(node);
if (propName != null) {
if (propName.getType() != Token.STRING) {
throw new IllegalStateException(
"Expected STRING, got " + Token.name(propName.getType()));
}
return buildCallNode(FACTORY_METHOD_NAME, propName,
node.getLineno(), node.getCharno());
} else {
return node;
}
}
示例5: 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) {
reservedNames.add(dest.getString());
}
}
}
示例6: 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 &&
(whitelist.isEmpty() || whitelist.contains(dest.getString()))) {
props.put(dest.getString(), new Property(dest.getString()));
}
}
}
示例7: transformAsString
/**
* Transforms the given node and then sets its type to Token.STRING if it
* was Token.NAME. If its type was already Token.STRING, then quotes it.
* Used for properties, as the old AST uses String tokens, while the new one
* uses Name tokens for unquoted strings. For example, in
* var o = {'a' : 1, b: 2};
* the string 'a' is quoted, while the name b is turned into a string, but
* unquoted.
*/
private Node transformAsString(AstNode n) {
Node ret = transform(n);
if (ret.getType() == Token.STRING) {
ret.putBooleanProp(Node.QUOTED_PROP, true);
} else if (ret.getType() == Token.NAME) {
ret.setType(Token.STRING);
}
return ret;
}
示例8: getStringValue
/**
* Gets the value of a node as a String, or null if it cannot be converted.
* When it returns a non-null String, this method effectively emulates the
* <code>String()</code> JavaScript cast function.
*/
static String getStringValue(Node n) {
// TODO(user): Convert constant array, object, and regex literals as well.
switch (n.getType()) {
case Token.NAME:
case Token.STRING:
return n.getString();
case Token.NUMBER:
double value = n.getDouble();
long longValue = (long) value;
// Return "1" instead of "1.0"
if (longValue == value) {
return Long.toString(longValue);
} else {
return Double.toString(n.getDouble());
}
case Token.FALSE:
case Token.TRUE:
case Token.NULL:
return Node.tokenToName(n.getType());
case Token.VOID:
return "undefined";
}
return null;
}
示例9: nameEndsWithFieldNameToStrip
/**
* Gets whether a name ends with a field name that should be stripped. For
* example, this function would return true when passed "this.logger" or
* "a.b.c.myLogger" if "logger" is a strip name.
*
* @param n A node (typically a GETPROP node)
* @return Whether the name ends with a field name that should be stripped
*/
boolean nameEndsWithFieldNameToStrip(@Nullable Node n) {
if (n != null && n.getType() == Token.GETPROP) {
Node propNode = n.getLastChild();
return propNode != null && propNode.getType() == Token.STRING &&
isStripName(propNode.getString());
}
return false;
}
示例10: isValidDefineValue
/**
* Determines whether the given value may be assigned to a define.
*
* @param val The value being assigned.
* @param defines The list of names of existing defines.
*/
static boolean isValidDefineValue(Node val, Set<String> defines) {
switch (val.getType()) {
case Token.STRING:
case Token.NUMBER:
case Token.TRUE:
case Token.FALSE:
return true;
// Single operators are valid if the child is valid.
case Token.BITAND:
case Token.BITNOT:
case Token.BITOR:
case Token.BITXOR:
case Token.NOT:
case Token.NEG:
return isValidDefineValue(val.getFirstChild(), defines);
// Names are valid if and only if they are defines themselves.
case Token.NAME:
case Token.GETPROP:
if (val.isQualifiedName()) {
return defines.contains(val.getQualifiedName());
}
}
return false;
}
示例11: isObjectCallMethod
/**
* @return Whether node is a call to methodName.
* a.f(...)
* a['f'](...)
*/
static boolean isObjectCallMethod(Node callNode, String methodName) {
if (callNode.getType() == Token.CALL) {
Node functionIndentifyingExpression = callNode.getFirstChild();
if (NodeUtil.isGet(functionIndentifyingExpression)) {
Node last = functionIndentifyingExpression.getLastChild();
if (last != null && last.getType() == Token.STRING) {
String propName = last.getString();
return (propName.equals(methodName));
}
}
}
return false;
}
示例12: isInlineableDeclaredConstant
/**
* Determines whether the given variable is declared as a constant
* and may be inlined.
*/
private boolean isInlineableDeclaredConstant(Var var,
ReferenceCollection refInfo) {
if (!identifyConstants.apply(var)) {
return false;
}
if (!refInfo.isAssignedOnce()) {
return false;
}
Reference init = refInfo.getInitializingReferenceForConstants();
if (init == null) {
return false;
}
Node value = init.getAssignedValue();
if (value == null) {
// This constant is either externally defined or initialized indirectly
// (e.g. in an anonymous function used to hide
// temporary variables), so the constant is ineligible for inlining.
return false;
}
// Is the constant's value immutable?
if (!NodeUtil.isImmutableValue(value)) {
return false;
}
// Determine if we should really inline a String or not.
return value.getType() != Token.STRING ||
isStringWorthInlining(var, refInfo.references);
}
示例13: visit
public void visit(NodeTraversal t, Node n, Node parent) {
if (OBJECT_PROPERTY_STRING.equals(n.getQualifiedName())) {
Node newName =
Node.newString(Token.NAME, EXTERN_OBJECT_PROPERTY_STRING);
newName.copyInformationFrom(n);
parent.replaceChild(n, newName);
compiler.reportCodeChange();
return;
}
// Rewrite "new goog.testing.ObjectPropertyString(foo, 'bar')" to
// "new goog.testing.ObjectPropertyString(window, foo.bar)" and
// issues errors if bad arguments are encountered.
if (n.getType() != Token.NEW) {
return;
}
Node objectName = n.getFirstChild();
if (!EXTERN_OBJECT_PROPERTY_STRING.equals(
objectName.getQualifiedName())) {
return;
}
if (n.getChildCount() != 3) {
compiler.report(JSError.make(t, n, INVALID_NUM_ARGUMENTS_ERROR,
"" + n.getChildCount()));
return;
}
Node firstArgument = objectName.getNext();
if (!firstArgument.isQualifiedName()) {
compiler.report(JSError.make(t, firstArgument,
QUALIFIED_NAME_EXPECTED_ERROR,
Token.name(firstArgument.getType())));
return;
}
Node secondArgument = firstArgument.getNext();
if (secondArgument.getType() != Token.STRING) {
compiler.report(JSError.make(t, secondArgument,
STRING_LITERAL_EXPECTED_ERROR,
Token.name(secondArgument.getType())));
return;
}
Node newFirstArgument = NodeUtil.newQualifiedNameNode(
compiler.getCodingConvention().getGlobalObject(),
firstArgument.getLineno(), firstArgument.getCharno());
Node newSecondArgument = NodeUtil.newQualifiedNameNode(
firstArgument.getQualifiedName() + "." +
firstArgument.getNext().getString(),
secondArgument.getLineno(), secondArgument.getCharno());
n.replaceChild(firstArgument, newFirstArgument);
n.replaceChild(secondArgument, newSecondArgument);
compiler.reportCodeChange();
}
示例14: isString
/**
* Is this a STRING node?
*/
static boolean isString(Node n) {
return n.getType() == Token.STRING;
}
示例15: visit
/**
* Looks for property reads and writes.
*/
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) {
if (parent.getType() == Token.ASSIGN &&
parent.getFirstChild() == n ||
NodeUtil.isExpressionNode(parent)) {
// The property is the *target* of the assign, like:
// x.foo = ...;
// or else it's a stub property for duck-typing, like:
// x.foo;
addWrite(dest, t, false);
} else {
addRead(dest, t);
}
}
break;
case Token.OBJECTLIT:
// Object literals have their property name/value pairs as a flat
// list as their children. We want every other node in order to get
// only the property names.
boolean isKey = true;
for (Node child = n.getFirstChild();
child != null;
child = child.getNext()) {
if (isKey && child.getType() == Token.STRING) {
addWrite(child, t, true);
}
isKey = !isKey;
}
break;
case Token.CALL:
// Some generated code accesses properties using a special function
// call syntax that has meaning only to the compiler.
Node callee = n.getFirstChild();
if (callee.getType() == Token.NAME &&
callee.getString().equals(
RenameProperties.RENAME_PROPERTY_FUNCTION_NAME)) {
Node argument = callee.getNext();
if (argument.getType() == Token.STRING) {
// Not sure how the property names will be used, so count as both
// reads and writes to keep this pass silent about them.
for (String name : DOT_PATTERN.split(argument.getString())) {
Property prop = getProperty(name);
prop.readCount++;
prop.writeCount++;
prop.reads = null;
prop.writes = null;
}
}
}
break;
}
}