Class Java8InferenceContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordWhere an implicitly typed lambda parameter's type comes from: the target type of the lambda that declares it, and the parameter's index in the lambda's parameter list. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal DeclaredTypeThe type of class that encloses the top level expression whose type arguments are inferred.final ProcessingEnvironmentjavax.annotation.processing.ProcessingEnvironmentfinal TypeMirrorTypeMirror for java.lang.Error.final InvocationTypeInferenceInvocation type inference object.final InferenceFactoryThe inference factory.Maps each implicitly typed lambda parameter encountered by this inference problem to the information needed to compute its type.final Set<VariableElement> There's no way to tell if an element is a parameter of a lambda, so keep track of them.final Map<ExpressionTree, Theta> Store previously created type variable to inference variable maps as a map from invocation expression to Theta.final Typesjavax.lang.model.util.Typesfinal ProperTypeProperType for java.lang.Object.final TypeMirrorTypeMirror for java.lang.RuntimeException.final AnnotatedTypeFactoryThe annotated type factory.final com.sun.tools.javac.code.Typescom.sun.tools.javac.code.Types -
Constructor Summary
ConstructorsConstructorDescriptionJava8InferenceContext(AnnotatedTypeFactory factory, TreePath pathToExpression, InvocationTypeInference inference) Creates a context. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLambdaParamTargets(List<? extends VariableTree> parameters, AbstractType lambdaTargetType) Records where each parameter of an implicitly typed lambda gets its type from.voidaddLambdaParms(List<? extends VariableTree> parameters) Adds the parameters to the list of trees that are lambda parameters.intReturns the next number to use as the id for a capture variable.intReturns the next number to use as the id for a qualifier variable.intReturns the next number to use as the id for a non-capture variable.Returns the path to the expression whose type arguments are inferred.booleanisLambdaParam(ExpressionTree expression) Returns true if theexpressionis a lambda parameter.voidsetPathToExpression(TreePath pathToExpression) Sets the path to the expression whose type arguments are inferred.
-
Field Details
-
env
javax.annotation.processing.ProcessingEnvironment -
object
ProperType for java.lang.Object. -
inference
Invocation type inference object. -
types
public final com.sun.tools.javac.code.Types typescom.sun.tools.javac.code.Types -
modelTypes
javax.lang.model.util.Types -
enclosingType
The type of class that encloses the top level expression whose type arguments are inferred. -
maps
Store previously created type variable to inference variable maps as a map from invocation expression to Theta. -
error
TypeMirror for java.lang.Error. -
runtimeException
TypeMirror for java.lang.RuntimeException. -
inferenceTypeFactory
The inference factory. -
typeFactory
The annotated type factory. -
lambdaParms
There's no way to tell if an element is a parameter of a lambda, so keep track of them. -
lambdaParamTargets
Maps each implicitly typed lambda parameter encountered by this inference problem to the information needed to compute its type.- See Also:
-
-
Constructor Details
-
Java8InferenceContext
public Java8InferenceContext(AnnotatedTypeFactory factory, TreePath pathToExpression, InvocationTypeInference inference) Creates a context.- Parameters:
factory- type factorypathToExpression- path to the expression whose type arguments are inferredinference- inference object
-
-
Method Details
-
addLambdaParamTargets
public void addLambdaParamTargets(List<? extends VariableTree> parameters, AbstractType lambdaTargetType) Records where each parameter of an implicitly typed lambda gets its type from.- Parameters:
parameters- the formal parameters of an implicitly typed lambdalambdaTargetType- the target type of that lambda
-
getPathToExpression
Returns the path to the expression whose type arguments are inferred.- Returns:
- the path to the expression whose type arguments are inferred
-
setPathToExpression
Sets the path to the expression whose type arguments are inferred.This method exists because inference for an outer invocation does not always instantiate the type variables of a method reference that appears within one of its arguments. (The method reference need not be the argument itself; it might be nested, as
A::mis infoo(flag ? A::m : B::m).) In that case, inference is run a second time, on the method reference itself, in this same context: the variables and maps that the first run created are still needed, but the target type (seeInferenceFactory.getTargetType()) must now be computed with respect to the method reference rather than the outer invocation. Calling this method is what makes that happen, so its effect depends on when it is called relative to the two inference runs.- Parameters:
pathToExpression- the path to the expression whose type arguments are inferred
-
getNextVariableId
public int getNextVariableId()Returns the next number to use as the id for a non-capture variable. This id is only unique for this inference problem.- Returns:
- the next number to use as the id for a non-capture variable
-
getNextCaptureVariableId
public int getNextCaptureVariableId()Returns the next number to use as the id for a capture variable. This id is only unique for this inference problem.- Returns:
- the next number to use as the id for a capture variable
-
getNextQualifierVariableId
public int getNextQualifierVariableId()Returns the next number to use as the id for a qualifier variable. This id is only unique for this inference problem.- Returns:
- the next number to use as the id for a qualifier variable
-
addLambdaParms
Adds the parameters to the list of trees that are lambda parameters.There's no way to tell if a tree is a parameter of a lambda, so keep track of them.
- Parameters:
parameters- list of lambda parameters
-
isLambdaParam
Returns true if theexpressionis a lambda parameter.- Parameters:
expression- an expression- Returns:
- true if the
expressionis a lambda parameter
-