public abstract class JSType extends Object implements TypeI, FunctionTypeI, ObjectTypeI
TypeI.Nullability, TypeI.TypeInference| Modifier and Type | Field and Description |
|---|---|
static boolean |
mockToString |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsArguments(List<? extends TypeI> argumentTypes)
Checks if a call to this function with the given list of arguments is valid.
|
JSType |
autobox() |
ObjectTypeI |
autoboxAndGetObject() |
static JSType |
buildRecordTypeFromObject(JSTypes commonTypes,
JSType t)
Create an anonymous record using the "own" properties of the given type.
|
boolean |
containsArray() |
TypeI |
convertMethodToFunction()
Creates a new function type B based on the original function type A.
|
boolean |
equals(Object o) |
JSType |
findSubtypeWithProp(QualifiedName pname) |
static JSType |
fromObjectType(com.google.javascript.jscomp.newtypes.ObjectType obj) |
static JSType |
fromProperties(JSTypes commonTypes,
Map<String,JSType> propTypes)
Create an anonymous record type with the given properties.
|
static JSType |
fromTypeVar(JSTypes commonTypes,
String typevarName) |
Collection<ObjectTypeI> |
getAncestorInterfaces() |
FunctionTypeI |
getConstructor()
Gets this object's constructor, or null if it is a native
object (constructed natively vs.
|
JSType |
getDeclaredProp(QualifiedName qname) |
Collection<FunctionTypeI> |
getDirectSubTypes()
Returns an iterable of direct types that are subtypes of this type.
|
String |
getDisplayName() |
JSType |
getEnumeratedTypeOfEnumElement() |
TypeI |
getEnumeratedTypeOfEnumObject()
If this type is an enum object, returns the declared type of the elements.
|
protected abstract com.google.common.collect.ImmutableSet<EnumType> |
getEnums() |
FunctionType |
getFunType() |
FunctionType |
getFunTypeIfSingletonObj() |
TypeI |
getGreatestSubtypeWithProperty(String pname) |
JSType |
getIndexedType() |
JSType |
getIndexType() |
ObjectTypeI |
getInstanceType()
Returns a type representing an instance of
this constructor,
or null if this is not a constructor. |
JSType |
getInstantiatedTypeArgument(JSType supertype)
Given an generic supertype of this,
returns the type argument as instantiated by this type.
|
JSDocInfo |
getJSDocInfo() |
TypeI |
getLegacyResolvedType()
Only called on instances of NamedType.
|
protected abstract int |
getMask() |
int |
getMaxArity()
Returns the maximum number of allowed arguments, or Integer.MAX_VALUE if variadic.
|
int |
getMinArity()
Returns the number of required arguments.
|
NominalType |
getNominalTypeIfSingletonObj() |
FunctionTypeI |
getOwnerFunction()
If this type represents the object in a function's prototype property, return that function.
|
Node |
getOwnPropertyDefSite(String propertyName) |
JSDocInfo |
getOwnPropertyJSDocInfo(String propertyName)
TODO(dimvar): rename methods in this file that use the phrase OwnProp to NonInheritedProp,
to avoid ambiguity with the built-in methods such as hasOwnProperty, which have
different semantics.
|
Iterable<String> |
getOwnPropertyNames()
Return the names of all non-inherited properties of this type, including prototype properties.
|
Iterable<TypeI> |
getParameterTypes() |
JSType |
getProp(QualifiedName qname) |
Node |
getPropertyDefSite(String propertyName) |
JSDocInfo |
getPropertyJSDocInfo(String propertyName) |
Set<String> |
getPropertyNames()
Returns a set of properties defined or inferred on this type or any of its supertypes.
|
TypeI |
getPropertyType(String propName)
Returns the type of property propName on this object, or null if the property doesn't exist.
|
JSType |
getPrototypeObject()
Returns the __proto__ object of this object type, NOT the ".prototype" property.
|
ObjectTypeI |
getPrototypeProperty() |
ObjectTypeI |
getRawType()
If this type is not generic, return as is.
|
String |
getReferenceName()
For a constructor function, returns the name of the instances.
|
TypeI |
getReturnType() |
Node |
getSource()
Gets the AST Node where this function was defined.
|
FunctionTypeI |
getSuperClassConstructor() |
com.google.common.collect.ImmutableList<? extends TypeI> |
getTemplateTypes()
For an instantiated generic type, return the types that the type variables are mapped to.
|
JSType |
getTopDefiningInterface(String pname)
Given an interface and a property, finds a top-most super interface
that has the property defined (including this interface).
|
TypeI |
getTypeOfThis()
Gets the type of
this in this function. |
List<TypeI> |
getTypeParameters()
If this type is a generic nominal type or function, return the type parameters as type
variables.
|
protected abstract String |
getTypeVar() |
Iterable<JSType> |
getUnionMembers()
If this type is a union type, returns a list of its members.
|
boolean |
hasConstantProp(QualifiedName pname) |
int |
hashCode() |
boolean |
hasInstanceType()
Returns whether
this type represents a constructor. |
boolean |
hasNonScalar() |
boolean |
hasOwnProperty(String propertyName) |
boolean |
hasProp(QualifiedName qname) |
boolean |
hasProperties()
Whether this function type has any properties (not counting "prototype").
|
boolean |
hasProperty(String propertyName) |
boolean |
hasTypeVariable() |
static boolean |
haveCommonSubtype(JSType lhs,
JSType rhs) |
JSType |
instantiateGenerics(List<? extends TypeI> typeiArgs)
If this type represents an uninstantiated nominal type or function, instantiate it using
the given type arguments.
|
ObjectTypeI |
instantiateGenericsWithUnknown()
When this type represents an instance of a generic class/interface Foo, return an instance
of Foo with type parameters mapped to the unknown type.
|
boolean |
isAmbiguousObject()
Returns true if this object is an anonymous object or function type (i.e.
|
boolean |
isAnyFalsyType() |
boolean |
isAnyTruthyType() |
boolean |
isBoolean() |
boolean |
isBooleanValueType()
Whether the type is a scalar boolean.
|
boolean |
isBottom() |
boolean |
isBoxableScalar() |
boolean |
isConstructor() |
boolean |
isDict() |
boolean |
isEnumElement() |
boolean |
isEnumObject() |
boolean |
isEquivalentTo(TypeI type) |
boolean |
isFalseOrFalsy() |
boolean |
isFullyInstantiated()
Returns true if this type is a generic object (non function) and *all* its type variables
are instantiated.
|
boolean |
isFunctionType() |
boolean |
isFunctionWithProperties() |
boolean |
isGenericObjectType()
True if this type represents a generic object (non function) type, instantiated or not.
|
boolean |
isInstanceofObject()
True when the nominal type of this type is Object.
|
boolean |
isInstanceType()
Whether this type is an instance object of some constructor.
|
boolean |
isInterface() |
boolean |
isInterfaceDefinition() |
boolean |
isInterfaceInstance() |
boolean |
isIObject() |
boolean |
isLegacyNamedType()
The old type checker uses NamedType to wrap types (e.g., defined by typedefs), and to represent
unresolved forward declares.
|
boolean |
isLiteralObject() |
boolean |
isLoose() |
boolean |
isNamespace() |
boolean |
isNonClassyObject() |
boolean |
isNonLooseSubtypeOf(JSType other) |
boolean |
isNullable() |
boolean |
isNullOrUndef() |
boolean |
isNullType() |
boolean |
isNumber() |
boolean |
isNumberValueType()
Whether the type is a scalar number.
|
boolean |
isObjectType() |
boolean |
isPartiallyInstantiated()
Returns true if this type is a generic object (non function) and *some* of its type variables
are instantiated.
|
boolean |
isPropDefinedOnSubtype(QualifiedName pname) |
boolean |
isPrototypeObject() |
boolean |
isRecordType()
Whether this type represents an anonymous structural type, e.g., { a: number, b: string }.
|
boolean |
isScalar() |
boolean |
isSingletonObj() |
boolean |
isSomeUnknownType() |
boolean |
isString() |
boolean |
isStringValueType()
Whether the type is a scalar string.
|
boolean |
isStruct() |
boolean |
isStructuralInterface() |
boolean |
isStructWithoutProp(QualifiedName pname) |
boolean |
isSubtypeOf(TypeI other) |
boolean |
isSubtypeWithoutStructuralTyping(TypeI other) |
boolean |
isTop() |
boolean |
isTrueOrTruthy() |
boolean |
isTypeVariable() |
boolean |
isUndefined() |
boolean |
isUnion() |
boolean |
isUnionType() |
boolean |
isUnknown() |
boolean |
isUnknownType() |
boolean |
isUnresolved() |
boolean |
isUnresolvedOrResolvedUnknown() |
boolean |
isVoidable() |
boolean |
isVoidType() |
static JSType |
join(JSType lhs,
JSType rhs) |
boolean |
mayBeDict() |
boolean |
mayBeStruct() |
boolean |
mayContainUnknownObject() |
boolean |
mayHaveProp(QualifiedName qname) |
static JSType |
meet(JSType lhs,
JSType rhs) |
TypeI |
meetWith(TypeI other) |
JSType |
negate() |
ObjectTypeI |
normalizeObjectForCheckAccessControls()
Works around the OTI distinction between prototype-object types and other objects.
|
static JSType |
plus(JSType lhs,
JSType rhs) |
JSType |
removeType(JSType other) |
TypeI |
restrictByNotNullOrUndefined()
If this is a union type, returns a union type that does not include
the null or undefined type.
|
void |
setSource(Node n) |
JSType |
specialize(JSType other) |
JSType |
substituteGenerics(Map<String,JSType> concreteTypes)
Creates a new JSType by deeply substituting the *free* type variables in this type with
concrete replacements from the given map.
|
JSType |
substituteGenericsWithUnknown() |
String |
toAnnotationString(TypeI.Nullability nullability)
Returns a string representation of this type, suitable for printing
in type annotations at code generation time.
|
JSType |
toBoolean() |
FunctionTypeI |
toMaybeFunctionType()
Downcasts this to a FunctionTypeI, or returns null if this is not
a function.
|
ObjectTypeI |
toMaybeObjectType()
If this type is a single object, downcast it to ObjectTypeI.
|
String |
toString() |
String |
toString(ToStringContext ctx) |
TypeI.TypeInference |
typeInference()
Returns the type inference of this object.
|
void |
unifyWith(JSType other,
List<String> typeParameters,
com.google.common.collect.Multimap<String,JSType> typeMultimap)
Unify
this, which may contain free type variables,
with other, a concrete subtype, modifying the supplied
typeMultimap to add any new template variable type bindings. |
static MismatchInfo |
whyNotSubtypeOf(JSType found,
JSType expected) |
JSType |
withDeclaredProperty(QualifiedName qname,
JSType type,
boolean isConstant) |
JSType |
withFunction(FunctionType ft,
NominalType fnNominal) |
JSType |
withLoose()
Turns the class-less object of this type (if any) into a loose object
|
JSType |
withoutProperty(QualifiedName qname) |
JSType |
withProperty(QualifiedName qname,
JSType type) |
JSType |
withPropertyRequired(String pname) |
FunctionTypeI |
withReturnType(TypeI returnType)
Returns a function type that is the same as functionType except for the return type, which is
set to be returnType.
|
protected abstract int getMask()
protected abstract String getTypeVar()
protected abstract com.google.common.collect.ImmutableSet<EnumType> getEnums()
public static JSType fromObjectType(com.google.javascript.jscomp.newtypes.ObjectType obj)
public final boolean isUndefined()
public final boolean isUnknown()
public final boolean isTrueOrTruthy()
public final boolean isFalseOrFalsy()
public final boolean isAnyTruthyType()
public final boolean isAnyFalsyType()
public final boolean isBoolean()
public final boolean isBooleanValueType()
TypeIisBooleanValueType in interface TypeIpublic final boolean isString()
public final boolean isStringValueType()
TypeIisStringValueType in interface TypeIpublic final boolean isNumber()
public final boolean isNumberValueType()
TypeIisNumberValueType in interface TypeIpublic final boolean isNullOrUndef()
public final boolean isScalar()
public final boolean hasNonScalar()
public final boolean isNullable()
isNullable in interface TypeIpublic final boolean isTypeVariable()
isTypeVariable in interface TypeIpublic final boolean hasTypeVariable()
public final boolean isStruct()
public final boolean mayBeStruct()
public final boolean isStructWithoutProp(QualifiedName pname)
public final boolean isLoose()
public final boolean isDict()
public final JSType getIndexType()
public final JSType getIndexedType()
public final boolean mayBeDict()
public final boolean isEnumElement()
isEnumElement in interface TypeIpublic final boolean isEnumObject()
isEnumObject in interface TypeIpublic final TypeI getEnumeratedTypeOfEnumObject()
ObjectTypeIgetEnumeratedTypeOfEnumObject in interface ObjectTypeIpublic final boolean isUnion()
public final boolean isFunctionWithProperties()
public final boolean isNamespace()
public final JSType getEnumeratedTypeOfEnumElement()
getEnumeratedTypeOfEnumElement in interface TypeIpublic final JSType substituteGenerics(Map<String,JSType> concreteTypes)
ForAll T.Foo<T>.
When you define a generic function f with U, that takes a Foo<U> as an argument and
returns a U, f's type is ForAll U.Foo<U> => U.
When you call f with some argument, say Foo of string, you instantiate U in f's type.
The part of f's type without the ForAll contains U as a free type variable.
So you call substituteGenerics in order to convert the Foo<U> to a Foo<string>public final JSType substituteGenericsWithUnknown()
public JSType getInstantiatedTypeArgument(JSType supertype)
(Iterable<Foo>).getInstantiatedTypeArgument(Iterable<?>) returns Foo,
and
/** {@literal @}template A * /
class Foo {}
/**
* {@literal @}template B
* {@literal @}extends {Foo<Array<B>>}
* /
class Bar {}
(Bar<string>).getInstantiatedTypeArguments(Bar<?>) returns string
(Bar<string>).getInstantiatedTypeArguments(Foo<?>) returns Array<string>
This is used, for example, in type-checking for-of and yield.public final void unifyWith(JSType other, List<String> typeParameters, com.google.common.collect.Multimap<String,JSType> typeMultimap)
this, which may contain free type variables,
with other, a concrete subtype, modifying the supplied
typeMultimap to add any new template variable type bindings.
This method should only be called outside the newtypes package;
classes inside the package should use unifyWithSubtype.
Unification algorithm.
Say that this is a potentially generic type G and other is a concrete type C.
1. If C is not a union:
(A) If C is a subtype of G, then unification succeeds and we don't update the type map.
E.g., (T|string) unifies with string and we learn nothing about T.
(B) If some member of G unifies with C, unification succeeds and we update the type map.
(C) If 2+ members of G unify with C, we use each of them to update the type map. This is
simpler than depending on the iteration order of the members of G to decide which one
to unify with C.
E.g., if Foo extends Bar and implements Baz,
(Bar(T)|Baz(T)) unifies with Foo(number) and T is number.
(Bar(number, T)|Baz(T, string)) doesn't unify with Foo(number,string), but each member
unifies with C, and we get a "not unique instantiation" warning.
2. If C is a union:
We throw away C's members that are subtypes of G, and for each remaining
member we try to individually unify G with it. A single member of G may unify with
2+ members of C.
Let SubC be a type that contains all members of C that are left over: they are not subtypes
of G and G doesn't unify with them. If G is of the form (T|...), then T is mapped to SubC.
E.g., (T|Foo|Bar(U)) unifies with (number|string|Foo|Bar(Baz))
SubC is (number|string), T is mapped to (number|string), and U is mapped to Baz.public final JSType negate()
public final JSType toBoolean()
public final boolean isNonLooseSubtypeOf(JSType other)
public final boolean isSubtypeOf(TypeI other)
isSubtypeOf in interface TypeIpublic static MismatchInfo whyNotSubtypeOf(JSType found, JSType expected)
public final JSType withFunction(FunctionType ft, NominalType fnNominal)
public final boolean isSingletonObj()
public final FunctionType getFunTypeIfSingletonObj()
public final FunctionType getFunType()
public final NominalType getNominalTypeIfSingletonObj()
public final boolean isInterfaceInstance()
public final boolean isNonClassyObject()
public final boolean isIObject()
public final boolean isInterfaceDefinition()
public final JSType withLoose()
public final JSType getProp(QualifiedName qname)
public final JSType getDeclaredProp(QualifiedName qname)
public final boolean mayHaveProp(QualifiedName qname)
public final boolean hasProp(QualifiedName qname)
public final boolean hasConstantProp(QualifiedName pname)
public final boolean containsArray()
containsArray in interface TypeIpublic final JSType withoutProperty(QualifiedName qname)
public final JSType withProperty(QualifiedName qname, JSType type)
public final JSType withDeclaredProperty(QualifiedName qname, JSType type, boolean isConstant)
public final JSType findSubtypeWithProp(QualifiedName pname)
public final boolean isPropDefinedOnSubtype(QualifiedName pname)
public final String toString(ToStringContext ctx)
public final String toAnnotationString(TypeI.Nullability nullability)
TypeItoAnnotationString in interface TypeIpublic final boolean isConstructor()
isConstructor in interface TypeIpublic final boolean isEquivalentTo(TypeI type)
isEquivalentTo in interface TypeIpublic final boolean isFunctionType()
isFunctionType in interface TypeIpublic final boolean isInterface()
isInterface in interface TypeIpublic final boolean isUnknownType()
isUnknownType in interface TypeIpublic final boolean isSomeUnknownType()
isSomeUnknownType in interface TypeIpublic final boolean isUnresolved()
isUnresolved in interface TypeIpublic final boolean isUnresolvedOrResolvedUnknown()
isUnresolvedOrResolvedUnknown in interface TypeIpublic final boolean isUnionType()
isUnionType in interface TypeIpublic final boolean isVoidable()
isVoidable in interface TypeIpublic final boolean isNullType()
isNullType in interface TypeIpublic final boolean isVoidType()
isVoidType in interface TypeIpublic final TypeI restrictByNotNullOrUndefined()
TypeIrestrictByNotNullOrUndefined in interface TypeIpublic final FunctionTypeI toMaybeFunctionType()
TypeItoMaybeFunctionType in interface TypeIpublic final ObjectTypeI toMaybeObjectType()
TypeItoMaybeObjectType in interface TypeIpublic final ObjectTypeI autoboxAndGetObject()
autoboxAndGetObject in interface TypeIpublic final String getDisplayName()
getDisplayName in interface TypeIpublic final TypeI convertMethodToFunction()
FunctionTypeIconvertMethodToFunction in interface FunctionTypeIpublic final boolean hasInstanceType()
FunctionTypeIthis type represents a constructor.hasInstanceType in interface FunctionTypeIpublic final ObjectTypeI getInstanceType()
FunctionTypeIthis constructor,
or null if this is not a constructor.getInstanceType in interface FunctionTypeIpublic final String getReferenceName()
FunctionTypeIgetReferenceName in interface FunctionTypeIpublic final Node getSource()
FunctionTypeIgetSource in interface FunctionTypeIpublic final Collection<FunctionTypeI> getDirectSubTypes()
FunctionTypeIgetDirectSubTypes in interface FunctionTypeIpublic final TypeI getTypeOfThis()
FunctionTypeIthis in this function.getTypeOfThis in interface FunctionTypeIpublic final boolean acceptsArguments(List<? extends TypeI> argumentTypes)
FunctionTypeIacceptsArguments in interface FunctionTypeIpublic final int getMinArity()
FunctionTypeIgetMinArity in interface FunctionTypeIpublic final int getMaxArity()
FunctionTypeIgetMaxArity in interface FunctionTypeIpublic final List<TypeI> getTypeParameters()
TypeIgetTypeParameters in interface TypeIpublic final boolean hasProperties()
FunctionTypeIhasProperties in interface FunctionTypeIpublic final void setSource(Node n)
setSource in interface FunctionTypeIpublic final TypeI getReturnType()
getReturnType in interface FunctionTypeIpublic FunctionTypeI withReturnType(TypeI returnType)
FunctionTypeIwithReturnType in interface FunctionTypeIpublic final FunctionTypeI getConstructor()
ObjectTypeIgetConstructor in interface ObjectTypeIpublic final FunctionTypeI getSuperClassConstructor()
getSuperClassConstructor in interface ObjectTypeIpublic final JSType getPrototypeObject()
ObjectTypeIgetPrototypeObject in interface ObjectTypeIpublic final JSDocInfo getJSDocInfo()
getJSDocInfo in interface TypeIpublic final JSDocInfo getOwnPropertyJSDocInfo(String propertyName)
ObjectTypeIgetOwnPropertyJSDocInfo in interface ObjectTypeIpublic final JSDocInfo getPropertyJSDocInfo(String propertyName)
getPropertyJSDocInfo in interface ObjectTypeIpublic final Node getOwnPropertyDefSite(String propertyName)
getOwnPropertyDefSite in interface ObjectTypeIpublic final Node getPropertyDefSite(String propertyName)
getPropertyDefSite in interface ObjectTypeIpublic final Iterable<String> getOwnPropertyNames()
ObjectTypeIgetOwnPropertyNames in interface ObjectTypeIpublic final boolean isPrototypeObject()
isPrototypeObject in interface TypeIpublic final boolean isAmbiguousObject()
ObjectTypeIisAmbiguousObject in interface ObjectTypeIpublic final boolean isLiteralObject()
isLiteralObject in interface TypeIpublic final boolean isInstanceofObject()
TypeIisInstanceofObject in interface TypeIpublic final boolean mayContainUnknownObject()
public final boolean isInstanceType()
ObjectTypeIisInstanceType in interface ObjectTypeIpublic final boolean hasProperty(String propertyName)
hasProperty in interface ObjectTypeIpublic final Iterable<JSType> getUnionMembers()
TypeIgetUnionMembers in interface TypeIpublic final ObjectTypeI normalizeObjectForCheckAccessControls()
ObjectTypeInormalizeObjectForCheckAccessControls in interface ObjectTypeIpublic final boolean isBoxableScalar()
isBoxableScalar in interface TypeIpublic final boolean isObjectType()
isObjectType in interface TypeIpublic final boolean isGenericObjectType()
TypeIisGenericObjectType in interface TypeIpublic final Collection<ObjectTypeI> getAncestorInterfaces()
getAncestorInterfaces in interface FunctionTypeIpublic final boolean isStructuralInterface()
isStructuralInterface in interface TypeIpublic final boolean hasOwnProperty(String propertyName)
hasOwnProperty in interface ObjectTypeIpublic final ObjectTypeI getRawType()
ObjectTypeIgetRawType in interface ObjectTypeIpublic final ObjectTypeI instantiateGenericsWithUnknown()
ObjectTypeIinstantiateGenericsWithUnknown in interface ObjectTypeIpublic final JSType instantiateGenerics(List<? extends TypeI> typeiArgs)
public static JSType fromProperties(JSTypes commonTypes, Map<String,JSType> propTypes)
public static JSType buildRecordTypeFromObject(JSTypes commonTypes, JSType t)
public final boolean isLegacyNamedType()
ObjectTypeIisLegacyNamedType in interface ObjectTypeIpublic final TypeI getLegacyResolvedType()
ObjectTypeIgetLegacyResolvedType in interface ObjectTypeIpublic final TypeI getGreatestSubtypeWithProperty(String pname)
getGreatestSubtypeWithProperty in interface TypeIpublic final ObjectTypeI getPrototypeProperty()
getPrototypeProperty in interface FunctionTypeIpublic final JSType getTopDefiningInterface(String pname)
ObjectTypeIgetTopDefiningInterface in interface ObjectTypeIpublic final FunctionTypeI getOwnerFunction()
ObjectTypeIgetOwnerFunction in interface ObjectTypeIpublic final boolean isSubtypeWithoutStructuralTyping(TypeI other)
isSubtypeWithoutStructuralTyping in interface TypeIpublic final Iterable<TypeI> getParameterTypes()
getParameterTypes in interface FunctionTypeIpublic TypeI getPropertyType(String propName)
ObjectTypeIgetPropertyType in interface ObjectTypeIpublic boolean isRecordType()
TypeIisRecordType in interface TypeIpublic boolean isFullyInstantiated()
TypeIisFullyInstantiated in interface TypeIpublic boolean isPartiallyInstantiated()
TypeIisPartiallyInstantiated in interface TypeIpublic com.google.common.collect.ImmutableList<? extends TypeI> getTemplateTypes()
ObjectTypeIgetTemplateTypes in interface ObjectTypeIpublic Set<String> getPropertyNames()
ObjectTypeIgetPropertyNames in interface ObjectTypeIpublic TypeI.TypeInference typeInference()
TypeItypeInference in interface TypeICopyright © 2009-2017 Google. All Rights Reserved.