com.google.javascript.rhino.Node

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

1792 Examples 7

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

/**
 * This function adds a comma-separated list as is specified by an ARRAYLIT
 * node with the replacedociated skipIndexes array.  This is a space optimization
 * since we avoid creating a whole Node object for each empty array literal
 * slot.
 * @param firstInList The first in the node list (chained through the next
 * property).
 */
void addArrayList(Node firstInList) {
    boolean lastWasEmpty = false;
    for (Node n = firstInList; n != null; n = n.getNext()) {
        if (n != firstInList) {
            cc.listSeparator();
        }
        addExpr(n, 1);
        lastWasEmpty = n.getType() == Token.EMPTY;
    }
    if (lastWasEmpty) {
        cc.listSeparator();
    }
}

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

/**
 * @return Whether the name is an indirect eval.
 */
private boolean isIndirectEval(Node n) {
    return n.getType() == Token.NAME && "eval".equals(n.getString()) && !n.getBooleanProp(Node.DIRECT_EVAL);
}

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

/**
 * Gets the first non-empty child of the given node.
 */
private static Node getFirstNonEmptyChild(Node n) {
    for (Node c = n.getFirstChild(); c != null; c = c.getNext()) {
        if (c.getType() == Token.BLOCK) {
            Node result = getFirstNonEmptyChild(c);
            if (result != null) {
                return result;
            }
        } else if (c.getType() != Token.EMPTY) {
            return c;
        }
    }
    return null;
}

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

void addList(Node firstInList, boolean isArrayOrFunctionArgument, Context lhsContext) {
    for (Node n = firstInList; n != null; n = n.getNext()) {
        boolean isFirst = n == firstInList;
        if (isFirst) {
            addLeftExpr(n, isArrayOrFunctionArgument ? 1 : 0, lhsContext);
        } else {
            cc.listSeparator();
            addExpr(n, isArrayOrFunctionArgument ? 1 : 0);
        }
    }
}

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

/**
 * @param maxCount The maximum number of children to look for.
 * @return The number of children of this node that are non empty up to
 * maxCount.
 */
private static int getNonEmptyChildCount(Node n, int maxCount) {
    int i = 0;
    Node c = n.getFirstChild();
    for (; c != null && i < maxCount; c = c.getNext()) {
        if (c.getType() == Token.BLOCK) {
            i += getNonEmptyChildCount(c, maxCount - i);
        } else if (c.getType() != Token.EMPTY) {
            i++;
        }
    }
    return i;
}

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

void addAllSiblings(Node n) {
    for (Node c = n; c != null; c = c.getNext()) {
        add(c);
    }
}

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

/**
 * Adds a node at the left-hand side of an expression. Unlike
 * {@link #addExpr(Node,int)}, this preserves information about the context.
 *
 * The left side of an expression is special because in the JavaScript
 * grammar, certain tokens may be parsed differently when they are at
 * the beginning of a statement. For example, "{}" is parsed as a block,
 * but "{'x': 'y'}" is parsed as an object literal.
 */
void addLeftExpr(Node n, int minPrecedence, Context context) {
    addExpr(n, minPrecedence, context);
}

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

private void addExpr(Node n, int minPrecedence, Context context) {
    if ((NodeUtil.precedence(n.getType()) < minPrecedence) || ((context == Context.IN_FOR_INIT_CLAUSE) && (n.getType() == Token.IN))) {
        add("(");
        add(n, clearContextForNoInOperator(context));
        add(")");
    } else {
        add(n, context);
    }
}

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

void addCaseBody(Node caseBody) {
    cc.beginCaseBody();
    add(caseBody);
    cc.endCaseBody();
}

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

/**
 * Given a qualified name node, returns whether "prototype" is at the end.
 * For example:
 * a.b.c => false
 * a.b.c.prototype => true
 */
private boolean endsWithPrototype(Node qualifiedName) {
    return qualifiedName.getType() == Token.GETPROP && qualifiedName.getLastChild().getString().equals("prototype");
}

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

/**
 * Get the TRY block with a CATCH that would be run if n throws an exception.
 * @return The CATCH node or null if it there isn't a CATCH before the
 *     the function terminates.
 */
static Node getExceptionHandler(Node n) {
    for (Node cur = n; !cur.isScript() && !cur.isFunction(); cur = cur.getParent()) {
        Node catchNode = getCatchHandlerForBlock(cur);
        if (catchNode != null) {
            return catchNode;
        }
    }
    return null;
}

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

/**
 * Determines whether the given node can be advanced with a CONTINUE node.
 */
static boolean isContinueStructure(Node n) {
    switch(n.getType()) {
        case Token.FOR:
        case Token.DO:
        case Token.WHILE:
            return true;
        default:
            return false;
    }
}

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

private void handleThrow(Node node) {
    connectToPossibleExceptionHandler(node, node);
}

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

/**
 * Checks if target is actually the continue target of labeled continue. The
 * label can be null if it is an unlabeled continue.
 */
private static boolean isContinueTarget(Node target, Node parent, String label) {
    return isContinueStructure(target) && matchLabel(parent, label);
}

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

static Node computeFollowNode(Node node) {
    return computeFollowNode(node, node, null);
}

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

/**
 * Get the next sibling (including itself) of one of the given types.
 */
private static Node getNextSiblingOfType(Node first, int... types) {
    for (Node c = first; c != null; c = c.getNext()) {
        for (int type : types) {
            if (c.getType() == type) {
                return c;
            }
        }
    }
    return null;
}

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

/**
 * 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;
    }
}

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

static Node computeFollowNode(Node node, ControlFlowreplacedysis cfa) {
    return computeFollowNode(node, node, cfa);
}

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

/**
 * Checks if target is actually the break target of labeled continue. The
 * label can be null if it is an unlabeled break.
 */
public static boolean isBreakTarget(Node target, String label) {
    return isBreakStructure(target, label != null) && matchLabel(target.getParent(), label);
}

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

/**
 * Connects the two nodes in the control flow graph.
 *
 * @param fromNode Source.
 * @param toNode Destination.
 */
private void createEdge(Node fromNode, ControlFlowGraph.Branch branch, Node toNode) {
    cfg.createNode(fromNode);
    cfg.createNode(toNode);
    cfg.connectIfNotFound(fromNode, branch, toNode);
}

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

/**
 * Gets an estimate of the cost in characters of making the function call:
 * the sum of the identifiers and the separators.
 * @param referencesThis
 */
private static int estimateCallCost(Node fnNode, boolean referencesThis) {
    Node argsNode = NodeUtil.getFunctionParameters(fnNode);
    int numArgs = argsNode.getChildCount();
    int callCost = NAME_COST_ESTIMATE + PAREN_COST;
    if (numArgs > 0) {
        callCost += (numArgs * NAME_COST_ESTIMATE) + ((numArgs - 1) * COMMA_COST);
    }
    if (referencesThis) {
        // TODO(johnlenz): Update this if we start supporting inlining
        // other functions that reference this.
        // The only functions that reference this that are currently inlined
        // are those that are called via ".call" with an explicit "this".
        // ".call" + "this,"
        callCost += 5 + 5;
    }
    return callCost;
}

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

/**
 * Determine if inlining the function is likely to reduce the code size.
 * @param namesToAlias
 */
boolean inliningLowersCost(JSModule fnModule, Node fnNode, Collection<? extends Reference> refs, Set<String> namesToAlias, boolean isRemovable, boolean referencesThis) {
    int referenceCount = refs.size();
    if (referenceCount == 0) {
        return true;
    }
    int referencesUsingBlockInlining = 0;
    boolean checkModules = isRemovable && fnModule != null;
    JSModuleGraph moduleGraph = compiler.getModuleGraph();
    for (Reference ref : refs) {
        if (ref.mode == InliningMode.BLOCK) {
            referencesUsingBlockInlining++;
        }
        // Check if any of the references cross the module boundaries.
        if (checkModules && ref.module != null) {
            if (ref.module != fnModule && !moduleGraph.dependsOn(ref.module, fnModule)) {
                // Calculate the cost as if the function were non-removable,
                // if it still lowers the cost inline it.
                isRemovable = false;
                // no need to check additional modules.
                checkModules = false;
            }
        }
    }
    int referencesUsingDirectInlining = referenceCount - referencesUsingBlockInlining;
    // Don't bother calculating the cost of function for simple functions where
    // possible.
    // However, when inlining a complex function, even a single reference may be
    // larger than the original function if there are many returns (resulting
    // in additional replacedignments) or many parameters that need to be aliased
    // so use the cost estimating.
    if (referenceCount == 1 && isRemovable && referencesUsingDirectInlining == 1) {
        return true;
    }
    int callCost = estimateCallCost(fnNode, referencesThis);
    int overallCallCost = callCost * referenceCount;
    int costDeltaDirect = inlineCostDelta(fnNode, namesToAlias, InliningMode.DIRECT);
    int costDeltaBlock = inlineCostDelta(fnNode, namesToAlias, InliningMode.BLOCK);
    return doesLowerCost(fnNode, overallCallCost, referencesUsingDirectInlining, costDeltaDirect, referencesUsingBlockInlining, costDeltaBlock, isRemovable);
}

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

/**
 * Inline a function into the call site.
 */
Node inline(Node callNode, String fnName, Node fnNode, InliningMode mode) {
    Preconditions.checkState(compiler.getLifeCycleStage().isNormalized());
    if (mode == InliningMode.DIRECT) {
        return inlineReturnValue(callNode, fnNode);
    } else {
        return inlineFunction(callNode, fnNode, fnName);
    }
}

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

/**
 * If required, rewrite the statement containing the call expression.
 * @see ExpressionDecomposer#canExposeExpression
 */
void maybePrepareCall(Node callNode) {
    CallSiteType callSiteType = clreplacedifyCallSite(callNode);
    callSiteType.prepare(this, callNode);
}

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

/**
 * @return The difference between the function definition cost and
 *     inline cost.
 */
private static int inlineCostDelta(Node fnNode, Set<String> namesToAlias, InliningMode mode) {
    // The part of the function that is never inlined:
    // "function xx(xx,xx){}" (15 + (param count * 3) -1;
    int paramCount = NodeUtil.getFunctionParameters(fnNode).getChildCount();
    int commaCount = (paramCount > 1) ? paramCount - 1 : 0;
    int costDeltaFunctionOverhead = 15 + commaCount + (paramCount * InlineCostEstimator.ESTIMATED_IDENTIFIER_COST);
    Node block = fnNode.getLastChild();
    if (!block.hasChildren()) {
        // replacedume the inline cost is zero for empty functions.
        return -costDeltaFunctionOverhead;
    }
    if (mode == InliningMode.DIRECT) {
        // The part of the function that is inlined using direct inlining:
        // "return " (7)
        return -(costDeltaFunctionOverhead + 7);
    } else {
        int aliasCount = namesToAlias.size();
        // Originally, we estimated purely base on the function code size, relying
        // on later optimizations. But that did not produce good results, so here
        // we try to estimate the something closer to the actual inlined coded.
        // NOTE 1: Result overhead is only if there is an replacedignment, but
        // getting that information would require some refactoring.
        // NOTE 2: The aliasing overhead is currently an under-estimate,
        // as some parameters are aliased because of the parameters used.
        // Perhaps we should just replacedume all parameters will be aliased?
        // "X:{}"
        final int inlineBlockOverhead = 4;
        // "return" --> "break X"
        final int perReturnOverhead = 2;
        // "XX="
        final int perReturnResultOverhead = 3;
        // "XX="
        final int perAliasOverhead = 3;
        // TODO(johnlenz): Counting the number of returns is relatively expensive
        // this information should be determined during the traversal and
        // cached.
        int returnCount = NodeUtil.getNodeTypeReferenceCount(block, Token.RETURN, new NodeUtil.MatchShallowStatement());
        int resultCount = (returnCount > 0) ? returnCount - 1 : 0;
        int baseOverhead = (returnCount > 0) ? inlineBlockOverhead : 0;
        int overhead = baseOverhead + returnCount * perReturnOverhead + resultCount * perReturnResultOverhead + aliasCount * perAliasOverhead;
        return (overhead - costDeltaFunctionOverhead);
    }
}

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

/**
 * @param t  The traversal use to reach the call site.
 * @param callNode The CALL node.
 * @param fnNode The function to evaluate for inlining.
 * @param needAliases A set of function parameter names that can not be
 *     used without aliasing. Returned by getUnsafeParameterNames().
 * @param mode Inlining mode to be used.
 * @param referencesThis Whether fnNode contains references to its this
 *     object.
 * @param containsFunctions Whether fnNode contains inner functions.
 * @return Whether the inlining can occur.
 */
CanInlineResult canInlineReferenceToFunction(NodeTraversal t, Node callNode, Node fnNode, Set<String> needAliases, InliningMode mode, boolean referencesThis, boolean containsFunctions) {
    // TODO(johnlenz): This function takes too many parameter, without
    // context.  Modify the API to take a structure describing the function.
    // Allow direct function calls or "fn.call" style calls.
    if (!isSupportedCallType(callNode)) {
        return CanInlineResult.NO;
    }
    // Limit where functions that contain functions can be inline.  Introducing
    // an inner function into another function can capture a variable and cause
    // a memory leak.  This isn't a problem in the global scope as those values
    // last until explicitly cleared.
    if (containsFunctions) {
        if (!replacedumeMinimumCapture && !t.inGlobalScope()) {
            // TODO(johnlenz): Allow inlining into any scope without local names or
            // inner functions.
            return CanInlineResult.NO;
        } else if (NodeUtil.isWithinLoop(callNode)) {
            // An inner closure maybe relying on a local value holding a value for a
            // single iteration through a loop.
            return CanInlineResult.NO;
        }
    }
    // TODO(johnlenz): Add support for 'apply'
    if (referencesThis && !NodeUtil.isFunctionObjectCall(callNode)) {
        // TODO(johnlenz): Allow 'this' references to be replaced with a
        // global 'this' object.
        return CanInlineResult.NO;
    }
    if (mode == InliningMode.DIRECT) {
        return canInlineReferenceDirectly(callNode, fnNode);
    } else {
        return canInlineReferencereplacedtatementBlock(t, callNode, fnNode, needAliases);
    }
}

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

/**
 * @return Whether inlining will lower cost.
 */
private boolean doesLowerCost(Node fnNode, int callCost, int directInlines, int costDeltaDirect, int blockInlines, int costDeltaBlock, boolean removable) {
    // Determine the threshold value for this inequality:
    // inline_cost < call_cost
    // But solve it for the function declaration size so the size of it
    // is only calculated once and terminated early if possible.
    int fnInstanceCount = directInlines + blockInlines - (removable ? 1 : 0);
    // Prevent division by zero.
    if (fnInstanceCount == 0) {
        // Special case single reference function that are being block inlined:
        // If the cost of the inline is greater than the function definition size,
        // don't inline.
        if (blockInlines > 0 && costDeltaBlock > 0) {
            return false;
        }
        return true;
    }
    int costDelta = (directInlines * costDeltaDirect) + (blockInlines * costDeltaBlock);
    int threshold = (callCost - costDelta) / fnInstanceCount;
    return InlineCostEstimator.getCost(fnNode, threshold + 1) <= threshold;
}

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

/**
 * Parse the supplied JS and create the global SyntaticScope object.
 * @return The error count.
 */
private int createGlobalScopeHelper(String js) {
    Compiler compiler = new Compiler();
    CompilerOptions options = new CompilerOptions();
    options.checkSymbols = true;
    compiler.initOptions(options);
    Node root = compiler.parseTestCode(js);
    replacedertEquals(0, compiler.getErrorCount());
    Scope globalScope = new SyntacticScopeCreator(compiler).createScope(root, null);
    replacedertEquals(root, globalScope.getRootNode());
    return compiler.getErrorCount();
}

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

/**
 * Helper to create a top-level scope from a JavaScript string
 */
private static Scope getScope(String js) {
    Compiler compiler = new Compiler();
    Node root = compiler.parseTestCode(js);
    replacedertEquals(0, compiler.getErrorCount());
    Scope scope = new SyntacticScopeCreator(compiler).createScope(root, null);
    return scope;
}

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

/**
 * Helper to traverse the tree creating the Scope object everywhere.
 */
private static void testScopes(String js, int errorCount) {
    Compiler compiler = new Compiler();
    Node root = compiler.parseTestCode(js);
    NodeTraversal.traverse(compiler, root, new NodeTraversal.AbstractPostOrderCallback() {

        @Override
        public void visit(NodeTraversal t, Node n, Node parent) {
            t.getScope();
        }
    });
    replacedertEquals(errorCount, compiler.getErrorCount());
}

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

private void replacedertFunctionAliased(boolean alireplacedtatus, String functionName) {
    Node function = findFunction(functionName);
    replacedertEquals(alireplacedtatus, replacedysis.isAliased(function));
}

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

private void replacedertFunctionExposedToCallOrApply(boolean exposure, String functionName) {
    Node function = findFunction(functionName);
    replacedertEquals(exposure, replacedysis.isExposedToCallOrApply(function));
}

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

private void replacedertMove(LocationAbstractionMode abstraction, String src, boolean expected) {
    SideEffectsreplacedysis replacedysis = compileAndRun(src, abstraction);
    Node sourceNode = findLabeledStatement("src");
    Node environmentNode = findLabeledStatement("env");
    Node destinationNode = findLabeledStatement("dest");
    boolean result = replacedysis.safeToMoveBefore(sourceNode, environment(environmentNode), destinationNode);
    if (expected) {
        replacedertTrue(result);
    } else {
        replacedertFalse(result);
    }
}

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

private SideEffectsreplacedysis.AbstractMotionEnvironment environment(Node... nodes) {
    return new SideEffectsreplacedysis.RawMotionEnvironment(ImmutableSet.copyOf(nodes));
}

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

public void testNoSymbolMapStripsCallAndDoesntIssueWarnings() {
    String input = "[goog.getCssName('test'), goog.getCssName(base, 'active')]";
    Compiler compiler = new Compiler();
    ErrorManager errorMan = new BasicErrorManager() {

        @Override
        protected void printSummary() {
        }

        @Override
        public void println(CheckLevel level, JSError error) {
        }
    };
    compiler.setErrorManager(errorMan);
    Node root = compiler.parseTestCode(input);
    useReplacementMap = false;
    ReplaceCssNames replacer = new ReplaceCssNames(compiler, null, null);
    replacer.process(null, root);
    replacedertEquals("[\"test\",base+\"-active\"]", compiler.toSource(root));
    replacedertEquals("There should be no errors", 0, errorMan.getErrorCount());
    replacedertEquals("There should be no warnings", 0, errorMan.getWarningCount());
}

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

private Node main(Node root) {
    return root.getFirstChild().getNext();
}

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

private void test(Compiler compiler, FunctionInformationMap expected) {
    Node root = root(compiler);
    test(compiler, externs(root), main(root), expected);
}

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

private void test(Compiler compiler, Node externsRoot, Node mainRoot, FunctionInformationMap expected) {
    FunctionNames functionNames = new FunctionNames(compiler);
    functionNames.process(externsRoot, mainRoot);
    RecordFunctionInformation processor = new RecordFunctionInformation(compiler, functionNames);
    processor.process(externsRoot, mainRoot);
    FunctionInformationMap result = processor.getMap();
    replacedertEquals(expected, result);
}

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

private Node externs(Node root) {
    return root.getFirstChild();
}

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

public void testIdeModePartialTree() {
    Node partialTree = parseError("function Foo() {} f.", "missing name after . operator");
    replacedertNull(partialTree);
    isIdeMode = true;
    partialTree = parseError("function Foo() {} f.", "missing name after . operator");
    replacedertNotNull(partialTree);
}

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

public void testJSDocAttachment14() {
    Node varNode = parse("/** */ var a;").getFirstChild();
    replacedertNull(varNode.getJSDocInfo());
}

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

private void replacedertNodeEquality(Node expected, Node found) {
    String message = expected.checkTreeEquals(found);
    if (message != null) {
        fail(message);
    }
}

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

private Node createScript(Node n) {
    Node script = new Node(Token.SCRIPT);
    script.addChildToBack(n);
    return script;
}

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

public void testJSDocAttachment13() {
    Node varNode = parse("/** foo */ var a;").getFirstChild();
    replacedertNotNull(varNode.getJSDocInfo());
}

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

public void testJSDocAttachment15() {
    Node varNode = parse("/** \n * \n */ var a;").getFirstChild();
    replacedertNull(varNode.getJSDocInfo());
}

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

private void testParseError(String string, String[] errors) {
    Node root = newParse(string, new TestErrorReporter(errors, null));
    replacedertTrue("unexpected warnings reported", errorReporter.hasEncounteredAllWarnings());
    replacedertTrue("expected error were not reported", errorReporter.hasEncounteredAllErrors());
}

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

private void replacedertMarkerPosition(Node n, int lineno, int charno) {
    int count = 0;
    for (JSDocInfo.Marker marker : n.getJSDocInfo().getMarkers()) {
        replacedertEquals(lineno, marker.getAnnotation().getStartLine());
        replacedertEquals(charno, marker.getAnnotation().getPositionOnStartLine());
        count++;
    }
    replacedertEquals(1, count);
}

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

public void testPruningCallbackShouldTraverse2() {
    PruningCallback include = new PruningCallback(ImmutableSet.of(Token.SCRIPT, Token.VAR), false);
    Node script = new Node(Token.SCRIPT);
    replacedertFalse(include.shouldTraverse(null, script, null));
    replacedertFalse(include.shouldTraverse(null, new Node(Token.VAR), null));
    replacedertTrue(include.shouldTraverse(null, new Node(Token.NAME), null));
    replacedertTrue(include.shouldTraverse(null, new Node(Token.ADD), null));
}

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

private static Node parse(Compiler compiler, String js) {
    Node n = compiler.parseTestCode(js);
    replacedertEquals(0, compiler.getErrorCount());
    return n;
}

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

public void testGetCurrentNode() {
    Compiler compiler = new Compiler();
    ScopeCreator creator = new SyntacticScopeCreator(compiler);
    ExpectNodeOnEnterScope callback = new ExpectNodeOnEnterScope();
    NodeTraversal t = new NodeTraversal(compiler, callback, creator);
    String code = "" + "var a; " + "function foo() {" + "  var b;" + "}";
    Node tree = parse(compiler, code);
    Scope topScope = creator.createScope(tree, null);
    // Calling #traverseWithScope uses the given scope but starts traversal at
    // the given node.
    callback.expect(tree.getFirstChild(), tree);
    t.traverseWithScope(tree.getFirstChild(), topScope);
    callback.replacedertEntered();
    // Calling #traverse creates a new scope with the given node as the root.
    callback.expect(tree.getFirstChild(), tree.getFirstChild());
    t.traverse(tree.getFirstChild());
    callback.replacedertEntered();
    // Calling #traverseAtScope starts traversal from the scope's root.
    Node fn = tree.getFirstChild().getNext();
    Scope fnScope = creator.createScope(fn, topScope);
    callback.expect(fn, fn);
    t.traverseAtScope(fnScope);
    callback.replacedertEntered();
}

See More Examples