本文整理汇总了Java中com.google.javascript.rhino.Token.REGEXP属性的典型用法代码示例。如果您正苦于以下问题:Java Token.REGEXP属性的具体用法?Java Token.REGEXP怎么用?Java Token.REGEXP使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.REGEXP属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: visit
/**
* {@inheritDoc}
*/
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.STRING &&
parent.getType() != Token.GETPROP &&
parent.getType() != Token.REGEXP &&
!NodeUtil.isObjectLitKey(n, parent)) {
String s = n.getString();
for (blacklist.reset(s); blacklist.find();) {
if (insideGetCssNameCall(n, parent)) {
continue;
}
if (insideGetUniqueIdCall(n, parent)) {
continue;
}
if (insideAssignmentToIdConstant(n, parent)) {
continue;
}
compiler.report(JSError.make(t, n, level, MISSING_GETCSSNAME,
blacklist.group()));
}
}
}
示例3: getBooleanValue
/**
* Gets the boolean value of a node that represents a literal. This method
* effectively emulates the <code>Boolean()</code> JavaScript cast function.
*
* @throws IllegalArgumentException If {@code n} is not a literal value
*/
static boolean getBooleanValue(Node n) {
switch (n.getType()) {
case Token.STRING:
return n.getString().length() > 0;
case Token.NUMBER:
return n.getDouble() != 0;
case Token.NULL:
case Token.FALSE:
case Token.VOID:
return false;
case Token.NAME:
String name = n.getString();
if ("undefined".equals(name)
|| "NaN".equals(name)) {
// We assume here that programs don't change the value of the keyword
// undefined to something other than the value undefined.
return false;
} else if ("Infinity".equals(name)) {
return true;
}
break;
case Token.TRUE:
case Token.ARRAYLIT:
case Token.OBJECTLIT:
case Token.REGEXP:
return true;
}
throw new IllegalArgumentException("Non-literal value: " + n);
}
示例4: processRegExpLiteral
@Override
Node processRegExpLiteral(RegExpLiteral literalNode) {
Node literalStringNode = Node.newString(literalNode.getValue());
// assume it's on the same line.
literalStringNode.setLineno(literalNode.getLineno());
Node node = new Node(Token.REGEXP, literalStringNode);
String flags = literalNode.getFlags();
if (flags != null && !flags.isEmpty()) {
Node flagsNode = Node.newString(flags);
// Assume the flags are on the same line as the literal node.
flagsNode.setLineno(literalNode.getLineno());
node.addChildToBack(flagsNode);
}
return node;
}
示例5: 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 + ")");
}
}
示例6: visit
/**
* {@inheritDoc}
*/
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.STRING &&
parent.getType() != Token.GETPROP &&
parent.getType() != Token.REGEXP &&
!NodeUtil.isObjectLitKey(n, parent)) {
String str = n.getString();
// "undefined" is special-cased, since it needs to be used when JS code
// is unloading and therefore variable references aren't available.
// This is because of a bug in FireFox.
if ("undefined".equals(str)) {
return;
}
if (blacklist != null && blacklist.reset(str).find()) {
return;
}
if (aliasableStrings == null || aliasableStrings.contains(str)) {
StringOccurrence occurrence = new StringOccurrence(n, parent);
StringInfo info = getOrCreateStringInfo(str);
info.occurrences.add(occurrence);
info.numOccurrences++;
if (t.inGlobalScope() || isInThrowExpression(n)) {
info.numOccurrencesInfrequentlyExecuted++;
}
if (info.numOccurrences == 1) {
info.moduleToContainDecl = t.getModule();
// Take note of the optimal place to insert the var declaration.
// We'll insert it as the previous sibling of our first ancestor
// in global scope that has a SCRIPT parent.
Node prev = n;
for (Node ancestor : n.getAncestors()) {
if (ancestor.getType() == Token.SCRIPT) {
info.parentForNewVarDecl = ancestor;
info.siblingToInsertVarDeclBefore = prev;
break;
}
prev = ancestor;
}
} else {
// Check whether the current module depends on the module containing
// the declaration.
JSModule module = t.getModule();
if (module != null &&
info.moduleToContainDecl != null &&
module != info.moduleToContainDecl &&
!moduleGraph.dependsOn(module, info.moduleToContainDecl)) {
// We need to declare this string in the deepest module in the
// module dependency graph that both of these modules depend on.
module = moduleGraph.getDeepestCommonDependency(
module, info.moduleToContainDecl);
Node varParent = moduleVarParentMap.get(module);
if (varParent == null) {
varParent = compiler.getNodeForCodeInsertion(module);
moduleVarParentMap.put(module, varParent);
}
info.moduleToContainDecl = module;
info.parentForNewVarDecl = varParent;
info.siblingToInsertVarDeclBefore = varParent.getFirstChild();
}
}
}
}
}