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);
}
}
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;
}
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;
}