Interface JTypeVar

  • All Superinterfaces:
    JTypeMirror, JTypeVisitable, SubstVar

    public interface JTypeVar
    extends SubstVar
    The type of a type variable. There are two sorts of those:

    Type variables may appear in their own bound (F-bound), and we have to make sure all those occurrences are represented by the same instance. We have to pay attention to cycles in our algos too.

    Type variables do not, in general, use reference identity. Use equals to compare them.

    • Method Detail

      • getSymbol

        @Nullable JTypeParameterSymbol getSymbol()
        Returns the reflected type variable this instance represents, or null if this is a capture variable.
        Specified by:
        getSymbol in interface JTypeMirror
      • getName

        @NonNull String getName()
        Returns the name of this variable, which may something autogenerated if this is a captured variable. This is not necessarily an identifier.
      • getUpperBound

        @NonNull JTypeMirror getUpperBound()
        Gets the upper bound. This defaults to Object, and may be an intersection type.

        Note that the upper bound of a capture variable is not necessarily the upper bound of the captured wildcard. The declared bound of each variable is glbed with the declared bound of the wildcard. For example, given class Foo<T extends List<T>>, then Foo<?> will have TypeSystem.UNBOUNDED_WILD as a type argument. But the capture of Foo<?> will look like Foo<capture#.. of ?>, where the capture var's upper bound is actually List<?>.

      • getLowerBound

        @NonNull JTypeMirror getLowerBound()
        Gets the lower bound. TypeSystem.NULL_TYPE conventionally represents the bottom type (a trivial lower bound).
      • isCaptured

        boolean isCaptured()
        Returns true if this is a capture variable, ie this variable originates from the capture of a wildcard type argument. Capture variables use reference identity.
      • isCaptureOf

        boolean isCaptureOf​(JWildcardType wildcard)
        Returns true if this is a capture variable for the given wildcard.
      • getCapturedOrigin

        @Nullable JWildcardType getCapturedOrigin()
        Returns the original wildcard, if this is a capture variable. Otherwise returns null.
      • acceptVisitor

        default <T,​P> T acceptVisitor​(JTypeVisitor<T,​P> visitor,
                                            P p)
        Description copied from interface: JTypeVisitable
        Accept a type visitor, dispatching on this object's runtime type to the correct method of the visitor.
        Specified by:
        acceptVisitor in interface JTypeVisitable
        Type Parameters:
        T - Type of result of the visitor
        P - Type of data of the visitor
      • withUpperBound

        JTypeVar withUpperBound​(@NonNull JTypeMirror newUB)
        Return a new type variable with the same underlying symbol or capture variable, but the upper bound is now the given type.
        Parameters:
        newUB - New upper bound
        Returns:
        a new tvar
      • withAnnotations

        JTypeVar withAnnotations​(org.pcollections.PSet<SymbolicValue.SymAnnot> newTypeAnnots)
        Description copied from interface: JTypeMirror
        Returns a type mirror that is equal to this instance but has different type annotations. Note that some types ignore this method and return themselves without changing. Eg the null type cannot be annotated.
        Specified by:
        withAnnotations in interface JTypeMirror
        Parameters:
        newTypeAnnots - New type annotations (not null)
        Returns:
        A new type, maybe this one
      • streamMethods

        default Stream<JMethodSig> streamMethods​(Predicate<? super JMethodSymbol> prefilter)
        Description copied from interface: JTypeMirror
        Returns a stream of method signatures declared in and inherited by this type. Method signatures are created on-demand by this method, they're not reused between calls. This stream does not include constructors.

        Note: streams are a bit impractical when it comes to configuring the filter. Possibly a specialized API should be introduced. We need to support the use cases of the symbol table, ie filter by name + accessibility + staticity, and also possibly use cases for rules, like getting a method from a known signature. See also JClassType.getDeclaredMethod(JExecutableSymbol), which looks like this. Unifying this API would be nice.

        Specified by:
        streamMethods in interface JTypeMirror
        Parameters:
        prefilter - Filter selecting symbols for which a signature should be created and yielded by the stream