Search in sources :

Example 1 with Scope

use of com.google.javascript.jscomp.Scope in project ow by vtst.

the class CompilerRun method getScope.

/**
 * Get the scope for a node (or its first ascendant having a scope).
 * @param node  The node to look for.
 * @return  The scope of the node, or null if not found.
 */
public Scope getScope(Node node) {
    if (!keepCompilationResultsInMemory)
        return null;
    while (node != null) {
        Scope scope = scopeCreator.getScope(node);
        if (scope != null)
            return scope;
        node = node.getParent();
    }
    return null;
}
Also used : Scope(com.google.javascript.jscomp.Scope)

Example 2 with Scope

use of com.google.javascript.jscomp.Scope in project ow by vtst.

the class ClosureTextHover method getElementInfo.

/**
 * @return  The element info for a given node, or null.
 */
private JSElementInfo getElementInfo(CompilerRun run, Node node) {
    Scope scope = run.getScope(node);
    if (scope == null)
        return null;
    LinkedList<String> qualifiedName = getQualifiedName(node);
    if (qualifiedName.isEmpty())
        return null;
    String propertyName = qualifiedName.removeLast();
    if (qualifiedName.isEmpty()) {
        // This is a top level node
        Var var = scope.getVar(propertyName);
        if (var == null)
            return null;
        else
            return JSElementInfo.makeFromVar(run, var);
    } else {
        // This is a property
        JSType type = CompilerRun.getTypeOfQualifiedName(scope, qualifiedName);
        return JSElementInfo.makeFromPropertyOrNull(run, type, propertyName);
    }
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Scope(com.google.javascript.jscomp.Scope) Var(com.google.javascript.jscomp.Scope.Var)

Example 3 with Scope

use of com.google.javascript.jscomp.Scope in project ow by vtst.

the class ClosureCompletionProposalCollector method getProposals.

/**
 * Get all the completion proposals which are valid in the given context.
 * @return  The list of the completion proposals.
 */
public List<ClosureCompletionProposal> getProposals() {
    CompilerRun run = context.getCompilerRun();
    List<String> qualifiedName = context.getPrefixAsQualifiedName();
    if (qualifiedName.isEmpty()) {
        try {
            return getProposalsFromScope();
        } catch (RuntimeException e) {
            return Collections.emptyList();
        }
    } else {
        Scope scope = run.getScope(context.getNode());
        if (scope == null)
            return Collections.emptyList();
        JSType type = CompilerRun.getTypeOfQualifiedName(scope, qualifiedName);
        if (type == null)
            return Collections.emptyList();
        else
            return getProposalsFromType(type);
    }
}
Also used : JSType(com.google.javascript.rhino.jstype.JSType) Scope(com.google.javascript.jscomp.Scope) CompilerRun(net.vtst.ow.closure.compiler.compile.CompilerRun)

Aggregations

Scope (com.google.javascript.jscomp.Scope)3 JSType (com.google.javascript.rhino.jstype.JSType)2 Var (com.google.javascript.jscomp.Scope.Var)1 CompilerRun (net.vtst.ow.closure.compiler.compile.CompilerRun)1