Search in sources :

Example 1 with Var

use of com.google.javascript.jscomp.Scope.Var 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 2 with Var

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

the class ClosureCompletionProposalCollector method getProposalsFromScope.

// **************************************************************************
// Getting completion proposals from variables in the scope
/**
 * Get the list of completion proposals computed from the scope.  This method is called
 * in the case where the prefix does not contain a dot.
 * @return  The list of completion proposals.
 */
private List<ClosureCompletionProposal> getProposalsFromScope() {
    String prefix = context.getPrefix();
    LinkedList<ClosureCompletionProposal> list = new LinkedList<ClosureCompletionProposal>();
    for (Var var : context.getCompilerRun().getAllSymbols(context.getNode())) {
        String name = var.getName();
        if (isValidForPrefix(name, prefix) && isSimpleName(name) && isVisibleName(name) && isConcreteNode(var.getNameNode())) {
            list.add(new ClosureCompletionProposal(context, name, JSElementInfo.makeFromVar(context.getCompilerRun(), var)));
        }
    }
    return list;
}
Also used : Var(com.google.javascript.jscomp.Scope.Var) LinkedList(java.util.LinkedList)

Example 3 with Var

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

the class CompilerRun method getAllSymbolsRecursively.

/**
 * Get all the symbols defined by a scope and its ascendant.  Only the visible symbols (i.e. those which
 * are not overridden by another symbol with the same name in a closest context) are returned.
 * @param scope
 * @return  The defined symbols.
 */
private static Iterable<Var> getAllSymbolsRecursively(Scope scope) {
    Set<String> names = new HashSet<String>();
    Collection<Var> vars = new ArrayList<Var>();
    while (scope != null) {
        for (Var var : scope.getAllSymbols()) {
            if (names.add(var.getName()))
                vars.add(var);
        }
        scope = scope.getParent();
    }
    return vars;
}
Also used : Var(com.google.javascript.jscomp.Scope.Var) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

Var (com.google.javascript.jscomp.Scope.Var)3 Scope (com.google.javascript.jscomp.Scope)1 JSType (com.google.javascript.rhino.jstype.JSType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1