Interface ExprMirror
-
- All Known Subinterfaces:
ExprMirror.BranchingMirror
,ExprMirror.CtorInvocationMirror
,ExprMirror.FunctionalExprMirror
,ExprMirror.InvocationMirror
,ExprMirror.LambdaExprMirror
,ExprMirror.MethodRefMirror
,ExprMirror.PolyExprMirror
public interface ExprMirror
Adapter class to manipulate expressions. The framework ideally keeps focus on types and doesn't have a dependency on the AST. Only the impl package can have such dependencies.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ExprMirror.BranchingMirror
Mirrors a conditional or switch expression.static interface
ExprMirror.CtorInvocationMirror
An invocation mirror reflecting a constructor invocation expression.static interface
ExprMirror.FunctionalExprMirror
Mirror of some expression that targets a functional interface type: lambda or method reference.static interface
ExprMirror.InvocationMirror
Adapter over a method or constructor invocation expression.static interface
ExprMirror.LambdaExprMirror
Mirrors a lambda expression.static interface
ExprMirror.MethodRefMirror
Mirror of a method reference expression.static interface
ExprMirror.PolyExprMirror
static class
ExprMirror.TypeSpecies
A general category of types.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
finishStandaloneInference(@NonNull JTypeMirror standaloneType)
For a standalone expr, finish type inference by computing properties that are guarded by the type res lock.@Nullable JTypeMirror
getInferredType()
Return the value set in the last call tosetInferredType(JTypeMirror)
.JavaNode
getLocation()
Returns a node which is used as a location to report messages.default @NonNull ExprMirror.TypeSpecies
getStandaloneSpecies()
Returns the species that this expression produces.@Nullable JTypeMirror
getStandaloneType()
If this expression is of a standalone form, returns the type of the expression.TypingContext
getTypingContext()
Returns typing information for the lambdas parameters in scope in this expression and its subexpressions.boolean
isEquivalentToUnderlyingAst()
Returns true if this mirror and its subexpressions are equivalent to the underlying AST node.void
setInferredType(JTypeMirror mirror)
Set the type of the underlying ast node.
-
-
-
Method Detail
-
getLocation
JavaNode getLocation()
Returns a node which is used as a location to report messages. Do not use this any other way.
-
getStandaloneType
@Nullable JTypeMirror getStandaloneType()
If this expression is of a standalone form, returns the type of the expression. Otherwise returns null.Note that standalone types can directly be set on the type node.
- Returns:
- The type of the expression if it is standalone
-
finishStandaloneInference
default void finishStandaloneInference(@NonNull JTypeMirror standaloneType)
For a standalone expr, finish type inference by computing properties that are guarded by the type res lock. For instance for a standalone ctor call, the standalone type is trivially known (it's the type node). But we still need to do overload resolution.
-
setInferredType
void setInferredType(JTypeMirror mirror)
Set the type of the underlying ast node. Used when we need to find out the type of a poly to infer the type of another, that way, we don't repeat computation.
-
getInferredType
@Nullable JTypeMirror getInferredType()
Return the value set in the last call tosetInferredType(JTypeMirror)
.
-
getTypingContext
TypingContext getTypingContext()
Returns typing information for the lambdas parameters in scope in this expression and its subexpressions. When overload resolution involves lambdas, we might have to try several target types for each lambda. Each of those may give a different type to the lambda parameters, and hence, to every expression in the lambda body. These "tentative" typing are kept in theTypingContext
object and only committed to the AST for the overload that is selected in the end.
-
getStandaloneSpecies
default @NonNull ExprMirror.TypeSpecies getStandaloneSpecies()
Returns the species that this expression produces. The species may be known even if the expr is not standalone. For example a diamond constructor call is not standalone, but its species is obviously REFERENCE.This is used for specificity tests for lambdas. They use species because invocation needs to be done exactly once, and the actual type of the expression may differ depending on the selected overload. Eg given the signatures
<T>foo(Supplier<T>)
andfoo(Runnable)
, the expressionfoo(() -> new List<>())
must select the supplier overload, even before the invocation type ofList<>
is known. The overload selection compares the expected species of both function types (REFERENCE for Supplier, VOID for Runnable), and determines that the supplier is more appropriate.
-
isEquivalentToUnderlyingAst
boolean isEquivalentToUnderlyingAst()
Returns true if this mirror and its subexpressions are equivalent to the underlying AST node. This is only relevant when making mirrors that are not exactly equal to the AST node (eg, omitting explicit type arguments), in order to check if the transformation does not change the meaning of the program. It verifies that method and constructor calls are overload-selected to the same compile-time declaration, and that nested lambdas have the same type as in the AST.This mirror's state, as filled-in during type resolution by
Infer
using the various setters ofExprMirror
interfaces, is compared to the AST's corresponding state. Consequently, if this state is missing (meaning, that no overload resolution has been run using this mirror), the analysis cannot be performed and an exception is thrown.- Throws:
IllegalStateException
- If this mirror has not been used for overload resolution
-
-