Package org.sonar.java.resolve
Class JavaType
- java.lang.Object
-
- org.sonar.java.resolve.JavaType
-
- All Implemented Interfaces:
Type
- Direct Known Subclasses:
ArrayJavaType,ClassJavaType,DeferredType,MethodJavaType,TypeVariableJavaType,WildCardType
public class JavaType extends Object implements Type
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.sonar.plugins.java.api.semantic.Type
Type.ArrayType, Type.Primitives
-
-
Field Summary
Fields Modifier and Type Field Description static intARRAYstatic intBOOLEANstatic intBOTstatic intBYTEstatic intCHARstatic intCLASSstatic intDEFERREDstatic intDOUBLEstatic intFLOATstatic intINTstatic intINTERSECTIONstatic intLONGstatic intMETHODstatic intPARAMETERIZEDstatic intSHORTstatic intTYPEVARstatic intUNKNOWNstatic intVOIDstatic intWILDCARD
-
Constructor Summary
Constructors Constructor Description JavaType(int tag, JavaSymbol.TypeJavaSymbol symbol)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<ClassJavaType>directSuperTypes()JavaTypeerasure()JLS8 4.6StringfullyQualifiedName()Fully qualified name of the type.JavaTypegetSuperType()JavaSymbol.TypeJavaSymbolgetSymbol()booleanis(String fullyQualifiedName)Check 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.booleanisNumerical()Check if this type is a primitive numerical type.booleanisParameterized()booleanisPrimitive()Check if this type is a primitive.booleanisPrimitive(Type.Primitives primitive)Check if this type is the given primitive.booleanisPrimitiveWrapper()booleanisSubtypeOf(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.booleanisTagged(int tag)booleanisUnknown()Check if this type has been resolved.booleanisVoid()Check if type is Void type.Stringname()simple name of the type.JavaTypeprimitiveType()JavaTypeprimitiveWrapperType()Symbol.TypeSymbolsymbol()Symbol of this type.StringtoString()
-
-
-
Field Detail
-
BYTE
public static final int BYTE
- See Also:
- Constant Field Values
-
CHAR
public static final int CHAR
- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT
- See Also:
- Constant Field Values
-
INT
public static final int INT
- See Also:
- Constant Field Values
-
LONG
public static final int LONG
- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
- See Also:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN
- See Also:
- Constant Field Values
-
VOID
public static final int VOID
- See Also:
- Constant Field Values
-
CLASS
public static final int CLASS
- See Also:
- Constant Field Values
-
ARRAY
public static final int ARRAY
- See Also:
- Constant Field Values
-
METHOD
public static final int METHOD
- See Also:
- Constant Field Values
-
BOT
public static final int BOT
- See Also:
- Constant Field Values
-
UNKNOWN
public static final int UNKNOWN
- See Also:
- Constant Field Values
-
TYPEVAR
public static final int TYPEVAR
- See Also:
- Constant Field Values
-
WILDCARD
public static final int WILDCARD
- See Also:
- Constant Field Values
-
DEFERRED
public static final int DEFERRED
- See Also:
- Constant Field Values
-
PARAMETERIZED
public static final int PARAMETERIZED
- See Also:
- Constant Field Values
-
INTERSECTION
public static final int INTERSECTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JavaType
public JavaType(int tag, JavaSymbol.TypeJavaSymbol symbol)
-
-
Method Detail
-
isTagged
public boolean isTagged(int tag)
-
isNumerical
public boolean isNumerical()
Description copied from interface:TypeCheck if this type is a primitive numerical type.- Specified by:
isNumericalin interfaceType- Returns:
- true if type is byte, char, short, int, long, float or double.
-
getSymbol
public JavaSymbol.TypeJavaSymbol getSymbol()
-
getSuperType
@CheckForNull public JavaType getSuperType()
-
directSuperTypes
public Set<ClassJavaType> directSuperTypes()
-
is
public boolean is(String fullyQualifiedName)
Description copied from interface:TypeCheck 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");
-
isSubtypeOf
public boolean isSubtypeOf(String fullyQualifiedName)
Description copied from interface:TypeCheck 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");- Specified by:
isSubtypeOfin interfaceType- 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
public boolean isSubtypeOf(Type superType)
Description copied from interface:TypeCheck whether a type is a subtype of another.This method will consider implemented interfaces as well as superclasses.
Type type, myOtherType; type.isSubtypeOf(myOtherType);
- Specified by:
isSubtypeOfin interfaceType- 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.
-
erasure
public JavaType erasure()
JLS8 4.6
-
isPrimitive
public boolean isPrimitive()
Description copied from interface:TypeCheck if this type is a primitive.- Specified by:
isPrimitivein interfaceType- Returns:
- true if this is a primitive type.
-
isPrimitive
public boolean isPrimitive(Type.Primitives primitive)
Description copied from interface:TypeCheck if this type is the given primitive.Type type; type.isPrimitive(Primitives.INT);
- Specified by:
isPrimitivein interfaceType- Parameters:
primitive- primitive type to be checked with.- Returns:
- true if this is the primitive type
-
isUnknown
public boolean isUnknown()
Description copied from interface:TypeCheck 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.
-
isPrimitiveWrapper
public boolean isPrimitiveWrapper()
-
isArray
public boolean isArray()
Description copied from interface:TypeCheck if this type is an array.
-
isParameterized
public boolean isParameterized()
-
isClass
public boolean isClass()
Description copied from interface:TypeCheck if this type is a class, an enum, an interface or an annotation.
-
isVoid
public boolean isVoid()
Description copied from interface:TypeCheck if type is Void type. This is used to check type of method invocation expressions.
-
fullyQualifiedName
public String fullyQualifiedName()
Description copied from interface:TypeFully qualified name of the type.- Specified by:
fullyQualifiedNamein interfaceType- Returns:
- complete name of type.
-
symbol
public Symbol.TypeSymbol symbol()
Description copied from interface:TypeSymbol of this type.
-
-