本文整理汇总了Java中com.google.javascript.rhino.Node.getFirstChild方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getFirstChild方法的具体用法?Java Node.getFirstChild怎么用?Java Node.getFirstChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.rhino.Node
的用法示例。
在下文中一共展示了Node.getFirstChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryReduceReturn
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Reduce "return undefined" or "return void 0" to simply "return".
*/
private void tryReduceReturn(NodeTraversal t, Node n) {
Node result = n.getFirstChild();
if (result != null) {
switch (result.getType()) {
case Token.VOID:
Node operand = result.getFirstChild();
if (!NodeUtil.mayHaveSideEffects(operand)) {
n.removeFirstChild();
t.getCompiler().reportCodeChange();
}
return;
case Token.NAME:
String name = result.getString();
if (name.equals("undefined")) {
n.removeFirstChild();
t.getCompiler().reportCodeChange();
}
return;
}
}
}
示例2: testLinenoCharnoArrayLiteral
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testLinenoCharnoArrayLiteral() throws Exception {
Node n = parse("\n [8, 9]").getFirstChild().getFirstChild();
assertEquals(Token.ARRAYLIT, n.getType());
assertEquals(2, n.getLineno());
assertEquals(2, n.getCharno());
n = n.getFirstChild();
assertEquals(Token.NUMBER, n.getType());
assertEquals(2, n.getLineno());
assertEquals(3, n.getCharno());
n = n.getNext();
assertEquals(Token.NUMBER, n.getType());
assertEquals(2, n.getLineno());
assertEquals(6, n.getCharno());
}
示例3: shouldEmitDeprecationWarning
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Determines whether a deprecation warning should be emitted.
* @param t The current traversal.
* @param n The node which we are checking.
* @param parent The parent of the node which we are checking.
*/
private boolean shouldEmitDeprecationWarning(
NodeTraversal t, Node n, Node parent) {
// In the global scope, there are only two kinds of accesses that should
// be flagged for warnings:
// 1) Calls of deprecated functions and methods.
// 2) Instantiations of deprecated classes.
// For now, we just let everything else by.
if (t.inGlobalScope()) {
if (!((parent.getType() == Token.CALL && parent.getFirstChild() == n) ||
n.getType() == Token.NEW)) {
return false;
}
}
// We can always assign to a deprecated property, to keep it up to date.
if (n.getType() == Token.GETPROP && n == parent.getFirstChild() &&
NodeUtil.isAssignmentOp(parent)) {
return false;
}
return !canAccessDeprecatedTypes(t);
}
示例4: getDefinitionsReferencedAt
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
@Override
public Collection<Definition> getDefinitionsReferencedAt(Node useSite) {
if (definitionSiteMap.containsKey(useSite)) {
return null;
}
if (NodeUtil.isGetProp(useSite)) {
String propName = useSite.getLastChild().getString();
if (propName.equals("apply") || propName.equals("call")) {
useSite = useSite.getFirstChild();
}
}
String name = getSimplifiedName(useSite);
if (name != null) {
Collection<Definition> defs = nameDefinitionMultimap.get(name);
if (!defs.isEmpty()) {
return defs;
} else {
return null;
}
} else {
return null;
}
}
示例5: fixUnitializedVarDeclarations
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* For all VAR node with uninitialized declarations, set
* the values to be "undefined".
*/
private void fixUnitializedVarDeclarations(Node n) {
// Inner loop structure must already have logic to initialize its
// variables. In particular FOR-IN structures must not be modified.
if (NodeUtil.isLoopStructure(n)) {
return;
}
// For all VARs
if (NodeUtil.isVar(n)) {
Node name = n.getFirstChild();
// It isn't initialized.
if (!name.hasChildren()) {
name.addChildToBack(NodeUtil.newUndefinedNode());
}
return;
}
for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
fixUnitializedVarDeclarations(c);
}
}
示例6: isAliasDefinition
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Does the given node define one of our aliases?
*/
private boolean isAliasDefinition(Node n) {
if (n.getType() != Token.NAME) {
return false;
}
if (!isAliasName(n.getString())) {
// The given Node's string contents is not an alias. Skip it.
return false;
}
/*
* A definition must have a child node (otherwise it's just a
* reference to the alias).
*/
return n.getFirstChild() != null;
}
示例7: eliminateKeysWithStripNamesFromObjLit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Eliminates any object literal keys in an object literal declaration that
* have strip names.
*
* @param t The traversal
* @param n An OBJLIT node
*/
void eliminateKeysWithStripNamesFromObjLit(NodeTraversal t, Node n) {
// OBJLIT
// key1
// value1
// ...
Node key = n.getFirstChild();
while (key != null) {
if (key.getType() == Token.STRING &&
isStripName(key.getString())) {
Node value = key.getNext();
Node next = value.getNext();
n.removeChild(key);
n.removeChild(value);
key = next;
compiler.reportCodeChange();
} else {
key = key.getNext().getNext();
}
}
}
示例8: replaceAccessor
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void replaceAccessor(Node getPropNode) {
/*
* BEFORE
getprop
NODE...
string length
AFTER
getelem
NODE...
name PROP_length
*/
Node propNameNode = getPropNode.getLastChild();
String propName = propNameNode.getString();
if (props.get(propName).aliasAccessor) {
Node propSrc = getPropNode.getFirstChild();
getPropNode.removeChild(propSrc);
Node newNameNode =
Node.newString(Token.NAME, getArrayNotationNameFor(propName));
Node elemNode = new Node(Token.GETELEM, propSrc, newNameNode);
replaceNode(getPropNode.getParent(), getPropNode, elemNode);
compiler.reportCodeChange();
}
}
示例9: has
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* @return Whether the predicate is true for the node or any of its children.
*/
static boolean has(Node node,
Predicate<Node> pred,
Predicate<Node> traverseChildrenPred) {
if (pred.apply(node)) {
return true;
}
if (!traverseChildrenPred.apply(node)) {
return false;
}
for (Node c = node.getFirstChild(); c != null; c = c.getNext()) {
if (has(c, pred, traverseChildrenPred)) {
return true;
}
}
return false;
}
示例10: 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);
}
示例11: testFunctionParamLocation
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testFunctionParamLocation() {
Node root = newParse(
"\nfunction\n" +
" foo(a,\n" +
" b,\n" +
" c)\n" +
"{}\n");
Node function = root.getFirstChild();
Node functionName = function.getFirstChild();
Node params = functionName.getNext();
Node param1 = params.getFirstChild();
Node param2 = param1.getNext();
Node param3 = param2.getNext();
Node body = params.getNext();
assertNodePosition(2, 5, function);
assertNodePosition(2, 5, functionName);
// params corresponds to the LP token.
// Can't be on a separate line because of inferred
// semicolons.
assertNodePosition(2, 8, params);
assertNodePosition(2, 9, param1);
assertNodePosition(3, 5, param2);
assertNodePosition(4, 5, param3);
assertNodePosition(5, 0, body);
}
示例12: createAssignmentActions
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Returns an action for assigning the right-hand-side to the left or null
* if this assignment should be ignored.
*/
private List<Action> createAssignmentActions(
Node lhs, Node rhs, Node parent) {
switch (lhs.getType()) {
case Token.NAME:
ConcreteSlot var = (ConcreteSlot) scope.getSlot(lhs.getString());
Preconditions.checkState(var != null,
"Type tightener could not find variable with name %s",
lhs.getString());
return Lists.<Action>newArrayList(
new VariableAssignAction(var, rhs));
case Token.GETPROP:
Node receiver = lhs.getFirstChild();
return Lists.<Action>newArrayList(
new PropertyAssignAction(receiver, rhs));
case Token.GETELEM:
return Lists.newArrayList();
case Token.GET_REF:
// We ignore ref specials as their types should not be computed.
if (lhs.getFirstChild().getType() == Token.REF_SPECIAL) {
return Lists.newArrayList();
} else {
throw new AssertionError(
"Bad LHS for getref: " + parent.toStringTree());
}
default:
throw new AssertionError(
"Bad LHS for assignment: " + parent.toStringTree());
}
}
示例13: visit
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void visit(NodeTraversal t, Node n, Node parent) {
if (n.getType() == Token.FUNCTION) {
Node functionNameNode = n.getFirstChild();
String functionName = functionNameNode.getString();
Node enclosingFunction = t.getEnclosingFunction();
functionMap.put(n,
new FunctionRecord(nextId, enclosingFunction, functionName));
nextId++;
}
}
示例14: replacePrototypeMemberDeclaration
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
* Replaces a member declaration to an assignment to the temp prototype
* object.
*/
private void replacePrototypeMemberDeclaration(
PrototypeMemberDeclaration declar) {
// x.prototype.y = ... -> t.y = ...
Node assignment = declar.node.getFirstChild();
Node lhs = assignment.getFirstChild();
Node name = NodeUtil.newQualifiedNameNode(
prototypeAlias + "." + declar.memberName, declar.node,
declar.memberName);
// Save the full prototype path on the left hand side of the assignment
// for debugging purposes.
// declar.lhs = x.prototype.y so first child of the first child
// is 'x'.
Node accessNode = declar.lhs.getFirstChild().getFirstChild();
Object originalName = accessNode.getProp(Node.ORIGINALNAME_PROP);
String className = "?";
if (originalName != null) {
className = originalName.toString();
}
NodeUtil.setDebugInformation(name.getFirstChild(), lhs,
className + ".prototype");
assignment.replaceChild(lhs, name);
}
示例15: testLinenoCharnoObjectLiteral
import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testLinenoCharnoObjectLiteral() throws Exception {
Node n = parse("\n\n var a = {a:0\n,b :1};")
.getFirstChild().getFirstChild().getFirstChild();
assertEquals(Token.OBJECTLIT, n.getType());
assertEquals(3, n.getLineno());
assertEquals(9, n.getCharno());
n = n.getFirstChild();
assertEquals(Token.STRING, n.getType());
assertEquals(3, n.getLineno());
assertEquals(10, n.getCharno());
n = n.getNext();
assertEquals(Token.NUMBER, n.getType());
assertEquals(3, n.getLineno());
assertEquals(12, n.getCharno());
n = n.getNext();
assertEquals(Token.STRING, n.getType());
assertEquals(4, n.getLineno());
assertEquals(1, n.getCharno());
n = n.getNext();
assertEquals(Token.NUMBER, n.getType());
assertEquals(4, n.getLineno());
assertEquals(4, n.getCharno());
}