本文整理汇总了Java中com.google.javascript.rhino.Node.getLastChild方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getLastChild方法的具体用法?Java Node.getLastChild怎么用?Java Node.getLastChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.getLastChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isControlStructureCodeBlock
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Determines whether the given node is code node for FOR, DO,
* WHILE, WITH, or IF node.
*/
static boolean isControlStructureCodeBlock(Node parent, Node n) {
switch (parent.getType()) {
case Token.FOR:
case Token.WHILE:
case Token.LABEL:
case Token.WITH:
return parent.getLastChild() == n;
case Token.DO:
return parent.getFirstChild() == n;
case Token.IF:
return parent.getFirstChild() != n;
case Token.TRY:
return parent.getFirstChild() == n || parent.getLastChild() == n;
case Token.CATCH:
return parent.getLastChild() == n;
case Token.SWITCH:
case Token.CASE:
return parent.getFirstChild() != n;
case Token.DEFAULT:
return true;
default:
Preconditions.checkState(isControlStructure(parent));
return false;
}
}
示例2: getFunctionValue
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* If the given value is a qualified name which refers
* a function, the function's node is returned. Otherwise,
* {@code null} is returned.
*/
protected Node getFunctionValue(Node value) {
String qualifiedName = value.getQualifiedName();
if (qualifiedName == null) {
return null;
}
if (!definitionMap.containsKey(qualifiedName)) {
return null;
}
Node definitionParent = definitionMap.get(qualifiedName);
Node definition = definitionParent.getLastChild();
if (definition.getType() != Token.FUNCTION) {
return null;
}
return definition;
}
示例3: getPreciserScopeKnowingConditionOutcome
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public FlowScope getPreciserScopeKnowingConditionOutcome(Node condition,
FlowScope blindScope, boolean outcome) {
if (condition.getType() == CALL && condition.getChildCount() == 2) {
Node callee = condition.getFirstChild();
Node param = condition.getLastChild();
if (callee.getType() == GETPROP && param.isQualifiedName()) {
JSType paramType = getTypeIfRefinable(param, blindScope);
Node left = callee.getFirstChild();
Node right = callee.getLastChild();
if (left.getType() == NAME && "goog".equals(left.getString()) &&
right.getType() == STRING) {
Function<TypeRestriction, JSType> restricter =
restricters.get(right.getString());
if (restricter != null) {
return restrictParameter(param, paramType, blindScope, restricter,
outcome);
}
}
}
}
return nextPreciserScopeKnowingConditionOutcome(
condition, blindScope, outcome);
}
示例4: rewriteDefinition
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Rewrites method definitions as global functions that take "this"
* as their first argument.
*
* Before:
* a.prototype.b = function(a, b, c) {...}
*
* After:
* var b = function(self, a, b, c) {...}
*/
private void rewriteDefinition(Node node, String newMethodName) {
Node parent = node.getParent();
Node functionNode = parent.getLastChild();
Node expr = parent.getParent();
Node block = expr.getParent();
Node newNameNode = Node.newString(Token.NAME, newMethodName);
parent.removeChild(functionNode);
newNameNode.addChildToFront(functionNode);
block.replaceChild(expr, new Node(Token.VAR, newNameNode));
// add extra argument
String self = newMethodName + "$self";
Node argList = functionNode.getFirstChild().getNext();
argList.addChildToFront(Node.newString(Token.NAME, self));
// rewrite body
Node body = functionNode.getLastChild();
replaceReferencesToThis(body, self);
// fix type
fixFunctionType(functionNode);
compiler.reportCodeChange();
}
示例5: getMaxArguments
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Gets the maximum number of arguments that this function requires,
* or Integer.MAX_VALUE if this is a variable argument function.
*/
public int getMaxArguments() {
Node params = getParametersNode();
if (params != null) {
Node lastParam = params.getLastChild();
if (lastParam == null || !lastParam.isVarArgs()) {
return params.getChildCount();
}
}
return Integer.MAX_VALUE;
}
示例6: getLoopCodeBlock
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* @param n The node to inspect.
* @return If the node, is a FOR, WHILE, or DO, it returns the node for
* the code BLOCK, null otherwise.
*/
static Node getLoopCodeBlock(Node n) {
switch (n.getType()) {
case Token.FOR:
case Token.WHILE:
return n.getLastChild();
case Token.DO:
return n.getFirstChild();
default:
return null;
}
}
示例7: tryRemoveRepeatedStatements
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Try to remove duplicate statements from IF blocks. For example:
*
* if (a) {
* x = 1;
* return true;
* } else {
* x = 2;
* return true;
* }
*
* becomes:
*
* if (a) {
* x = 1;
* } else {
* x = 2;
* }
* return true;
*
* @param n The IF node to examine.
*/
private void tryRemoveRepeatedStatements(NodeTraversal t, Node n) {
Preconditions.checkState(n.getType() == Token.IF);
Node parent = n.getParent();
if (!NodeUtil.isStatementBlock(parent)) {
// If the immediate parent is something like a label, we
// can't move the statement, so bail.
return;
}
Node cond = n.getFirstChild();
Node trueBranch = cond.getNext();
Node falseBranch = trueBranch.getNext();
Preconditions.checkNotNull(trueBranch);
Preconditions.checkNotNull(falseBranch);
while (true) {
Node lastTrue = trueBranch.getLastChild();
Node lastFalse = falseBranch.getLastChild();
if (lastTrue == null || lastFalse == null
|| !compiler.areNodesEqualForInlining(lastTrue, lastFalse)) {
break;
}
lastTrue.detachFromParent();
lastFalse.detachFromParent();
parent.addChildAfter(lastTrue, n);
t.getCompiler().reportCodeChange();
}
}
示例8: removeChild
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/** 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());
}
}
示例9: traverseFunction
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Traverses a function, which creates a new scope in javascript.
*
* Note that CATCH blocks also create a new scope, but only for the
* catch variable. Declarations within the block actually belong to the
* enclosing scope. Because we don't remove catch variables, there's
* no need to treat CATCH blocks differently like we do functions.
*/
private void traverseFunction(Node n, Scope scope) {
Preconditions.checkState(n.getChildCount() == 3);
Preconditions.checkState(n.getType() == Token.FUNCTION);
final Node body = n.getLastChild();
Preconditions.checkState(body.getNext() == null &&
body.getType() == Token.BLOCK);
Scope fnScope = new SyntacticScopeCreator(compiler_).createScope(n, scope);
traverseNode(body, n, fnScope);
removeUnreferencedFunctionArgs(n, fnScope);
removeUnreferencedVars(fnScope);
}
示例10: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
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();
}
示例11: testMergeBlock2
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testMergeBlock2() {
Compiler compiler = new Compiler();
// Test removing the initializer.
Node actual = parse("foo:{a();}");
Node parentLabel = actual.getFirstChild();
Node childBlock = parentLabel.getLastChild();
assertTrue(NodeUtil.tryMergeBlock(childBlock));
String expected = "foo:a();";
String difference = parse(expected).checkTreeEquals(actual);
assertNull("Nodes do not match:\n" + difference, difference);
}
示例12: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.ASSIGN) {
Node nameNode = n.getFirstChild();
Node valueNode = n.getLastChild();
if (nameNode.isQualifiedName() &&
valueNode.isQualifiedName() &&
ABSTRACT_METHOD_NAME.equals(valueNode.getQualifiedName())) {
abstractMethodAssignmentNodes.add(new RemovableAssignment(
n.getFirstChild(), n, t));
}
}
}
示例13: maybeGetSingleReturnRValue
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* @return function return value node if function body contains a
* single return statement. Otherwise, null.
*/
protected final Node maybeGetSingleReturnRValue(Node functionNode) {
Node body = functionNode.getLastChild();
if (!body.hasOneChild()) {
return null;
}
Node statement = body.getFirstChild();
if (statement.getType() == Token.RETURN) {
return statement.getFirstChild();
}
return null;
}
示例14: enterScope
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public void enterScope(NodeTraversal t) {
Node declarationRoot = t.getScopeRoot();
Renamer renamer;
if (nameStack.isEmpty()) {
// If the contextual renamer is being used the starting context can not
// be a function.
Preconditions.checkState(
declarationRoot.getType() != Token.FUNCTION ||
!(rootRenamer instanceof ContextualRenamer));
Preconditions.checkState(t.inGlobalScope());
renamer = rootRenamer;
} else {
renamer = nameStack.peek().forChildScope();
}
if (declarationRoot.getType() == Token.FUNCTION) {
// Add the function parameters
Node fnParams = declarationRoot.getFirstChild().getNext();
for (Node c = fnParams.getFirstChild(); c != null; c = c.getNext()) {
String name = c.getString();
renamer.addDeclaredName(name);
}
// Add the function body declarations
Node functionBody = declarationRoot.getLastChild();
findDeclaredNames(functionBody, null, renamer);
} else {
// Add the block declarations
findDeclaredNames(declarationRoot, null, renamer);
}
nameStack.push(renamer);
}
示例15: testCommentPositions
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testCommentPositions() {
Node root = newParse("/** @param {string} x */function a(x) {};" +
"/** @param {string} x */function b(x) {}");
Node a = root.getFirstChild();
Node b = root.getLastChild();
assertMarkerPosition(a, 0, 4);
assertMarkerPosition(b, 0, 45);
}