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