Class TypeVariableSubstitutor
java.lang.Object
org.checkerframework.framework.type.TypeVariableSubstitutor
TypeVariableSubstitutor replaces type variables from a declaration with arguments to its use.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classVisitor that makes the substitution. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal AnnotatedTypeMirrorsubstitute(Map<TypeVariable, AnnotatedTypeMirror> typeVarToTypeArgument, AnnotatedTypeMirror type) Given a mapping from type variable to its type argument, replace each instance of a type variable with a copy of type argument.final AnnotatedTypeMirrorsubstitute(Map<TypeVariable, AnnotatedTypeMirror> typeVarToTypeArgument, AnnotatedTypeMirror type, boolean typeArgumentsInferred) Given a mapping from type variable to its type argument, replace each instance of a type variable with a copy of type argument.protected AnnotatedTypeMirrorsubstituteTypeVariable(AnnotatedTypeMirror argument, AnnotatedTypeMirror.AnnotatedTypeVariable use, boolean argumentIsInferred) Given the types of a type parameter declaration, the argument to that type parameter declaration, and a given use of that declaration, return a substitute for the use with the correct annotations.substituteWithoutCopyingTypeArguments(Map<TypeVariable, AnnotatedTypeMirror> typeVarToTypeArgument, AnnotatedTypeMirror type) Given a mapping from type variable to its type argument, replace each instance of a type variable with the given type argument.
-
Constructor Details
-
TypeVariableSubstitutor
public TypeVariableSubstitutor()Create a TypeVariableSubstitutor.
-
-
Method Details
-
substitute
public final AnnotatedTypeMirror substitute(Map<TypeVariable, AnnotatedTypeMirror> typeVarToTypeArgument, AnnotatedTypeMirror type) Given a mapping from type variable to its type argument, replace each instance of a type variable with a copy of type argument.This method is
final: it is a convenience entry point, not an extension point. A checker that wants to customize substitution should overridesubstituteTypeVariable(AnnotatedTypeMirror, AnnotatedTypeVariable, boolean)instead (installed viaAnnotatedTypeFactory#createTypeVariableSubstitutor), so there is exactly one override point rather than two arities that could be overridden inconsistently.- Parameters:
typeVarToTypeArgument- a mapping from type variable to its type argumenttype- the type to substitute- Returns:
- a copy of type with its type variables substituted
- See Also:
-
substitute
public final AnnotatedTypeMirror substitute(Map<TypeVariable, AnnotatedTypeMirror> typeVarToTypeArgument, AnnotatedTypeMirror type, boolean typeArgumentsInferred) Given a mapping from type variable to its type argument, replace each instance of a type variable with a copy of type argument.This method is
final; seesubstitute(Map, AnnotatedTypeMirror).- Parameters:
typeVarToTypeArgument- a mapping from type variable to its type argumenttype- the type to substitutetypeArgumentsInferred- whether the type arguments intypeVarToTypeArgumentwere inferred by the type checker, as opposed to written explicitly by the programmer at the call site- Returns:
- a copy of type with its type variables substituted
- See Also:
-
substituteWithoutCopyingTypeArguments
public AnnotatedTypeMirror substituteWithoutCopyingTypeArguments(Map<TypeVariable, AnnotatedTypeMirror> typeVarToTypeArgument, AnnotatedTypeMirror type) Given a mapping from type variable to its type argument, replace each instance of a type variable with the given type argument.- Parameters:
typeVarToTypeArgument- a mapping from type variable to its type argumenttype- the type to substitute- Returns:
- a copy of type with its type variables substituted
- See Also:
-
substituteTypeVariable
protected AnnotatedTypeMirror substituteTypeVariable(AnnotatedTypeMirror argument, AnnotatedTypeMirror.AnnotatedTypeVariable use, boolean argumentIsInferred) Given the types of a type parameter declaration, the argument to that type parameter declaration, and a given use of that declaration, return a substitute for the use with the correct annotations.To determine what primary annotations are correct for the substitute the following rules are used: If the type variable use has a primary annotation then apply that primary annotation to the substitute. Otherwise, use the annotations of the argument.
- Parameters:
argument- the argument to declaration (this will be a value in typeParamToArg)use- the use that is being replacedargumentIsInferred- whetherargumentis a type argument that the type checker inferred (true), as opposed to one the programmer wrote explicitly at the call site (false)- Returns:
- a deep copy of argument with the appropriate annotations applied
-