Class ExprContext


  • public abstract class ExprContext
    extends Object
    Context of an expression. This determines the target type of poly expressions, which is necessary for overload resolution. It also determines what kinds of conversions apply to the value to make it compatible with the context.
    • Method Detail

      • getTargetType

        public abstract @Nullable JTypeMirror getTargetType()
        Returns the target type, or null if there is none.
      • acceptsType

        public boolean acceptsType​(@NonNull JTypeMirror type)
        Returns true if the given type is compatible with this context implicitly (without cast). Conversions may occur to make this possible. What conversions may occur depends on the kind of this context.

        By convention, any type is compatible with a missing context.

        Parameters:
        type - A type which is checked against the target type
      • isMissing

        public boolean isMissing()
        Returns true if this context does not provide any target type. This is then a sentinel object.
      • getInvocNodeIfInvocContext

        public @Nullable InvocationNode getInvocNodeIfInvocContext()
      • getToplevelCtx

        public @NonNull ExprContext getToplevelCtx()
      • getPolyTargetType

        public @Nullable JTypeMirror getPolyTargetType​(boolean lambdaOrMethodRef)
        Returns the target type bestowed by this context ON A POLY EXPRESSION.
        Parameters:
        lambdaOrMethodRef - Whether the poly to be considered is a lambda or method ref. In this case, cast contexts can give a target type.
      • getMissingInstance

        public static net.sourceforge.pmd.lang.java.types.ast.internal.RegularCtx getMissingInstance()
        Returns an ExprContext instance which represents a missing context. Use isMissing() instead of testing for equality.