use of com.google.javascript.jscomp.newtypes.EnumType in project closure-compiler by google.
the class NTIScope method addNamespace.
void addNamespace(QualifiedName qname, Node defSite, Namespace ns) {
if (ns instanceof EnumType) {
this.localEnums.add((EnumType) ns);
}
if (qname.isIdentifier()) {
String varName = qname.getLeftmostName();
Preconditions.checkState(!this.localNamespaces.containsKey(varName), "Namespace %s already defined.", varName);
this.localNamespaces.put(varName, ns);
if (defSite.isFromExterns() && !this.externs.containsKey(varName)) {
// We don't know the full type of a namespace until after we see all
// its properties. But we want to add it to the externs, otherwise it
// is treated as a local and initialized to the wrong thing in NTI.
this.externs.put(varName, null);
}
} else {
checkState(!isDefined(qname));
Namespace rootns = getNamespace(qname.getLeftmostName());
rootns.addNamespace(qname.getAllButLeftmost(), ns);
}
}
use of com.google.javascript.jscomp.newtypes.EnumType in project closure-compiler by google.
the class SimpleInference method inferPropAccess.
private JSType inferPropAccess(Node recv, String pname, NTIScope scope) {
if (recv.isGetProp() && recv.getLastChild().getString().equals("prototype")) {
return inferPrototypeProperty(recv.getFirstChild(), pname, scope);
}
QualifiedName propQname = new QualifiedName(pname);
JSType recvType = null;
if (recv.isQualifiedName()) {
QualifiedName recvQname = QualifiedName.fromNode(recv);
Declaration decl = scope.getDeclaration(recvQname, false);
if (decl != null) {
EnumType et = decl.getEnum();
if (et != null && et.enumLiteralHasKey(pname)) {
return et.getPropType();
}
Namespace ns = decl.getNamespace();
if (ns != null) {
return inferDeclaration(ns.getDeclaration(propQname));
}
recvType = decl.getTypeOfSimpleDecl();
}
}
if (recvType == null) {
recvType = inferExprRecur(recv, scope);
}
if (recvType == null) {
return null;
}
if (recvType.isScalar()) {
recvType = recvType.autobox();
}
FunctionType ft = recvType.getFunTypeIfSingletonObj();
if (ft != null && pname.equals("call")) {
return this.commonTypes.fromFunctionType(ft.transformByCallProperty());
} else if (ft != null && pname.equals("apply")) {
return this.commonTypes.fromFunctionType(ft.transformByApplyProperty());
}
if (recvType.mayHaveProp(propQname)) {
return recvType.getProp(propQname);
}
return null;
}
Aggregations