use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NTIScope method getNamespaceAfterFreezing.
private Namespace getNamespaceAfterFreezing(String typeName) {
checkNotNull(preservedNamespaces, "Failed to preserve namespaces post-finalization");
QualifiedName qname = QualifiedName.fromQualifiedString(typeName);
Namespace ns = preservedNamespaces.get(qname.getLeftmostName());
if (ns != null && !qname.isIdentifier()) {
ns = ns.getSubnamespace(qname.getAllButLeftmost());
}
return ns;
}
use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NTIScope method addTypedef.
void addTypedef(Node qnameNode, Typedef td) {
if (qnameNode.isName()) {
checkState(!localTypedefs.containsKey(qnameNode.getString()));
localTypedefs.put(qnameNode.getString(), td);
} else {
checkState(!isDefined(qnameNode));
QualifiedName qname = QualifiedName.fromNode(qnameNode);
Namespace ns = getNamespace(qname.getLeftmostName());
ns.addTypedef(qname.getAllButLeftmost(), td);
namespaceTypedefs.add(td);
}
}
use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NTIScope method getScope.
NTIScope getScope(String fnName) {
NTIScope s = getScopeHelper(new QualifiedName(fnName));
checkState(s != null);
return s;
}
use of com.google.javascript.jscomp.newtypes.QualifiedName 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;
}
use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NewTypeInference method analyzeObjLitFwd.
private EnvTypePair analyzeObjLitFwd(Node objLit, TypeEnv inEnv, JSType requiredType, JSType specializedType) {
if (NodeUtil.isEnumDecl(objLit.getParent())) {
return analyzeEnumObjLitFwd(objLit, inEnv, requiredType);
}
JSDocInfo jsdoc = objLit.getJSDocInfo();
boolean isStruct = jsdoc != null && jsdoc.makesStructs();
boolean isDict = jsdoc != null && jsdoc.makesDicts();
TypeEnv env = inEnv;
JSType result = pickReqObjType(objLit);
for (Node prop : objLit.children()) {
if (isStruct && prop.isQuotedString()) {
warnings.add(JSError.make(prop, ILLEGAL_OBJLIT_KEY, "struct"));
} else if (isDict && !prop.isQuotedString()) {
warnings.add(JSError.make(prop, ILLEGAL_OBJLIT_KEY, "dict"));
}
// an accidental clash.
if (prop.isGetterDef() || prop.isSetterDef()) {
String pname = NodeUtil.getObjectLitKeyName(prop);
EnvTypePair pair = analyzeExprFwd(prop.getFirstChild(), env);
FunctionType funType = pair.type.getFunType();
checkNotNull(funType);
String specialPropName;
JSType propType;
if (prop.isGetterDef()) {
specialPropName = commonTypes.createGetterPropName(pname);
propType = funType.getReturnType();
} else {
specialPropName = commonTypes.createSetterPropName(pname);
propType = pair.type;
}
result = result.withProperty(new QualifiedName(specialPropName), propType);
env = pair.env;
} else {
Node pnameNode = NodeUtil.getObjectLitKeyNode(prop);
if (pnameNode == null) {
// pnameNode is null when prop is a computed prop does not have a String node key.
// Just type-check the prop, then move on to the next property.
env = analyzeExprFwd(prop, env).env;
continue;
}
QualifiedName qname = new QualifiedName(pnameNode.getString());
JSType jsdocType = (JSType) prop.getTypeI();
JSType reqPtype;
JSType specPtype;
if (jsdocType != null) {
reqPtype = specPtype = jsdocType;
} else if (requiredType.mayHaveProp(qname)) {
reqPtype = specPtype = requiredType.getProp(qname);
if (specializedType.mayHaveProp(qname)) {
specPtype = specializedType.getProp(qname);
}
} else {
reqPtype = specPtype = UNKNOWN;
}
EnvTypePair pair = analyzeExprFwd(prop, env, reqPtype, specPtype);
if (jsdocType != null) {
// First declare it; then set the maybe more precise inferred type
result = result.withDeclaredProperty(qname, jsdocType, false);
if (!pair.type.isSubtypeOf(jsdocType)) {
warnings.add(JSError.make(prop, INVALID_OBJLIT_PROPERTY_TYPE, errorMsgWithTypeDiff(jsdocType, pair.type)));
pair.type = jsdocType;
}
}
result = result.withProperty(qname, pair.type);
env = pair.env;
}
}
result = mayAdjustObjLitType(objLit, jsdoc, inEnv, result);
return new EnvTypePair(env, result);
}
Aggregations