Class ExprContext

java.lang.Object
net.sourceforge.pmd.lang.java.types.ast.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.
  • Field Details

  • Constructor Details

  • Method Details

    • 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.
    • getKind

      public ExprContext.ExprContextKind getKind()
      Returns the kind of context this is.
    • 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.
    • hasKind

      public boolean hasKind(ExprContext.ExprContextKind kind)