use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method isFunctionNamespace.
boolean isFunctionNamespace(String name) {
checkArgument(!name.contains("."));
checkState(isFrozen);
Declaration d = getDeclaration(name, false);
if (d == null || d.getFunctionScope() == null || d.getTypeOfSimpleDecl() == null) {
return false;
}
return d.getTypeOfSimpleDecl().isNamespace();
}
use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method isNamespace.
boolean isNamespace(String name) {
checkArgument(!name.contains("."));
Declaration decl = getDeclaration(name, false);
if (decl == null) {
return false;
}
JSType simpleType = decl.getTypeOfSimpleDecl();
return decl.getNamespace() != null || (simpleType != null && simpleType.isNamespace());
}
use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method isConstVar.
boolean isConstVar(String name) {
checkArgument(!name.contains("."));
Declaration decl = getDeclaration(name, false);
return decl != null && decl.isConstant();
}
use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method getTypedef.
Typedef getTypedef(QualifiedName qname) {
Declaration decl;
if (qname.isIdentifier()) {
decl = getDeclaration(qname, true);
} else {
Namespace ns = getNamespace(qname.getLeftmostName());
decl = ns == null ? null : ns.getDeclaration(qname.getAllButLeftmost());
}
return decl == null ? null : decl.getTypedef();
}
use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method getDeclaredTypeOf.
@Override
public JSType getDeclaredTypeOf(String name) {
checkArgument(!name.contains("."));
if ("this".equals(name)) {
if (!hasThis()) {
return null;
}
return getDeclaredTypeForOwnBody().getThisType();
}
Declaration decl = getLocalDeclaration(name, false);
if (decl != null) {
if (decl.getTypeOfSimpleDecl() != null) {
Preconditions.checkState(!decl.getTypeOfSimpleDecl().isBottom(), "%s was bottom", name);
return decl.getTypeOfSimpleDecl();
}
NTIScope funScope = (NTIScope) decl.getFunctionScope();
if (funScope != null) {
Preconditions.checkNotNull(funScope.getDeclaredFunctionType(), "decl=%s, funScope=%s", decl, funScope);
return this.commonTypes.fromFunctionType(funScope.getDeclaredFunctionType().toFunctionType());
}
checkState(decl.getNamespace() == null);
return null;
}
// When a function is a namespace, the parent scope has a better type.
if (name.equals(this.name) && !parent.isFunctionNamespace(name)) {
return this.commonTypes.fromFunctionType(getDeclaredFunctionType().toFunctionType());
}
return parent == null ? null : parent.getDeclaredTypeOf(name);
}
Aggregations