use of com.google.javascript.jscomp.CodingConvention.ObjectLiteralCast 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;
}
Aggregations