/** Creates an instance for a function that might be a constructor. */ FunctionType( JSTypeRegistry registry, String name, Node source, ArrowType arrowType, JSType typeOfThis, TemplateTypeMap templateTypeMap, boolean isConstructor, boolean nativeType) { super( registry, name, registry.getNativeObjectType(JSTypeNative.FUNCTION_INSTANCE_TYPE), nativeType, templateTypeMap); setPrettyPrint(true); Preconditions.checkArgument(source == null || Token.FUNCTION == source.getType()); Preconditions.checkNotNull(arrowType); this.source = source; if (isConstructor) { this.kind = Kind.CONSTRUCTOR; this.propAccess = PropAccess.ANY; this.typeOfThis = typeOfThis != null ? typeOfThis : new InstanceObjectType(registry, this, nativeType); } else { this.kind = Kind.ORDINARY; this.typeOfThis = typeOfThis != null ? typeOfThis : registry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE); } this.call = arrowType; }
/** Returns ALL_TYPE, UNKNOWN_TYPE, or CHECKED_UNKNOWN_TYPE, as specified by the flags, or null */ private JSType getNativeWildcardType() { if (isAllType) { return registry.getNativeType(ALL_TYPE); } else if (isNativeUnknownType) { if (areAllUnknownsChecked) { return registry.getNativeType(CHECKED_UNKNOWN_TYPE); } else { return registry.getNativeType(UNKNOWN_TYPE); } } return null; }
/** * Reduce the alternates into a non-union type. If the alternates can't be accurately represented * with a non-union type, return null. */ private JSType reduceAlternatesWithoutUnion() { JSType wildcard = getNativeWildcardType(); if (wildcard != null) { return containsVoidType ? null : wildcard; } int size = alternates.size(); if (size > maxUnionSize) { return registry.getNativeType(UNKNOWN_TYPE); } else if (size > 1) { return null; } else if (size == 1) { return alternates.get(0); } else { return registry.getNativeType(NO_TYPE); } }
/** Create a named type based on the reference. */ NamedType(JSTypeRegistry registry, String reference, String sourceName, int lineno, int charno) { super(registry, registry.getNativeObjectType(JSTypeNative.UNKNOWN_TYPE)); Preconditions.checkNotNull(reference); this.reference = reference; this.sourceName = sourceName; this.lineno = lineno; this.charno = charno; }
Collection<JSType> getAlternates() { JSType specialCaseType = reduceAlternatesWithoutUnion(); if (specialCaseType != null) { return ImmutableList.of(specialCaseType); } JSType wildcard = getNativeWildcardType(); if (wildcard != null && containsVoidType) { return ImmutableList.of(wildcard, registry.getNativeType(VOID_TYPE)); } return Collections.unmodifiableList(alternates); }
/** * Creates an object type, allowing specification of the implicit prototype when creating native * objects. */ PrototypeObjectType( JSTypeRegistry registry, String className, ObjectType implicitPrototype, boolean nativeType) { super(registry); this.properties = Maps.newTreeMap(); this.className = className; this.nativeType = nativeType; if (nativeType || implicitPrototype != null) { setImplicitPrototype(implicitPrototype); } else { setImplicitPrototype(registry.getNativeObjectType(JSTypeNative.OBJECT_TYPE)); } }
/** Creates an instance for a function that is an interface. */ private FunctionType( JSTypeRegistry registry, String name, Node source, TemplateTypeMap typeParameters) { super( registry, name, registry.getNativeObjectType(JSTypeNative.FUNCTION_INSTANCE_TYPE), false, typeParameters); setPrettyPrint(true); Preconditions.checkArgument(source == null || Token.FUNCTION == source.getType()); Preconditions.checkArgument(name != null); this.source = source; this.call = new ArrowType(registry, new Node(Token.PARAM_LIST), null); this.kind = Kind.INTERFACE; this.typeOfThis = new InstanceObjectType(registry, this); }
/** * Creates an object type, allowing specification of the implicit prototype, whether the object is * native, and any templatized types. */ PrototypeObjectType( JSTypeRegistry registry, String className, ObjectType implicitPrototype, boolean nativeType, TemplateTypeMap templateTypeMap, boolean anonymousType) { super(registry, templateTypeMap); this.properties = new PropertyMap(); this.properties.setParentSource(this); this.className = className; this.nativeType = nativeType; this.anonymousType = anonymousType; if (nativeType || implicitPrototype != null) { setImplicitPrototype(implicitPrototype); } else { setImplicitPrototype(registry.getNativeObjectType(JSTypeNative.OBJECT_TYPE)); } }
NoObjectType(JSTypeRegistry registry) { super(registry, null, null, registry.createArrowType(null, null), null, null, true, true); getInternalArrowType().returnType = this; this.setInstanceType(this); }