Enum TypeOps.Convertibility
- java.lang.Object
-
- java.lang.Enum<TypeOps.Convertibility>
-
- net.sourceforge.pmd.lang.java.types.TypeOps.Convertibility
-
- All Implemented Interfaces:
Serializable
,Comparable<TypeOps.Convertibility>
- Enclosing class:
- TypeOps
public static enum TypeOps.Convertibility extends Enum<TypeOps.Convertibility>
A result for a convertibility check. This is a tiny generalization of a subtyping check.Primitive types are implicitly convertible to each other by widening primitive conversion. For reference types, subtyping implies convertibility (the conversion is technically called "widening reference conversion"). You can check those cases using:
t.isConvertibleTo(s).bySubtyping()
Unchecked conversion may go backwards from subtyping. For example,
List<String>
is a subtype of the raw typeList
, and as such is convertible to it by reference widening. ButList
may be "coerced" toList<String>
with an unchecked warning:t.isConvertibleTo(s).withUncheckedWarning()
If the parameterized type only has wildcard type arguments, then the conversion produces no warning.
t.isConvertibleTo(s) == UNCHECKED_NO_WARNING
Two types may be unconvertible:
t.isConvertibleTo(s).never()
the negation of which being
t.isConvertibleTo(s).somehow()
Note that this does not check for boxing or unboxing conversions, nor for narrowing conversions, which may happen through casts.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description NEVER
T is never implicitly convertible to S.SUBTYPING
T is a subtype of S (T <: S
).UNCHECKED_NO_WARNING
T <: |S|
andT </: S
, but S is parameterized with only unbounded wildcards.UNCHECKED_WARNING
T is not a subtype of S, but every time T is used in a context where an S is expected, unchecked conversion converts the T to an S with a mandated warning.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
bySubtyping()
True if this isSUBTYPING
.boolean
never()
Returns true if this isNEVER
.boolean
somehow()
Returns true if this is anything butNEVER
.static TypeOps.Convertibility
valueOf(String name)
Returns the enum constant of this type with the specified name.static TypeOps.Convertibility[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.boolean
withoutWarnings()
True if this isSUBTYPING
orUNCHECKED_NO_WARNING
.boolean
withUncheckedWarning()
True if this isUNCHECKED_WARNING
.
-
-
-
Enum Constant Detail
-
NEVER
public static final TypeOps.Convertibility NEVER
T is never implicitly convertible to S.
-
UNCHECKED_WARNING
public static final TypeOps.Convertibility UNCHECKED_WARNING
T is not a subtype of S, but every time T is used in a context where an S is expected, unchecked conversion converts the T to an S with a mandated warning. For example the raw typeClass
is convertible toClass<String>
with an unchecked warning.
-
UNCHECKED_NO_WARNING
public static final TypeOps.Convertibility UNCHECKED_NO_WARNING
T <: |S|
andT </: S
, but S is parameterized with only unbounded wildcards. This is a special case of unchecked conversion that produces no warning. We keep it distinct from subtyping to help some algorithms that require subtyping to be a partial order.For example,
List<String>
is a subtype of the rawCollection
, not a subtype ofCollection<?>
, but it is still convertible without warning.
-
SUBTYPING
public static final TypeOps.Convertibility SUBTYPING
T is a subtype of S (T <: S
). In particular, any type is a subtype of itself (T <: T
).For example,
int
can be widened tolong
, so we considerint <: long
.
-
-
Method Detail
-
values
public static TypeOps.Convertibility[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (TypeOps.Convertibility c : TypeOps.Convertibility.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static TypeOps.Convertibility valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
never
public boolean never()
Returns true if this isNEVER
.
-
somehow
public boolean somehow()
Returns true if this is anything butNEVER
.
-
bySubtyping
public boolean bySubtyping()
True if this isSUBTYPING
.
-
withUncheckedWarning
public boolean withUncheckedWarning()
True if this isUNCHECKED_WARNING
.
-
withoutWarnings
public boolean withoutWarnings()
True if this isSUBTYPING
orUNCHECKED_NO_WARNING
.
-
-