Interface Type
- All Known Subinterfaces:
Type.ArrayType
public interface Type
Interface to access resolved type of an expression or a Type.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceType for arrays.static enumPrimitive java types. -
Method Summary
Modifier and TypeMethodDescriptionReturns the declaring type of this typeerasure()Erasure of this type.Fully qualified name of the type.booleanCheck whether a type is the one designed by the fully qualified name.booleanisArray()Check if this type is an array.booleanisClass()Check if this type is a class, an enum, an interface or an annotation.booleanReturns whether this type is the null typebooleanCheck if this type is a primitive numerical type.booleanCheck if the current type is a parameterized type or not.booleanCheck if this type is a primitive.booleanisPrimitive(Type.Primitives primitive) Check if this type is the given primitive.booleanCheck if this type is a primitive wrapper.booleanCheck if this type is a raw typebooleanisSubtypeOf(String fullyQualifiedName) Check whether a type is a subtype of the one designed by the fully qualified name.booleanisSubtypeOf(Type superType) Check whether a type is a subtype of another.booleanReturns whether this type represents a type variablebooleanCheck if this type has been resolved.booleanisVoid()Check if type is Void type.name()simple name of the type.Returns the type of the primitiveReturns the type of the primitive wrappersymbol()Symbol of this type.The arguments of a parameterized type, as a parameterization of a generic type.
-
Method Details
-
is
Check whether a type is the one designed by the fully qualified name.Type type; type.is("int"); type.is("int[]"); type.is("java.lang.String[]"); type.is("java.lang.Object");- Parameters:
fullyQualifiedName- fully qualified name to check. Use "[]" for arrays and the simple name for primitive type ("int", "byte"...).- Returns:
- true if the type is the one looked for. false otherwise.
-
isSubtypeOf
Check whether a type is a subtype of the one designed by the fully qualified name.This method will consider implemented interfaces as well as superclasses.
Type type; type.isSubtypeOf("Object[]"); type.isSubtypeOf("org.mypackage.MyClass"); type.isSubtypeOf("org.mypackage.MyInterface"); type.isSubtypeOf("java.lang.Object");- Parameters:
fullyQualifiedName- fully qualified name to check in the type hierarchy. Use "[]" for arrays.- Returns:
- true if the type is the one passed in parameter or have this type in its hierarchy. false otherwise.
-
isSubtypeOf
Check whether a type is a subtype of another.This method will consider implemented interfaces as well as superclasses.
Type type, myOtherType; type.isSubtypeOf(myOtherType);
- Parameters:
superType- instance of a potential superType.- Returns:
- true if types are equivalent or if the one passed in parameter is in the hierarchy. false otherwise.
-
isArray
boolean isArray()Check if this type is an array.- Returns:
- true if this is an array.
-
isClass
boolean isClass()Check if this type is a class, an enum, an interface or an annotation.- Returns:
- true if this is a class, enum, interface or annotation.
-
isVoid
boolean isVoid()Check if type is Void type. This is used to check type of method invocation expressions.- Returns:
- true if the type is void.
-
isPrimitive
boolean isPrimitive()Check if this type is a primitive.- Returns:
- true if this is a primitive type.
-
isPrimitive
Check if this type is the given primitive.Type type; type.isPrimitive(Primitives.INT);
- Parameters:
primitive- primitive type to be checked with.- Returns:
- true if this is the primitive type
-
isPrimitiveWrapper
boolean isPrimitiveWrapper()Check if this type is a primitive wrapper.Type type; type.isPrimitiveWrapper();
- Returns:
- true if this is a primitive wrapper
-
primitiveWrapperType
Returns the type of the primitive wrapperType type; Type primitiveWrapperType = type.primitiveWrapperType();
- Returns:
- the type of the primitive wrapper, as Type
-
primitiveType
Returns the type of the primitiveType type; Type primitiveType = type.primitiveType();
- Returns:
- the type of the primitive, as Type
-
isNullType
boolean isNullType()Returns whether this type is the null typeType type; type.isNullType();
- Returns:
- true if it is a null type
-
isTypeVar
boolean isTypeVar()Returns whether this type represents a type variableType type; type.isTypeVar();
- Returns:
- true if this is a type variable
-
isRawType
boolean isRawType()Check if this type is a raw typeType type; type.isRawType();
- Returns:
- true if it is a raw type
-
declaringType
Type declaringType()Returns the declaring type of this typeType type; Type declaringType = type.declaringType();
- Returns:
- the declaring type of this, as Type
-
isUnknown
boolean isUnknown()Check if this type has been resolved. Type can be unknown in incomplete part of Semantic Analysis or when bytecode for a type is not provided and a method cannot be resolved.- Returns:
- true if type has not been resolved by semantic analysis.
-
isNumerical
boolean isNumerical()Check if this type is a primitive numerical type.- Returns:
- true if type is byte, char, short, int, long, float or double.
-
fullyQualifiedName
-
name
-
symbol
-
erasure
-
isParameterized
boolean isParameterized()Check if the current type is a parameterized type or not.- Returns:
- true in case of Generic and Parameterized types
- Since:
- SonarJava 6.3
-
typeArguments
-