use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method getLocalDeclaration.
private Declaration getLocalDeclaration(String name, boolean includeTypes) {
checkArgument(!name.contains("."));
if (!isDefinedLocally(name, includeTypes)) {
return null;
}
DeclaredFunctionType declaredType = getDeclaredTypeForOwnBody();
JSType type = null;
boolean isTypeVar = false;
if ("this".equals(name)) {
type = getDeclaredTypeOf("this");
} else if (locals.containsKey(name)) {
type = locals.get(name).getDeclaredType();
} else if (formals.contains(name)) {
int formalIndex = formals.indexOf(name);
if (declaredType != null && formalIndex != -1) {
JSType formalType = declaredType.getFormalType(formalIndex);
if (formalType != null && !formalType.isBottom()) {
type = formalType;
}
}
} else if (localFunDefs.containsKey(name)) {
// external function namespaces, don't rely on localFunDefs
if (isFrozen && externs.containsKey(name)) {
type = externs.get(name);
}
} else if (localTypedefs.containsKey(name) || localNamespaces.containsKey(name)) {
// Any further declarations are shadowed
} else if (declaredType != null && declaredType.isTypeVariableDefinedLocally(name)) {
isTypeVar = true;
type = JSType.fromTypeVar(this.commonTypes, declaredType.getTypeVariableDefinedLocally(name));
} else if (externs.containsKey(name)) {
type = externs.get(name);
}
Namespace ns = null;
if (localNamespaces.containsKey(name)) {
ns = localNamespaces.get(name);
} else if (preservedNamespaces != null) {
ns = preservedNamespaces.get(name);
}
return new Declaration(type, localTypedefs.get(name), ns, localFunDefs.get(name), isTypeVar, constVars.contains(name));
}
use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class NTIScope method getDeclaration.
@Override
public Declaration getDeclaration(QualifiedName qname, boolean includeTypes) {
if (qname.isIdentifier()) {
return getDeclaration(qname.getLeftmostName(), includeTypes);
}
Namespace ns = getNamespace(qname.getLeftmostName());
if (ns == null) {
return maybeGetForwardDeclaration(qname.toString());
}
Declaration decl = ns.getDeclaration(qname.getAllButLeftmost());
return decl != null ? decl : maybeGetForwardDeclaration(qname.toString());
}
use of com.google.javascript.jscomp.newtypes.Declaration in project closure-compiler by google.
the class SimpleInference method inferPrototypeProperty.
private JSType inferPrototypeProperty(Node recv, String pname, NTIScope scope) {
QualifiedName recvQname = QualifiedName.fromNode(recv);
Declaration decl = scope.getDeclaration(recvQname, false);
if (decl != null) {
Namespace ns = decl.getNamespace();
if (ns instanceof RawNominalType) {
return ((RawNominalType) ns).getProtoPropDeclaredType(pname);
}
}
return null;
}
Aggregations