use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NewTypeInference method analyzePropAccessBwd.
private EnvTypePair analyzePropAccessBwd(Node receiver, String pname, TypeEnv outEnv, JSType requiredType) {
Node propAccessNode = receiver.getParent();
QualifiedName qname = new QualifiedName(pname);
JSType reqObjType = pickReqObjType(propAccessNode);
if (!NodeUtil.isPropertyTest(compiler, propAccessNode)) {
reqObjType = reqObjType.withProperty(qname, requiredType);
}
EnvTypePair pair = analyzeExprBwd(receiver, outEnv, reqObjType);
JSType receiverType = pair.type;
JSType propAccessType = receiverType.mayHaveProp(qname) ? receiverType.getProp(qname) : requiredType;
pair.type = propAccessType;
return pair;
}
use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NewTypeInference method mayAdjustObjLitType.
/**
* If the object literal is lended, or assigned to a prototype, find a better
* type for it than the object-literal type.
*/
private JSType mayAdjustObjLitType(Node objLit, JSDocInfo jsdoc, TypeEnv env, JSType originalType) {
Node parent = objLit.getParent();
QualifiedName classqname = null;
if (parent.isAssign() && NodeUtil.isPrototypeAssignment(parent.getFirstChild())) {
classqname = QualifiedName.fromNode(parent.getFirstFirstChild());
} else if (jsdoc != null && jsdoc.getLendsName() != null) {
QualifiedName lendsQname = QualifiedName.fromQualifiedString(jsdoc.getLendsName());
if (lendsQname.getRightmostName().equals("prototype")) {
classqname = lendsQname.getAllButRightmost();
}
} else if (parent.isCall() && this.convention.getObjectLiteralCast(parent) != null) {
ObjectLiteralCast cast = this.convention.getObjectLiteralCast(parent);
if (cast.typeName != null) {
classqname = QualifiedName.fromQualifiedString(cast.typeName);
}
}
if (classqname != null) {
JSType classType = envGetTypeOfQname(env, classqname);
if (classType != null) {
FunctionType clazz = classType.getFunTypeIfSingletonObj();
JSType instance = clazz == null ? null : clazz.getInstanceTypeOfCtor();
if (instance != null) {
return instance.getPrototypeObject();
}
}
}
return originalType;
}
use of com.google.javascript.jscomp.newtypes.QualifiedName in project closure-compiler by google.
the class NewTypeInference method mayWarnAboutNullableReferenceAndTighten.
private EnvTypePair mayWarnAboutNullableReferenceAndTighten(Node obj, JSType recvType, JSType maybeSpecType, TypeEnv inEnv) {
if (!recvType.isUnknown() && !recvType.isTop() && (NULL.isSubtypeOf(recvType) || UNDEFINED.isSubtypeOf(recvType))) {
JSType minusNull = recvType.removeType(NULL_OR_UNDEFINED);
if (!minusNull.isBottom()) {
if (this.reportNullDeref) {
warnings.add(JSError.make(obj, NULLABLE_DEREFERENCE, recvType.toString()));
}
TypeEnv outEnv = inEnv;
if (obj.isQualifiedName()) {
QualifiedName qname = QualifiedName.fromNode(obj);
if (maybeSpecType != null && maybeSpecType.isSubtypeOf(minusNull)) {
minusNull = maybeSpecType;
}
outEnv = updateLvalueTypeInEnv(inEnv, obj, qname, minusNull);
}
return new EnvTypePair(outEnv, minusNull);
}
}
return new EnvTypePair(inEnv, recvType);
}
Aggregations