class TypeValidator
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
TypeValidator.TypeMismatch
Signals that the first type and the second type have been
used interchangeably.
|
Constructor and Description |
---|
TypeValidator(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private static boolean |
containsForwardDeclaredUnresolvedName(JSType type) |
(package private) void |
expectActualObject(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to be an object.
|
(package private) void |
expectAllInterfaceProperties(NodeTraversal t,
Node n,
FunctionType type)
Expect that all properties on interfaces that this type implements are
implemented and correctly typed.
|
(package private) void |
expectAnyObject(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to contain an object sometimes.
|
(package private) void |
expectArgumentMatchesParameter(NodeTraversal t,
Node n,
JSType argType,
JSType paramType,
Node callNode,
int ordinal)
Expect that the type of an argument matches the type of the parameter
that it's fulfilling.
|
(package private) void |
expectBitwiseable(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to be a valid operand to a bitwise operator.
|
(package private) boolean |
expectCanAssignTo(NodeTraversal t,
Node n,
JSType rightType,
JSType leftType,
java.lang.String msg)
Expect that the first type can be assigned to a symbol of the second
type.
|
(package private) boolean |
expectCanAssignToPropertyOf(NodeTraversal t,
Node n,
JSType rightType,
JSType leftType,
Node owner,
java.lang.String propName)
Expect that the first type can be assigned to a symbol of the second
type.
|
(package private) void |
expectCanCast(NodeTraversal t,
Node n,
JSType castType,
JSType type)
Expect that the first type can be cast to the second type.
|
(package private) void |
expectCastIsNecessary(NodeTraversal t,
Node n,
JSType castType,
JSType type)
Expect that casting type to castType is necessary.
|
(package private) void |
expectIndexMatch(NodeTraversal t,
Node n,
JSType objType,
JSType indexType)
Expect that the first type can be addressed with GETELEM syntax,
and that the second type is the right type for an index into the
first type.
|
private void |
expectInterfaceProperty(NodeTraversal t,
Node n,
ObjectType instance,
ObjectType implementedInterface,
java.lang.String prop)
Expect that the property in an interface that this type implements is
implemented and correctly typed.
|
(package private) boolean |
expectNotNullOrUndefined(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg,
JSType expectedType)
Expect the type to be anything but the null or void type.
|
(package private) void |
expectNumber(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to be a number, or a type convertible to number.
|
(package private) boolean |
expectObject(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to be an object, or a type convertible to object.
|
(package private) void |
expectString(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to be a string, or a type convertible to string.
|
(package private) void |
expectStringOrNumber(NodeTraversal t,
Node n,
JSType type,
java.lang.String msg)
Expect the type to be a number or string, or a type convertible to a number
or string.
|
(package private) void |
expectSuperType(NodeTraversal t,
Node n,
ObjectType superObject,
ObjectType subObject)
Expect that the first type is the direct superclass of the second type.
|
(package private) void |
expectSwitchMatchesCase(NodeTraversal t,
Node n,
JSType switchType,
JSType caseType)
Expect that the type of a switch condition matches the type of its
case condition.
|
(package private) TypedVar |
expectUndeclaredVariable(java.lang.String sourceName,
CompilerInput input,
Node n,
Node parent,
TypedVar var,
java.lang.String variableName,
JSType newType)
Expect that the given variable has not been declared with a type.
|
(package private) void |
expectValidTypeofName(NodeTraversal t,
Node n,
java.lang.String found) |
private static java.lang.String |
formatFoundRequired(java.lang.String description,
JSType found,
JSType required)
Formats a found/required error message.
|
(package private) static FunctionType |
getFunctionType(TypedVar v)
Utility function for getting a function type from a var.
|
java.lang.Iterable<TypeValidator.TypeMismatch> |
getImplicitStructuralInterfaceUses()
all uses of implicitly implemented structural interfaces,
captured during type validation and type checking
(uses of explicitly @implemented structural interfaces are excluded)
|
(package private) static ObjectType |
getInstanceOfCtor(TypedVar v)
Utility function for getting an instance type from a var pointing
to the constructor.
|
private JSType |
getJSType(Node n)
This method gets the JSType from the Node argument and verifies that it is
present.
|
(package private) java.lang.Iterable<TypeValidator.TypeMismatch> |
getMismatches()
Gets a list of type violations.
|
private JSType |
getNativeType(JSTypeNative typeId) |
private void |
mismatch(Node n,
java.lang.String msg,
JSType found,
JSType required) |
private void |
mismatch(NodeTraversal t,
Node n,
java.lang.String msg,
JSType found,
JSType required)
Report a type mismatch
|
private void |
mismatch(NodeTraversal t,
Node n,
java.lang.String msg,
JSType found,
JSTypeNative required) |
private void |
recordStructuralInterfaceUses(JSType found,
JSType required) |
private void |
registerIfMismatch(JSType found,
JSType required,
JSError error) |
private void |
registerMismatch(JSType found,
JSType required,
JSError error) |
private JSError |
report(JSError error) |
private final AbstractCompiler compiler
private final JSTypeRegistry typeRegistry
private final JSType allValueTypes
private final JSType nullOrUndefined
private final boolean reportUnnecessaryCasts
private final java.util.List<TypeValidator.TypeMismatch> mismatches
private final java.util.List<TypeValidator.TypeMismatch> implicitStructuralInterfaceUses
private static final java.lang.String FOUND_REQUIRED
static final DiagnosticType INVALID_CAST
static final DiagnosticType UNNECESSARY_CAST
static final DiagnosticType TYPE_MISMATCH_WARNING
static final DiagnosticType MISSING_EXTENDS_TAG_WARNING
static final DiagnosticType DUP_VAR_DECLARATION
static final DiagnosticType DUP_VAR_DECLARATION_TYPE_MISMATCH
static final DiagnosticType HIDDEN_PROPERTY_MISMATCH
static final DiagnosticType INTERFACE_METHOD_NOT_IMPLEMENTED
static final DiagnosticType HIDDEN_INTERFACE_PROPERTY_MISMATCH
static final DiagnosticType UNKNOWN_TYPEOF_VALUE
static final DiagnosticType ILLEGAL_PROPERTY_ACCESS
static final DiagnosticGroup ALL_DIAGNOSTICS
TypeValidator(AbstractCompiler compiler)
static FunctionType getFunctionType(@Nullable TypedVar v)
static ObjectType getInstanceOfCtor(@Nullable TypedVar v)
java.lang.Iterable<TypeValidator.TypeMismatch> getMismatches()
public java.lang.Iterable<TypeValidator.TypeMismatch> getImplicitStructuralInterfaceUses()
void expectValidTypeofName(NodeTraversal t, Node n, java.lang.String found)
boolean expectObject(NodeTraversal t, Node n, JSType type, java.lang.String msg)
void expectActualObject(NodeTraversal t, Node n, JSType type, java.lang.String msg)
void expectAnyObject(NodeTraversal t, Node n, JSType type, java.lang.String msg)
void expectString(NodeTraversal t, Node n, JSType type, java.lang.String msg)
void expectNumber(NodeTraversal t, Node n, JSType type, java.lang.String msg)
void expectBitwiseable(NodeTraversal t, Node n, JSType type, java.lang.String msg)
void expectStringOrNumber(NodeTraversal t, Node n, JSType type, java.lang.String msg)
boolean expectNotNullOrUndefined(NodeTraversal t, Node n, JSType type, java.lang.String msg, JSType expectedType)
private static boolean containsForwardDeclaredUnresolvedName(JSType type)
void expectSwitchMatchesCase(NodeTraversal t, Node n, JSType switchType, JSType caseType)
void expectIndexMatch(NodeTraversal t, Node n, JSType objType, JSType indexType)
t
- The node traversal.n
- The GETELEM node to issue warnings on.objType
- The type of the left side of the GETELEM.indexType
- The type inside the brackets of the GETELEM.boolean expectCanAssignToPropertyOf(NodeTraversal t, Node n, JSType rightType, JSType leftType, Node owner, java.lang.String propName)
t
- The node traversal.n
- The node to issue warnings on.rightType
- The type on the RHS of the assign.leftType
- The type of the symbol on the LHS of the assign.owner
- The owner of the property being assigned to.propName
- The name of the property being assigned to.boolean expectCanAssignTo(NodeTraversal t, Node n, JSType rightType, JSType leftType, java.lang.String msg)
t
- The node traversal.n
- The node to issue warnings on.rightType
- The type on the RHS of the assign.leftType
- The type of the symbol on the LHS of the assign.msg
- An extra message for the mismatch warning, if necessary.void expectArgumentMatchesParameter(NodeTraversal t, Node n, JSType argType, JSType paramType, Node callNode, int ordinal)
t
- The node traversal.n
- The node to issue warnings on.argType
- The type of the argument.paramType
- The type of the parameter.callNode
- The call node, to help with the warning message.ordinal
- The argument ordinal, to help with the warning message.void expectSuperType(NodeTraversal t, Node n, ObjectType superObject, ObjectType subObject)
t
- The node traversal.n
- The node where warnings should point to.superObject
- The expected super instance type.subObject
- The sub instance type.void expectCanCast(NodeTraversal t, Node n, JSType castType, JSType type)
t
- The node traversal.n
- The node where warnings should point.type
- The type being cast from.castType
- The type being cast to.void expectCastIsNecessary(NodeTraversal t, Node n, JSType castType, JSType type)
t
- The node traversal.n
- The node where warnings should point.castType
- The type being cast to.type
- The type being cast from.TypedVar expectUndeclaredVariable(java.lang.String sourceName, CompilerInput input, Node n, Node parent, TypedVar var, java.lang.String variableName, JSType newType)
sourceName
- The name of the source file we're in.n
- The node where warnings should point to.parent
- The parent of n
.var
- The variable that we're checking.variableName
- The name of the variable.newType
- The type being applied to the variable. Mostly just here
for the benefit of the warning.var
, but in some rare cases we will need to declare
a new var with new source info.void expectAllInterfaceProperties(NodeTraversal t, Node n, FunctionType type)
private void expectInterfaceProperty(NodeTraversal t, Node n, ObjectType instance, ObjectType implementedInterface, java.lang.String prop)
private void mismatch(NodeTraversal t, Node n, java.lang.String msg, JSType found, JSType required)
private void mismatch(NodeTraversal t, Node n, java.lang.String msg, JSType found, JSTypeNative required)
private void recordStructuralInterfaceUses(JSType found, JSType required)
private static java.lang.String formatFoundRequired(java.lang.String description, JSType found, JSType required)
private JSType getJSType(Node n)
private JSType getNativeType(JSTypeNative typeId)