本文整理汇总了Java中com.google.javascript.rhino.Token.BLOCK属性的典型用法代码示例。如果您正苦于以下问题:Java Token.BLOCK属性的具体用法?Java Token.BLOCK怎么用?Java Token.BLOCK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.Token
的用法示例。
在下文中一共展示了Token.BLOCK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: normalizeLabels
/**
* Limit the number of special cases where LABELs need to be handled. Only
* BLOCK and loops are allowed to be labeled. Loop labels must remain in
* place as the named continues are not allowed for labeled blocks.
*/
private void normalizeLabels(Node n) {
Preconditions.checkArgument(n.getType() == Token.LABEL);
Node last = n.getLastChild();
switch (last.getType()) {
case Token.LABEL:
case Token.BLOCK:
case Token.FOR:
case Token.WHILE:
case Token.DO:
return;
default:
Node block = new Node(Token.BLOCK);
n.replaceChild(last, block);
block.addChildToFront(last);
reportCodeChange("LABEL normalization");
return;
}
}
示例2: isStatement
/**
* @return Whether the node is used as a statement.
*/
static boolean isStatement(Node n) {
Node parent = n.getParent();
// It is not possible to determine definitely if a node is a statement
// or not if it is not part of the AST. A FUNCTION node, for instance,
// is either part of an expression (as a anonymous function) or as
// a statement.
Preconditions.checkState(parent != null);
switch (parent.getType()) {
case Token.SCRIPT:
case Token.BLOCK:
case Token.LABEL:
return true;
default:
return false;
}
}
示例3: parse
static Node parse(String js, boolean checkTypes) {
Compiler compiler = new Compiler();
Node n = compiler.parseTestCode(js);
if (checkTypes) {
CompilerPass typeResolver = new DefaultPassConfig(null)
.resolveTypes.create(compiler);
Node externs = new Node(Token.SCRIPT);
Node externAndJsRoot = new Node(Token.BLOCK, externs, n);
externAndJsRoot.setIsSyntheticBlock(true);
typeResolver.process(externs, n);
}
assertEquals("Errors for: " + js, 0, compiler.getErrorCount());
return n;
}
示例4: parseTypeExpressionList
/**
* TypeExpressionList := TopLevelTypeExpression
* | TopLevelTypeExpression ',' TypeExpressionList
*/
private Node parseTypeExpressionList(JsDocToken token) {
Node typeExpr = parseTopLevelTypeExpression(token);
if (typeExpr == null) {
return null;
}
Node typeList = new Node(Token.BLOCK);
typeList.addChildToBack(typeExpr);
while (match(JsDocToken.COMMA)) {
next();
skipEOLs();
typeExpr = parseTopLevelTypeExpression(next());
if (typeExpr == null) {
return null;
}
typeList.addChildToBack(typeExpr);
}
return typeList;
}
示例5: isBreakStructure
/**
* Determines whether the given node can be terminated with a BREAK node.
*/
static boolean isBreakStructure(Node n, boolean labeled) {
switch (n.getType()) {
case Token.FOR:
case Token.DO:
case Token.WHILE:
case Token.SWITCH:
return true;
case Token.BLOCK:
case Token.IF:
case Token.TRY:
return labeled;
default:
return false;
}
}
示例6: setUp
@Override
public void setUp() {
passesRun.clear();
compiler = new Compiler();
tracker = new PerformanceTracker(new Node(Token.BLOCK), false);
optimizer = new PhaseOptimizer(compiler, tracker);
}
示例7: removeChild
/** Safely remove children while maintaining a valid node structure. */
static void removeChild(Node parent, Node node) {
// Node parent = node.getParent();
if (isStatementBlock(parent)
|| isSwitchCase(node)
|| isTryFinallyNode(parent, node)) {
// A statement in a block can simply be removed.
parent.removeChild(node);
} else if (parent.getType() == Token.VAR) {
if (parent.hasMoreThanOneChild()) {
parent.removeChild(node);
} else {
// Remove the node from the parent, so it can be reused.
parent.removeChild(node);
// This would leave an empty VAR, remove the VAR itself.
removeChild(parent.getParent(), parent);
}
} else if (node.getType() == Token.BLOCK) {
// Simply empty the block. This maintains source location and
// "synthetic"-ness.
node.detachChildren();
} else if (parent.getType() == Token.LABEL
&& node == parent.getLastChild()) {
// Remove the node from the parent, so it can be reused.
parent.removeChild(node);
// A LABEL without children can not be referred to, remove it.
removeChild(parent.getParent(), parent);
} else if (parent.getType() == Token.FOR
&& parent.getChildCount() == 4) {
// Only Token.FOR can have an Token.EMPTY other control structure
// need something for the condition. Others need to be replaced
// or the structure removed.
parent.replaceChild(node, new Node(Token.EMPTY));
} else {
throw new IllegalStateException("Invalid attempt to remove node: " +
node.toString() + " of "+ parent.toString());
}
}
示例8: processTryStatement
@Override
Node processTryStatement(TryStatement statementNode) {
Node node = new Node(Token.TRY, transform(statementNode.getTryBlock()));
Node block = new Node(Token.BLOCK);
boolean lineSet = false;
for (CatchClause cc : statementNode.getCatchClauses()) {
// Mark the enclosing block at the same line as the first catch
// clause.
if (lineSet == false) {
block.setLineno(cc.getLineno());
lineSet = true;
}
block.addChildToBack(transform(cc));
}
node.addChildToBack(block);
AstNode finallyBlock = statementNode.getFinallyBlock();
if (finallyBlock != null) {
node.addChildToBack(transform(finallyBlock));
}
// If we didn't set the line on the catch clause, then
// we've got an empty catch clause. Set its line to be the same
// as the finally block (to match Old Rhino's behavior.)
if ((lineSet == false) && (finallyBlock != null)) {
block.setLineno(finallyBlock.getLineno());
}
return node;
}
示例9: testNameNode
/**
* Type checks a NAME node and retrieve its type.
*/
private JSType testNameNode(String name) {
Node node = Node.newString(Token.NAME, name);
Node parent = new Node(Token.SCRIPT, node);
Node externs = new Node(Token.BLOCK);
Node externAndJsRoot = new Node(Token.BLOCK, externs, parent);
externAndJsRoot.setIsSyntheticBlock(true);
makeTypeCheck().processForTesting(null, parent);
return node.getJSType();
}
示例10: typeCheck
private Node typeCheck(Node n) {
Node externsNode = new Node(Token.BLOCK);
Node externAndJsRoot = new Node(Token.BLOCK, externsNode, n);
externAndJsRoot.setIsSyntheticBlock(true);
makeTypeCheck().processForTesting(null, n);
return n;
}
示例11: testPartialTraversalOfScope
public void testPartialTraversalOfScope() {
Compiler compiler = new Compiler();
ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, true);
Node script1 = compiler.parseSyntheticCode("cfgtest", "var foo;");
Node script2 = compiler.parseSyntheticCode("cfgtest2", "var bar;");
Node root = new Node(Token.BLOCK, script1, script2);
cfa.process(null, script1);
ControlFlowGraph<Node> cfg = cfa.getCfg();
assertNotNull(cfg.getNode(script1));
assertNull(cfg.getNode(script2));
}
示例12: createNewFileLevelAstParallelizer
public static AstParallelizer createNewFileLevelAstParallelizer(Node root) {
// Split at every node that has a file name prop.
Predicate<Node> shouldSplit = new Predicate<Node>() {
@Override
public boolean apply(Node input) {
String sourceName = (String) input.getProp(Node.SOURCENAME_PROP);
return sourceName != null;
}
};
// Use a string as place holder.
Supplier<Node> placeHolders = new Supplier<Node>() {
@Override
public Node get() {
return NodeUtil.newExpr(Node.newString(TEMP_NAME));
}
};
// Only traverse blocks.
Predicate<Node> shouldTraverse = new Predicate<Node>() {
@Override
public boolean apply(Node n) {
return n.getType() == Token.BLOCK;
}
};
return new AstParallelizer(
shouldSplit, shouldTraverse, placeHolders, root, false);
}
示例13: createAliasFunctionNode
/**
* Creates a function node that takes a single argument, the object to
* throw. The function throws the object.
*/
private static Node createAliasFunctionNode(String aliasName) {
Node parameterName = Node.newString(Token.NAME, "t");
List<Node> parameters = Lists.newArrayList(parameterName.cloneNode());
Node throwStatement = new Node(Token.THROW, parameterName);
Node body = new Node(Token.BLOCK, throwStatement);
return NodeUtil.newFunctionNode(aliasName, parameters, body, -1, -1);
}
示例14: visit
public void visit(NodeTraversal t, Node n, Node parent) {
Node child;
switch (n.getType()) {
case Token.IF:
child = n.getFirstChild().getNext(); // skip the condition child
break;
case Token.WHILE:
case Token.FOR:
child = NodeUtil.getLoopCodeBlock(n);
break;
default:
return; // don't check other types
}
// semicolons cause VOID children. Empty blocks are allowed because
// that's usually intentional, especially with loops.
for (; child != null; child = child.getNext()) {
if ((child.getType() == Token.BLOCK) && (!child.hasChildren())) {
// Only warn on empty blocks that replaced EMPTY nodes. BLOCKs with no
// children are considered OK.
if (child.wasEmptyNode()) {
t.getCompiler().report(
JSError.make(t, n, level, SUSPICIOUS_SEMICOLON));
}
}
}
}
示例15: testClosureTypes
private void testClosureTypes(String js, String description)
throws Exception {
Node n = compiler.parseTestCode(js);
Node externs = new Node(Token.BLOCK);
Node externAndJsRoot = new Node(Token.BLOCK, externs, n);
externAndJsRoot.setIsSyntheticBlock(true);
assertEquals("parsing error: " +
Joiner.on(", ").join(compiler.getErrors()),
0, compiler.getErrorCount());
// For processing goog.addDependency for forward typedefs.
new ProcessClosurePrimitives(compiler, CheckLevel.ERROR, true)
.process(null, n);
CodingConvention convention = compiler.getCodingConvention();
new TypeCheck(compiler,
new ClosureReverseAbstractInterpreter(
convention, registry).append(
new SemanticReverseAbstractInterpreter(
convention, registry))
.getFirst(),
registry)
.processForTesting(null, n);
assertEquals(0, compiler.getErrorCount());
if (description == null) {
assertEquals(
"unexpected warning(s) : " +
Joiner.on(", ").join(compiler.getWarnings()),
0, compiler.getWarningCount());
} else {
assertEquals(1, compiler.getWarningCount());
assertEquals(description, compiler.getWarnings()[0].description);
}
}