@Override public final FunctionType getOwnerFunction() { return referencedObjType == null ? null : referencedObjType.getOwnerFunction(); }
@Override public final boolean isFunctionPrototypeType() { return getOwnerFunction() != null; }
@Override public final boolean isFunctionPrototypeType() { return getOwnerFunction() != null; }
@Override public FunctionType getOwnerFunction() { return referencedObjType == null ? null : referencedObjType.getOwnerFunction(); }
private ObjectType getPrototypeOwnerType(ObjectType ownerType) { if (ownerType != null && ownerType.isFunctionPrototypeType()) { return ownerType.getOwnerFunction(); } return null; }
private ObjectType getPrototypeOwnerType(ObjectType ownerType) { if (ownerType != null && ownerType.isFunctionPrototypeType()) { return ownerType.getOwnerFunction(); } return null; }
private void checkPropertyInheritanceOnPrototypeLitKey( NodeTraversal t, Node key, String propertyName, ObjectType type) { // Inheritance checks for prototype objlit properties. // // TODO(nicksantos): This isn't the right place to do this check. We // really want to do this when we're looking at the constructor. // We'd find all its properties and make sure they followed inheritance // rules, like we currently do for @implements to make sure // all the methods are implemented. // // As-is, this misses many other ways to override a property. // // object.prototype = { key: function() {} }; checkPropertyInheritance(t, key, propertyName, type.getOwnerFunction(), type); }
private JSType getInstanceFromPrototype(JSType type) { if (type.isFunctionPrototypeType()) { ObjectType prototype = (ObjectType) type; FunctionType owner = prototype.getOwnerFunction(); if (owner.isConstructor() || owner.isInterface()) { return prototype.getOwnerFunction().getInstanceType(); } } return null; }
private static boolean isStructuralInterfacePrototype(JSType type) { if (!type.isFunctionPrototypeType()) { return false; } FunctionType constructor = type.toObjectType().getOwnerFunction(); return constructor != null && constructor.isStructuralInterface(); }
private boolean isStructuralInterfacePrototype(JSType type) { return type.isFunctionPrototypeType() && type.toObjectType().getOwnerFunction().isStructuralInterface(); } }
/** * Returns the corresponding instance if `maybePrototype` is a prototype of a constructor, * otherwise null */ @Nullable private static JSType getInstanceIfPrototype(JSType maybePrototype) { if (maybePrototype.isFunctionPrototypeType()) { FunctionType constructor = maybePrototype.toObjectType().getOwnerFunction(); if (constructor != null) { if (!constructor.hasInstanceType()) { // this can happen when adding to the prototype of a non-constructor function return null; } return constructor.getInstanceType(); } } return null; }
/** * When a class has a stub for a property, and the property exists on a super interface, * use that type. */ private JSType getInheritedInterfacePropertyType(ObjectType obj, String propName) { if (obj != null && obj.isFunctionPrototypeType()) { FunctionType f = obj.getOwnerFunction(); for (ObjectType i : f.getImplementedInterfaces()) { if (i.hasProperty(propName)) { return i.getPropertyType(propName); } } } return null; }
private FunctionType getConstructor(JSType type) { ObjectType objType = type.toMaybeObjectType(); if (objType == null) { return null; } FunctionType constructor = null; if (objType.isFunctionType()) { constructor = objType.toMaybeFunctionType(); } else if (objType.isFunctionPrototypeType()) { constructor = objType.getOwnerFunction(); } else { constructor = objType.getConstructor(); } return constructor; } }
private FunctionType getConstructor(JSType type) { ObjectType objType = ObjectType.cast(type); if (objType == null) { return null; } FunctionType constructor = null; if (objType.isFunctionType()) { constructor = objType.toMaybeFunctionType(); } else if (objType.isFunctionPrototypeType()) { constructor = objType.getOwnerFunction(); } else { constructor = objType.getConstructor(); } return constructor != null && constructor.isConstructor() ? constructor : null; } }
private void checkPropertyInheritanceOnPrototypeLitKey( NodeTraversal t, Node key, String propertyName, ObjectType type) { // Inheritance checks for prototype objlit properties. // // TODO(nicksantos): This isn't the right place to do this check. We // really want to do this when we're looking at the constructor. // We'd find all its properties and make sure they followed inheritance // rules, like we currently do for @implements to make sure // all the methods are implemented. // // As-is, this misses many other ways to override a property. // // object.prototype = { key: function() {} }; FunctionType ctorType = type.getOwnerFunction(); if (ctorType == null || (!ctorType.isConstructor() && !ctorType.isInterface())) { return; } JSType propertyType = type.getPropertyType(propertyName); checkDeclaredPropertyInheritance( t, key.getFirstChild(), ctorType, propertyName, key.getJSDocInfo(), propertyType); }
/** * Normalize the type of a constructor, its instance, and its prototype * all down to the same type (the instance type). */ private static JSType normalizeClassType(JSType type) { if (type == null || type.isUnknownType()) { return type; } else if (type.isNominalConstructor()) { return (type.toMaybeFunctionType()).getInstanceType(); } else if (type.isFunctionPrototypeType()) { FunctionType owner = ((ObjectType) type).getOwnerFunction(); if (owner.isConstructor()) { return owner.getInstanceType(); } } return type; }
/** * Returns the type that best represents the instance type for {@code type}. * * <ul> * <li>Prototype type => The instance type having that prototype * <li>Instance type => The type * <li>Constructor type => The type that constructor instantiates * <li>Object-literal type => The type * </ul> */ @Nullable private static ObjectType instanceTypeFor(JSType type) { if (type == null) { return null; } else if (type.isUnionType()) { return null; // A union has no meaningful instance type. } else if (type.isInstanceType() || type.isUnknownType()) { return type.toMaybeObjectType(); } else if (type.isConstructor() || type.isInterface()) { return type.toMaybeFunctionType().getInstanceType(); } else if (type.isFunctionPrototypeType()) { return instanceTypeFor(type.toMaybeObjectType().getOwnerFunction()); } return type.toMaybeObjectType(); }
FunctionType ownerFn = ownerType.toObjectType().getOwnerFunction(); if (ownerFn.isInterface() && rightType.isFunctionType() && leftType.isFunctionType()) {
: getSymbolDeclaredBy(type.toMaybeFunctionType()); } else if (type.isFunctionPrototypeType()) { FunctionType ownerFn = ((ObjectType) type).getOwnerFunction(); if (!ownerFn.isConstructor() && !ownerFn.isInterface()) { return null;
if (foundObj != null) { if (foundObj.isFunctionPrototypeType()) { FunctionType ownerFun = foundObj.getOwnerFunction(); if (ownerFun.isConstructor()) { foundType = ownerFun.getInstanceType();