public abstract class JSType extends Object implements TypeI, FunctionTypeI, ObjectTypeI
| 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() |
boolean |
containsArray() |
TypeI |
convertMethodToFunction()
Creates a new function type B based on the original function type A.
|
static String |
createGetterPropName(String originalPropName) |
static String |
createSetterPropName(String originalPropName) |
boolean |
equals(Object o) |
JSType |
findSubtypeWithProp(QualifiedName pname) |
static JSType |
fromObjectType(com.google.javascript.jscomp.newtypes.ObjectType obj) |
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) |
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 |
getInstantiatedTypeOfIterable()
Given a type that is a subtype of Iterable, returns what that Iterable is instantiated with.
|
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) |
Iterable<String> |
getOwnPropertyNames()
Returns the names of all the properties directly on this type.
|
Iterable<TypeI> |
getParameterTypes() |
JSType |
getProp(QualifiedName qname) |
Node |
getPropertyDefSite(String propertyName) |
JSDocInfo |
getPropertyJSDocInfo(String propertyName) |
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() |
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.
|
Collection<FunctionTypeI> |
getSubTypes()
Returns an iterable of direct types that are subtypes of this type.
|
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<String> |
getTypeParameters()
Returns the names of all type parameters.
|
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() |
boolean |
hasProperty(String propertyName) |
boolean |
hasTypeVariable() |
boolean |
hasUninstantiatedTypeVariables()
Returns true if this type is a generic object (non function) and some (or all) of its type
variables are not instantiated.
|
static boolean |
haveCommonSubtype(JSType lhs,
JSType rhs) |
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 |
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 |
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 |
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 |
isUnknownObject()
Returns true if this object is an anonymous object type (i.e.
|
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()
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 |
toNonNullAnnotationString()
Returns a string representation of this type, suitable for printing
in type annotations at code generation time.
|
String |
toString() |
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) |
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 getInstantiatedTypeOfIterable()
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 toNonNullAnnotationString()
TypeItoNonNullAnnotationString in interface TypeIpublic final String toAnnotationString()
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> getSubTypes()
FunctionTypeIgetSubTypes 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<String> getTypeParameters()
FunctionTypeIgetTypeParameters in interface FunctionTypeIpublic final boolean hasProperties()
hasProperties in interface FunctionTypeIpublic final void setSource(Node n)
setSource in interface FunctionTypeIpublic final TypeI getReturnType()
getReturnType 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)
getOwnPropertyJSDocInfo 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()
getOwnPropertyNames in interface ObjectTypeIpublic final boolean isPrototypeObject()
isPrototypeObject in interface TypeIpublic final boolean isUnknownObject()
ObjectTypeIisUnknownObject 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()
getRawType in interface ObjectTypeIpublic final ObjectTypeI instantiateGenericsWithUnknown()
ObjectTypeIinstantiateGenericsWithUnknown in interface ObjectTypeIpublic 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 hasUninstantiatedTypeVariables()
TypeIhasUninstantiatedTypeVariables in interface TypeIpublic com.google.common.collect.ImmutableList<? extends TypeI> getTemplateTypes()
ObjectTypeIgetTemplateTypes in interface ObjectTypeICopyright © 2009-2017 Google. All Rights Reserved.