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; }
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; }
/** * Returns true for types that are class like, i.e. that define a constructor or interface, but * excludes typedefs and the built-in constructor functions such as {@code Function}. */ private boolean isClassLike(JSType propType) { // Confusingly, the typedef type returns true on isConstructor checks, so we need to filter // the NoType through this utility method. return !isTypedef(propType) && (propType.isConstructor() || propType.isInterface()) // "Function" is a constructor, but does not define a new type for our purposes. && !propType.toMaybeObjectType().isNativeObjectType() && !propType.isFunctionPrototypeType(); }
/** * 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; }
&& getType(owner) != null && (getType(owner).isNominalConstructor() || getType(owner).isFunctionPrototypeType() || getType(owner).isEnumType())) { removeSymbol(s);
&& getType(owner) != null && (getType(owner).isNominalConstructor() || getType(owner).isFunctionPrototypeType() || getType(owner).isEnumType())) { removeSymbol(s);
/** * 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(); }
if (type.isFunctionPrototypeType()) { FunctionType maybeCtor = type.toMaybeObjectType().getOwnerFunction(); if (maybeCtor.isConstructor() || maybeCtor.isInterface()) {
private String getTypeAnnotation(Node node) { // Only add annotations for things with JSDoc, or function literals. JSDocInfo jsdoc = NodeUtil.getBestJSDocInfo(node); if (jsdoc == null && !node.isFunction()) { return ""; } JSType type = node.getJSType(); if (type == null) { return ""; } else if (type.isFunctionType()) { return getFunctionAnnotation(node); } else if (type.isEnumType()) { return "/** @enum {" + type.toMaybeEnumType().getElementsType().toAnnotationString() + "} */\n"; } else if (!type.isUnknownType() && !type.isEmptyType() && !type.isVoidType() && !type.isFunctionPrototypeType()) { return "/** @type {" + node.getJSType().toAnnotationString() + "} */\n"; } else { return ""; } }
} else if (type instanceof ValueType) { return type.toString(); } else if (type.isFunctionPrototypeType()) { return type.toString(); } else if (type instanceof ObjectType) {
if (ownerType.isFunctionPrototypeType()) { FunctionType ownerFn = ownerType.toObjectType().getOwnerFunction(); if (ownerFn.isInterface()
if (type.isFunctionPrototypeType()) { addRelatedInstance(((ObjectType) type).getOwnerFunction(), related); return;
if (ownerType.isFunctionPrototypeType()) { FunctionType ownerFn = ownerType.toObjectType().getOwnerFunction(); if (ownerFn.isInterface()
return grandparent.getJSType().isFunctionPrototypeType()
&& !type.isEmptyType() && !type.isVoidType() && !type.isFunctionPrototypeType()) { return "/** @type {" + node.getJSType().toAnnotationString(Nullability.EXPLICIT) + "} */\n"; } else {
globalScope.getSlot("Function") : getSymbolDeclaredBy(type.toMaybeFunctionType()); } else if (type.isFunctionPrototypeType()) { FunctionType ownerFn = ((ObjectType) type).getOwnerFunction(); if (!ownerFn.isConstructor() && !ownerFn.isInterface()) {
? globalScope.getSlot("Function") : getSymbolDeclaredBy(type.toMaybeFunctionType()); } else if (type.isFunctionPrototypeType()) { FunctionType ownerFn = ((ObjectType) type).getOwnerFunction(); if (!ownerFn.isConstructor() && !ownerFn.isInterface()) {
if (type.isFunctionPrototypeType() || (type.toObjectType() != null && type.toObjectType().getConstructor() != null)) {