Search in sources :

Example 6 with Node

use of com.google.javascript.rhino.Node in project ow by vtst.

the class ClosureCompletionProposal method addFragmentsForFunctionParameters.

/**
   * Add the fragments for the parameters of a function.
   * @param list  The list to which the fragments will be added.
   * @param fnNode  The function node.
   */
private void addFragmentsForFunctionParameters(List<Fragment> list, Node fnNode) {
    if (fnNode == null)
        return;
    Preconditions.checkState(fnNode.getType() == Token.FUNCTION);
    JSType type = fnNode.getJSType();
    if (type == null || type.isUnknownType())
        return;
    FunctionType funType = type.toMaybeFunctionType();
    Node paramNode = NodeUtil.getFunctionParameters(fnNode).getFirstChild();
    list.add(new Fragment("("));
    boolean first = true;
    for (@SuppressWarnings("unused") Node parameterTypeNode : funType.getParameters()) {
        // Bail out if the paramNode is not there.
        if (paramNode == null)
            break;
        if (first)
            first = false;
        else
            list.add(new Fragment(", "));
        list.add(new LinkedFragment(paramNode.getString()));
        paramNode = paramNode.getNext();
    }
    list.add(new Fragment(")"));
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) FunctionType(com.google.javascript.rhino.jstype.FunctionType) Node(com.google.javascript.rhino.Node)

Example 7 with Node

use of com.google.javascript.rhino.Node in project ow by vtst.

the class CompilerRun method processCustomPassesOnNewScript.

private void processCustomPassesOnNewScript(JsAst ast) {
    if (!keepCompilationResultsInMemory)
        return;
    if (options.customPasses == null)
        return;
    Node scriptRoot = ast.getAstRoot(compiler);
    Node originalRoot = compiler.getRoot();
    for (CompilerPass pass : options.customPasses.get(CustomPassExecutionTime.BEFORE_CHECKS)) {
        if (pass instanceof HotSwapCompilerPass) {
            ((HotSwapCompilerPass) pass).hotSwapScript(scriptRoot, originalRoot);
        }
    }
}
Also used : Node(com.google.javascript.rhino.Node) HotSwapCompilerPass(com.google.javascript.jscomp.HotSwapCompilerPass) CompilerPass(com.google.javascript.jscomp.CompilerPass) HotSwapCompilerPass(com.google.javascript.jscomp.HotSwapCompilerPass)

Example 8 with Node

use of com.google.javascript.rhino.Node in project ow by vtst.

the class JSUnit method updateDependencies.

/**
   * Update the sets of provided and required names from the current code.
   * @param compiler  The compiler used to report errors.
   * @return  true if the dependencies have changed since the last update.
   */
public synchronized boolean updateDependencies(AbstractCompiler compiler) {
    if (!timestampKeeperForDependencies.hasChanged())
        return false;
    long modificationStamp = timestampKeeperForDependencies.getModificationStamp();
    // There is no need to make a clone, as this pass does not modify the AST.
    Node root = astFactory.getAstRoot(compiler);
    Set<String> newProvidedNames = new HashSet<String>();
    Set<String> newRequiredNames = new HashSet<String>();
    GetDependenciesNodeTraversal.run(compiler, root, newProvidedNames, newRequiredNames);
    if (newProvidedNames.equals(providedNames) && newRequiredNames.equals(requiredNames)) {
        return false;
    }
    setDependencies(newProvidedNames, newRequiredNames, modificationStamp);
    return true;
}
Also used : Node(com.google.javascript.rhino.Node) HashSet(java.util.HashSet)

Example 9 with Node

use of com.google.javascript.rhino.Node in project ow by vtst.

the class DevUtils method printNodeAndAncestors.

public static void printNodeAndAncestors(Node node) {
    StringBuffer buffer = new StringBuffer();
    Node current = node;
    while (current != null) {
        System.out.print(buffer.toString());
        System.out.println(current);
        buffer.append("  ");
        current = current.getParent();
    }
}
Also used : Node(com.google.javascript.rhino.Node)

Aggregations

Node (com.google.javascript.rhino.Node)9 JSType (com.google.javascript.rhino.jstype.JSType)3 FunctionType (com.google.javascript.rhino.jstype.FunctionType)2 ObjectType (com.google.javascript.rhino.jstype.ObjectType)2 CompilerPass (com.google.javascript.jscomp.CompilerPass)1 HotSwapCompilerPass (com.google.javascript.jscomp.HotSwapCompilerPass)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1 HashSet (java.util.HashSet)1 CompilableJSUnit (net.vtst.ow.closure.compiler.compile.CompilableJSUnit)1 CompilerRun (net.vtst.ow.closure.compiler.compile.CompilerRun)1 JSElementInfo (net.vtst.ow.eclipse.js.closure.editor.JSElementInfo)1