com.google.javascript.rhino.Node.getFirstChild()

Here are the examples of the java api com.google.javascript.rhino.Node.getFirstChild() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

528 Examples 7

19 Source : 1_ClosureCodingConvention.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * {@inheritDoc}
 *
 * <p>Understands several different inheritance patterns that occur in
 * Google code (various uses of {@code inherits} and {@code mixin}).
 */
@Override
public SubclreplacedRelationship getClreplacedesDefinedByCall(Node callNode) {
    Node callName = callNode.getFirstChild();
    SubclreplacedType type = typeofClreplacedDefiningName(callName);
    if (type != null) {
        Node subclreplaced = null;
        Node superclreplaced = callNode.getLastChild();
        // There are six possible syntaxes for a clreplaced-defining method:
        // SubClreplaced.inherits(SuperClreplaced)
        // goog.inherits(SubClreplaced, SuperClreplaced)
        // goog$inherits(SubClreplaced, SuperClreplaced)
        // SubClreplaced.mixin(SuperClreplaced.prototype)
        // goog.mixin(SubClreplaced.prototype, SuperClreplaced.prototype)
        // goog$mixin(SubClreplaced.prototype, SuperClreplaced.prototype)
        boolean isDeprecatedCall = callNode.getChildCount() == 2 && callName.getType() == Token.GETPROP;
        if (isDeprecatedCall) {
            // SubClreplaced.inherits(SuperClreplaced)
            subclreplaced = callName.getFirstChild();
        } else if (callNode.getChildCount() == 3) {
            // goog.inherits(SubClreplaced, SuperClreplaced)
            subclreplaced = callName.getNext();
        } else {
            return null;
        }
        if (type == SubclreplacedType.MIXIN) {
            // Only consider mixins that mix two prototypes as related to
            // inheritance.
            if (!endsWithPrototype(superclreplaced)) {
                return null;
            }
            if (!isDeprecatedCall) {
                if (!endsWithPrototype(subclreplaced)) {
                    return null;
                }
                // Strip off the prototype from the name.
                subclreplaced = subclreplaced.getFirstChild();
            }
            superclreplaced = superclreplaced.getFirstChild();
        }
        // bail out if either of the side of the "inherits"
        // isn't a real clreplaced name. This prevents us from
        // doing something weird in cases like:
        // goog.inherits(MySubClreplaced, cond ? SuperClreplaced1 : BaseClreplaced2)
        if (subclreplaced != null && subclreplaced.isUnscopedQualifiedName() && superclreplaced.isUnscopedQualifiedName()) {
            return new SubclreplacedRelationship(type, subclreplaced, superclreplaced);
        }
    }
    return null;
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

private void handleDefault(Node node) {
    // Directly goes to the body. It should not transfer to the next case.
    createEdge(node, Branch.UNCOND, node.getFirstChild());
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Determines if the subtree might throw an exception.
 */
public static boolean mayThrowException(Node n) {
    switch(n.getType()) {
        case Token.CALL:
        case Token.GETPROP:
        case Token.GETELEM:
        case Token.THROW:
        case Token.NEW:
        case Token.replacedIGN:
        case Token.INC:
        case Token.DEC:
        case Token.INSTANCEOF:
            return true;
        case Token.FUNCTION:
            return false;
    }
    for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
        if (!ControlFlowGraph.isEnteringNewCfgNode(c) && mayThrowException(c)) {
            return true;
        }
    }
    return false;
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

private void handleStmtList(Node node) {
    Node parent = node.getParent();
    // Special case, don't add a block of empty CATCH block to the graph.
    if (node.isBlock() && parent != null && parent.isTry() && NodeUtil.getCatchBlock(parent) == node && !NodeUtil.hasCatchHandler(node)) {
        return;
    }
    // A block transfer control to its first child if it is not empty.
    Node child = node.getFirstChild();
    // Function declarations are skipped since control doesn't go into that
    // function (unless it is called)
    while (child != null && child.isFunction()) {
        child = child.getNext();
    }
    if (child != null) {
        createEdge(node, Branch.UNCOND, computeFallThrough(child));
    } else {
        createEdge(node, Branch.UNCOND, computeFollowNode(node, this));
    }
    // Synthetic blocks
    if (parent != null) {
        switch(parent.getType()) {
            case Token.DEFAULT_CASE:
            case Token.CASE:
            case Token.TRY:
                break;
            default:
                if (node.isBlock() && node.isSyntheticBlock()) {
                    createEdge(node, Branch.SYN_BLOCK, computeFollowNode(node, this));
                }
                break;
        }
    }
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Check if label is actually referencing the target control structure. If
 * label is null, it always returns true.
 */
private static boolean matchLabel(Node target, String label) {
    if (label == null) {
        return true;
    }
    while (target.isLabel()) {
        if (target.getFirstChild().getString().equals(label)) {
            return true;
        }
        target = target.getParent();
    }
    return false;
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Computes the destination node of n when we want to fallthrough into the
 * subtree of n. We don't always create a CFG edge into n itself because of
 * DOs and FORs.
 */
static Node computeFallThrough(Node n) {
    switch(n.getType()) {
        case Token.DO:
            return computeFallThrough(n.getFirstChild());
        case Token.FOR:
            if (NodeUtil.isForIn(n)) {
                return n.getFirstChild().getNext();
            }
            return computeFallThrough(n.getFirstChild());
        case Token.LABEL:
            return computeFallThrough(n.getLastChild());
        default:
            return n;
    }
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

private void handleTry(Node node) {
    createEdge(node, Branch.UNCOND, node.getFirstChild());
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

private void handleSwitch(Node node) {
    // Transfer to the first non-DEFAULT CASE. if there are none, transfer
    // to the DEFAULT or the EMPTY node.
    Node next = getNextSiblingOfType(node.getFirstChild().getNext(), Token.CASE, Token.EMPTY);
    if (next != null) {
        // Has at least one CASE or EMPTY
        createEdge(node, Branch.UNCOND, next);
    } else {
        // Has no CASE but possibly a DEFAULT
        if (node.getFirstChild().getNext() != null) {
            createEdge(node, Branch.UNCOND, node.getFirstChild().getNext());
        } else {
            // No CASE, no DEFAULT
            createEdge(node, Branch.UNCOND, computeFollowNode(node, this));
        }
    }
    connectToPossibleExceptionHandler(node, node.getFirstChild());
}

19 Source : 1_ControlFlowAnalysis.java
with GNU General Public License v2.0
from xgdsmileboy

private void handleWith(Node node) {
    // Directly goes to the body. It should not transfer to the next case.
    createEdge(node, Branch.UNCOND, node.getLastChild());
    connectToPossibleExceptionHandler(node, node.getFirstChild());
}

19 Source : 1_FunctionInjector.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * @param fnName The name of this function. This either the name of the
 *  variable to which the function is replacedigned or the name from the FUNCTION
 *  node.
 * @param fnNode The FUNCTION node of the function to inspect.
 * @return Whether the function node meets the minimum requirements for
 * inlining.
 */
boolean doesFunctionMeetMinimumRequirements(final String fnName, Node fnNode) {
    Node block = NodeUtil.getFunctionBody(fnNode);
    // Basic restrictions on functions that can be inlined:
    // 0) The function is inlinable by convention
    // 1) It contains a reference to itself.
    // 2) It uses its parameters indirectly using "arguments" (it isn't
    // handled yet.
    // 3) It references "eval". Inline a function containing eval can have
    // large performance implications.
    if (!compiler.getCodingConvention().isInlinableFunction(fnNode)) {
        return false;
    }
    final String fnRecursionName = fnNode.getFirstChild().getString();
    Preconditions.checkState(fnRecursionName != null);
    // If the function references "arguments" directly in the function
    boolean referencesArguments = NodeUtil.isNameReferenced(block, "arguments", NodeUtil.MATCH_NOT_FUNCTION);
    // or it references "eval" or one of its names anywhere.
    Predicate<Node> p = new Predicate<Node>() {

        @Override
        public boolean apply(Node n) {
            if (n.isName()) {
                return n.getString().equals("eval") || (!fnName.isEmpty() && n.getString().equals(fnName)) || (!fnRecursionName.isEmpty() && n.getString().equals(fnRecursionName));
            }
            return false;
        }
    };
    return !referencesArguments && !NodeUtil.has(block, p, Predicates.<Node>alwaysTrue());
}

19 Source : 1_FunctionInjector.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Inline a function which fulfills the requirements of
 * canInlineReferencereplacedtatementBlock into the call site, replacing the
 * parent expression.
 */
private Node inlineFunction(Node callNode, Node fnNode, String fnName) {
    Node parent = callNode.getParent();
    Node grandParent = parent.getParent();
    // TODO(johnlenz): Consider storing the callSite clreplacedification in the
    // reference object and preplaceding it in here.
    CallSiteType callSiteType = clreplacedifyCallSite(callNode);
    Preconditions.checkArgument(callSiteType != CallSiteType.UNSUPPORTED);
    boolean isCallInLoop = NodeUtil.isWithinLoop(callNode);
    // Store the name for the result. This will be used to
    // replace "return expr" statements with "resultName = expr"
    // to replace
    String resultName = null;
    boolean needsDefaultReturnResult = true;
    switch(callSiteType) {
        case SIMPLE_replacedIGNMENT:
            resultName = parent.getFirstChild().getString();
            break;
        case VAR_DECL_SIMPLE_replacedIGNMENT:
            resultName = parent.getString();
            break;
        case SIMPLE_CALL:
            // "foo()" doesn't need a result.
            resultName = null;
            needsDefaultReturnResult = false;
            break;
        case EXPRESSION:
            throw new IllegalStateException("Movable expressions must be moved before inlining.");
        case DECOMPOSABLE_EXPRESSION:
            throw new IllegalStateException("Decomposable expressions must be decomposed before inlining.");
        default:
            throw new IllegalStateException("Unexpected call site type.");
    }
    FunctionToBlockMutator mutator = new FunctionToBlockMutator(compiler, this.safeNameIdSupplier);
    Node newBlock = mutator.mutate(fnName, fnNode, callNode, resultName, needsDefaultReturnResult, isCallInLoop);
    // TODO(nicksantos): Create a common mutation function that
    // can replace either a VAR name replacedignment, replacedignment expression or
    // a EXPR_RESULT.
    Node greatGrandParent = grandParent.getParent();
    switch(callSiteType) {
        case VAR_DECL_SIMPLE_replacedIGNMENT:
            // Remove the call from the name node.
            parent.removeChild(parent.getFirstChild());
            Preconditions.checkState(parent.getFirstChild() == null);
            // Add the call, after the VAR.
            greatGrandParent.addChildAfter(newBlock, grandParent);
            break;
        case SIMPLE_replacedIGNMENT:
            // The replacedignment is now part of the inline function so
            // replace it completely.
            Preconditions.checkState(grandParent.isExprResult());
            greatGrandParent.replaceChild(grandParent, newBlock);
            break;
        case SIMPLE_CALL:
            // If nothing is looking at the result just replace the call.
            Preconditions.checkState(parent.isExprResult());
            grandParent.replaceChild(parent, newBlock);
            break;
        default:
            throw new IllegalStateException("Unexpected call site type.");
    }
    return newBlock;
}

19 Source : 1_FunctionInjector.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Only ".call" calls and direct calls to functions are supported.
 * @param callNode The call evaluate.
 * @return Whether the call is of a type that is supported.
 */
private boolean isSupportedCallType(Node callNode) {
    if (!callNode.getFirstChild().isName()) {
        if (NodeUtil.isFunctionObjectCall(callNode)) {
            if (!replacedumeStrictThis) {
                Node thisValue = callNode.getFirstChild().getNext();
                if (thisValue == null || !thisValue.isThis()) {
                    return false;
                }
            }
        } else if (NodeUtil.isFunctionObjectApply(callNode)) {
            return false;
        }
    }
    return true;
}

19 Source : VariableVisibilityAnalysisTest.java
with GNU General Public License v2.0
from xgdsmileboy

private void replacedertFunctionHasVisibility(String functionName, VariableVisibility visibility) {
    Node functionNode = searchForFunction(functionName);
    replacedertNotNull(functionNode);
    Node nameNode = functionNode.getFirstChild();
    replacedertEquals(visibility, lastreplacedysis.getVariableVisibility(nameNode));
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment9() {
    Node varNode = parse("/** \n x */var a;").getFirstChild();
    // VAR
    replacedertEquals(Token.VAR, varNode.getType());
    // NAME
    Node nameNode = varNode.getFirstChild();
    replacedertEquals(Token.NAME, nameNode.getType());
    replacedertNull(nameNode.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testLinenoCharnoGetProp2() throws Exception {
    Node getprop = parse("\n foo.\nbar").getFirstChild().getFirstChild();
    replacedertEquals(Token.GETPROP, getprop.getType());
    replacedertEquals(2, getprop.getLineno());
    replacedertEquals(1, getprop.getCharno());
    Node name = getprop.getFirstChild().getNext();
    replacedertEquals(Token.STRING, name.getType());
    replacedertEquals(3, name.getLineno());
    replacedertEquals(0, name.getCharno());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testObjectLiteralDoc1() {
    Node n = parse("var x = {/** @type {number} */ 1: 2};");
    Node objectLit = n.getFirstChild().getFirstChild().getFirstChild();
    replacedertEquals(Token.OBJECTLIT, objectLit.getType());
    Node number = objectLit.getFirstChild();
    replacedertEquals(Token.STRING_KEY, number.getType());
    replacedertNotNull(number.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testFileOverviewJSDoc2() {
    Node n = parse("/** @fileoverview Hi mom! */ " + "/** @constructor */ function Foo() {}");
    replacedertTrue(n.getJSDocInfo() != null);
    replacedertEquals("Hi mom!", n.getJSDocInfo().getFileOverview());
    replacedertTrue(n.getFirstChild().getJSDocInfo() != null);
    replacedertFalse(n.getFirstChild().getJSDocInfo().hasFileOverview());
    replacedertTrue(n.getFirstChild().getJSDocInfo().isConstructor());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testFileOverviewJSDoc1() {
    Node n = parse("/** @fileoverview Hi mom! */ function Foo() {}");
    replacedertEquals(Token.FUNCTION, n.getFirstChild().getType());
    replacedertTrue(n.getJSDocInfo() != null);
    replacedertNull(n.getFirstChild().getJSDocInfo());
    replacedertEquals("Hi mom!", n.getJSDocInfo().getFileOverview());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment10() {
    Node varNode = parse("/** x\n */var a;").getFirstChild();
    // VAR
    replacedertEquals(Token.VAR, varNode.getType());
    // NAME
    Node nameNode = varNode.getFirstChild();
    replacedertEquals(Token.NAME, nameNode.getType());
    replacedertNull(nameNode.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testLinenoCharnoGetProp1() throws Exception {
    Node getprop = parse("\n foo.bar").getFirstChild().getFirstChild();
    replacedertEquals(Token.GETPROP, getprop.getType());
    replacedertEquals(2, getprop.getLineno());
    replacedertEquals(1, getprop.getCharno());
    Node name = getprop.getFirstChild().getNext();
    replacedertEquals(Token.STRING, name.getType());
    replacedertEquals(2, name.getLineno());
    replacedertEquals(5, name.getCharno());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment12() {
    Node varNode = parse("var a = {/** @type {Object} */ b: c};").getFirstChild();
    Node objectLitNode = varNode.getFirstChild().getFirstChild();
    replacedertEquals(Token.OBJECTLIT, objectLitNode.getType());
    replacedertNotNull(objectLitNode.getFirstChild().getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment1() {
    Node varNode = parse("/** @type number */var a;").getFirstChild();
    // VAR
    replacedertEquals(Token.VAR, varNode.getType());
    JSDocInfo info = varNode.getJSDocInfo();
    replacedertNotNull(info);
    replacedertTypeEquals(NUMBER_TYPE, info.getType());
    // NAME
    Node nameNode = varNode.getFirstChild();
    replacedertEquals(Token.NAME, nameNode.getType());
    replacedertNull(nameNode.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment8() {
    Node varNode = parse("/** x */var a;").getFirstChild();
    // VAR
    replacedertEquals(Token.VAR, varNode.getType());
    // NAME
    Node nameNode = varNode.getFirstChild();
    replacedertEquals(Token.NAME, nameNode.getType());
    replacedertNull(nameNode.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment7() {
    Node varNode = parse("/** */var a;").getFirstChild();
    // VAR
    replacedertEquals(Token.VAR, varNode.getType());
    // NAME
    Node nameNode = varNode.getFirstChild();
    replacedertEquals(Token.NAME, nameNode.getType());
    replacedertNull(nameNode.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testJSDocAttachment11() {
    Node varNode = parse("/** @type {{x : number, 'y' : string, z}} */var a;").getFirstChild();
    // VAR
    replacedertEquals(Token.VAR, varNode.getType());
    JSDocInfo info = varNode.getJSDocInfo();
    replacedertNotNull(info);
    replacedertTypeEquals(createRecordTypeBuilder().addProperty("x", NUMBER_TYPE, null).addProperty("y", STRING_TYPE, null).addProperty("z", UNKNOWN_TYPE, null).build(), info.getType());
    // NAME
    Node nameNode = varNode.getFirstChild();
    replacedertEquals(Token.NAME, nameNode.getType());
    replacedertNull(nameNode.getJSDocInfo());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testLinenoCharnoObjectLiteral() throws Exception {
    Node n = parse("\n\n var a = {a:0\n,b :1};").getFirstChild().getFirstChild().getFirstChild();
    replacedertEquals(Token.OBJECTLIT, n.getType());
    replacedertEquals(3, n.getLineno());
    replacedertEquals(9, n.getCharno());
    Node key = n.getFirstChild();
    replacedertEquals(Token.STRING_KEY, key.getType());
    replacedertEquals(3, key.getLineno());
    replacedertEquals(10, key.getCharno());
    Node value = key.getFirstChild();
    replacedertEquals(Token.NUMBER, value.getType());
    replacedertEquals(3, value.getLineno());
    replacedertEquals(12, value.getCharno());
    key = key.getNext();
    replacedertEquals(Token.STRING_KEY, key.getType());
    replacedertEquals(4, key.getLineno());
    replacedertEquals(1, key.getCharno());
    value = key.getFirstChild();
    replacedertEquals(Token.NUMBER, value.getType());
    replacedertEquals(4, value.getLineno());
    replacedertEquals(4, value.getCharno());
}

19 Source : ParserTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testParseBlockDescription() {
    Node n = parse("/** This is a variable. */ var x;");
    Node var = n.getFirstChild();
    replacedertNotNull(var.getJSDocInfo());
    replacedertEquals("This is a variable.", var.getJSDocInfo().getBlockDescription());
}

19 Source : IRFactoryTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testNewLocation() {
    Node root = newParse("new c();\n");
    Node exprStmt = root.getFirstChild();
    Node newExpr = exprStmt.getFirstChild();
    replacedertNodePosition(1, 0, 7, newExpr);
}

19 Source : IRFactoryTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testCommentPositions2() {
    Node root = newParse("/* foo \n" + "   bar \n" + "*/\n" + "/** @param {string} x */\n" + "function a(x) {};\n" + "\n" + "/* bar \n" + "   foo \n" + "   foo */\n" + "\n" + "/**   @param {string} x */\n" + "function b(x) {};");
    replacedertMarkerPosition(root.getFirstChild(), 4, 4);
    replacedertMarkerPosition(root.getFirstChild().getNext().getNext(), 11, 6);
}

19 Source : IRFactoryTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testCommentPositions1() {
    Node root = newParse("/** @param {string} x */function a(x) {};" + "/** @param {string} x */function b(x) {}");
    Node a = root.getFirstChild();
    Node b = root.getLastChild();
    replacedertMarkerPosition(a, 1, 4);
    replacedertMarkerPosition(b, 1, 45);
}

19 Source : IRFactoryTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testNewLocationMultiLine() {
    Node root = newParse("new   \n" + "c();\n");
    Node exprStmt = root.getFirstChild();
    Node newExpr = exprStmt.getFirstChild();
    replacedertNodePosition(1, 0, 10, newExpr);
}

19 Source : IRFactoryTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testVarDeclLocation() {
    Node root = newParse("var\n" + "    a =\n" + "    3\n");
    Node varDecl = root.getFirstChild();
    Node varName = varDecl.getFirstChild();
    Node varExpr = varName.getFirstChild();
    replacedertNodePosition(1, 0, varDecl);
    replacedertNodePosition(2, 4, 1, varName);
    replacedertNodePosition(3, 4, 1, varExpr);
}

19 Source : ClosureCodingConventionTest.java
with GNU General Public License v2.0
from xgdsmileboy

private void replacedertNotObjectLiteralCast(String code) {
    Node n = parseTestCode(code);
    replacedertNull(conv.getObjectLiteralCast(n.getFirstChild()));
}

19 Source : ClosureCodingConventionTest.java
with GNU General Public License v2.0
from xgdsmileboy

private void replacedertNotRequire(String code) {
    Node n = parseTestCode(code);
    replacedertNull(conv.extractClreplacedNameIfRequire(n.getFirstChild(), n));
}

19 Source : ClosureCodingConventionTest.java
with GNU General Public License v2.0
from xgdsmileboy

private void replacedertObjectLiteralCast(String code) {
    Node n = parseTestCode(code);
    replacedertNotNull(conv.getObjectLiteralCast(n.getFirstChild()));
}

19 Source : ClosureCodingConventionTest.java
with GNU General Public License v2.0
from xgdsmileboy

public void testVarAndOptionalParams() {
    Node args = new Node(Token.PARAM_LIST, Node.newString(Token.NAME, "a"), Node.newString(Token.NAME, "b"));
    Node optArgs = new Node(Token.PARAM_LIST, Node.newString(Token.NAME, "opt_a"), Node.newString(Token.NAME, "opt_b"));
    replacedertFalse(conv.isVarArgsParameter(args.getFirstChild()));
    replacedertFalse(conv.isVarArgsParameter(args.getLastChild()));
    replacedertFalse(conv.isVarArgsParameter(optArgs.getFirstChild()));
    replacedertFalse(conv.isVarArgsParameter(optArgs.getLastChild()));
    replacedertFalse(conv.isOptionalParameter(args.getFirstChild()));
    replacedertFalse(conv.isOptionalParameter(args.getLastChild()));
    replacedertFalse(conv.isOptionalParameter(optArgs.getFirstChild()));
    replacedertFalse(conv.isOptionalParameter(optArgs.getLastChild()));
}

19 Source : ClosureCodingConventionTest.java
with GNU General Public License v2.0
from xgdsmileboy

private void replacedertRequire(String code) {
    Node n = parseTestCode(code);
    replacedertNotNull(conv.extractClreplacedNameIfRequire(n.getFirstChild(), n));
}

19 Source : ArrowType.java
with GNU General Public License v2.0
from xgdsmileboy

private boolean hasTemplatedParameterType() {
    if (parameters != null) {
        for (Node paramNode = parameters.getFirstChild(); paramNode != null; paramNode = paramNode.getNext()) {
            JSType type = paramNode.getJSType();
            if (type != null && type.hasAnyTemplateTypes()) {
                return true;
            }
        }
    }
    return false;
}

19 Source : ArrowType.java
with GNU General Public License v2.0
from xgdsmileboy

boolean hasUnknownParamsOrReturn() {
    if (parameters != null) {
        for (Node paramNode = parameters.getFirstChild(); paramNode != null; paramNode = paramNode.getNext()) {
            JSType type = paramNode.getJSType();
            if (type == null || type.isUnknownType()) {
                return true;
            }
        }
    }
    return returnType == null || returnType.isUnknownType();
}

19 Source : SemanticReverseAbstractInterpreter.java
with GNU General Public License v2.0
from xgdsmileboy

private FlowScope caseEquality(Node condition, FlowScope blindScope, Function<TypePair, TypePair> merging) {
    return caseEquality(condition.getFirstChild(), condition.getLastChild(), blindScope, merging);
}

19 Source : StrictModeCheck.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Checks that variables, functions, and arguments are not deleted.
 */
private void checkDelete(NodeTraversal t, Node n) {
    if (n.getFirstChild().isName()) {
        Var v = t.getScope().getVar(n.getFirstChild().getString());
        if (v != null) {
            t.report(n, DELETE_VARIABLE);
        }
    }
}

19 Source : StrictModeCheck.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Checks that an replacedignment is not to the "arguments" object.
 */
private void checkreplacedignment(NodeTraversal t, Node n) {
    if (n.getFirstChild().isName()) {
        if ("arguments".equals(n.getFirstChild().getString())) {
            t.report(n, ARGUMENTS_replacedIGNMENT);
        } else if ("eval".equals(n.getFirstChild().getString())) {
            // Note that replacedignment to eval is already illegal because any use of
            // that name is illegal.
            if (noCajaChecks) {
                t.report(n, EVAL_replacedIGNMENT);
            }
        }
    }
}

19 Source : StrictModeCheck.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Checks that label names are valid.
 */
private void checkLabel(NodeTraversal t, Node n) {
    if (n.getFirstChild().getString().endsWith("__")) {
        if (!noCajaChecks) {
            t.report(n.getFirstChild(), ILLEGAL_NAME);
        }
    }
}

19 Source : ReplaceStrings.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Replace the parameters specified in the config, if possible.
 */
private void doSubsreplacedutions(NodeTraversal t, Config config, Node n) {
    Preconditions.checkState(n.isNew() || n.isCall());
    if (config.parameter != Config.REPLACE_ALL_VALUE) {
        // Note: the first child is the function, but the parameter id is 1 based.
        Node arg = n.getChildAtIndex(config.parameter);
        if (arg != null) {
            replaceExpression(t, arg, n);
        }
    } else {
        // Replace all parameters.
        Node firstParam = n.getFirstChild().getNext();
        for (Node arg = firstParam; arg != null; arg = arg.getNext()) {
            arg = replaceExpression(t, arg, n);
        }
    }
}

19 Source : RemoveUnusedVars.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * @return the LP node containing the function parameters.
 */
private static Node getFunctionArgList(Node function) {
    return function.getFirstChild().getNext();
}

19 Source : PureFunctionIdentifier.java
with GNU General Public License v2.0
from xgdsmileboy

private static boolean isCallOrApply(Node callSite) {
    Node callTarget = callSite.getFirstChild();
    if (NodeUtil.isGet(callTarget)) {
        String propString = callTarget.getLastChild().getString();
        if (propString.equals("call") || propString.equals("apply")) {
            return true;
        }
    }
    return false;
}

19 Source : ProcessClosurePrimitives.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * @return Whether the node is namespace placeholder.
 */
private static boolean isNamespacePlaceholder(Node n) {
    if (!n.getBooleanProp(Node.IS_NAMESPACE)) {
        return false;
    }
    Node value = null;
    if (n.isExprResult()) {
        Node replacedign = n.getFirstChild();
        value = replacedign.getLastChild();
    } else if (n.isVar()) {
        Node name = n.getFirstChild();
        value = name.getFirstChild();
    }
    return value != null && value.isObjectLit() && !value.hasChildren();
}

19 Source : ProcessClosurePrimitives.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * Handles a typedef definition for a goog.provided name.
 * @param n EXPR_RESULT node.
 */
private void handleTypedefDefinition(NodeTraversal t, Node n, Node parent) {
    JSDocInfo info = n.getFirstChild().getJSDocInfo();
    if (t.inGlobalScope() && info != null && info.hasTypedefType()) {
        String name = n.getFirstChild().getQualifiedName();
        if (name != null) {
            ProvidedName pn = providedNames.get(name);
            if (pn != null) {
                pn.addDefinition(n, t.getModule());
            }
        }
    }
}

19 Source : PeepholeReplaceKnownMethods.java
with GNU General Public License v2.0
from xgdsmileboy

private Node tryFoldKnownMethods(Node subtree) {
    // For now we only support string methods .join(),
    // .indexOf(), .substring() and .substr()
    // and numeric methods parseInt() and parseFloat().
    subtree = tryFoldArrayJoin(subtree);
    if (subtree.isCall()) {
        Node callTarget = subtree.getFirstChild();
        if (callTarget == null) {
            return subtree;
        }
        if (NodeUtil.isGet(callTarget)) {
            subtree = tryFoldKnownStringMethods(subtree);
        } else {
            subtree = tryFoldKnownNumericMethods(subtree);
        }
    }
    return subtree;
}

19 Source : PeepholeRemoveDeadCode.java
with GNU General Public License v2.0
from xgdsmileboy

/**
 * @return The condition of a conditional statement.
 */
private Node getConditionalStatementCondition(Node n) {
    if (n.isIf()) {
        return NodeUtil.getConditionExpression(n);
    } else {
        Preconditions.checkState(isExprConditional(n));
        return n.getFirstChild().getFirstChild();
    }
}

See More Examples