Interface ExprMirror

    • 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.
      • 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 the TypingContext 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>) and foo(Runnable), the expression foo(() -> new List<>()) must select the supplier overload, even before the invocation type of List<> 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 of ExprMirror 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