Interface Type

All Known Subinterfaces:
Type.ArrayType

public interface Type
Interface to access resolved type of an expression or a Type.
  • Method Details

    • is

      boolean is(String fullyQualifiedName)
      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

      boolean isSubtypeOf(String fullyQualifiedName)
      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

      boolean isSubtypeOf(Type superType)
      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

      boolean isPrimitive(Type.Primitives primitive)
      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

      @Nullable Type primitiveWrapperType()
      Returns the type of the primitive wrapper
         Type type;
         Type primitiveWrapperType = type.primitiveWrapperType();
      
      Returns:
      the type of the primitive wrapper, as Type
    • primitiveType

      @Nullable Type primitiveType()
      Returns the type of the primitive
         Type type;
         Type primitiveType = type.primitiveType();
      
      Returns:
      the type of the primitive, as Type
    • isNullType

      boolean isNullType()
      Returns whether this type is the null type
         Type type;
         type.isNullType();
      
      Returns:
      true if it is a null type
    • isTypeVar

      boolean isTypeVar()
      Returns whether this type represents a type variable
         Type type;
         type.isTypeVar();
      
      Returns:
      true if this is a type variable
    • isRawType

      boolean isRawType()
      Check if this type is a raw type
         Type type;
         type.isRawType();
      
      Returns:
      true if it is a raw type
    • declaringType

      Type declaringType()
      Returns the declaring type of this type
         Type 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

      String fullyQualifiedName()
      Fully qualified name of the type.
      Returns:
      complete name of type.
    • name

      String name()
      simple name of the type.
      Returns:
      simple name of type.
    • symbol

      Symbol of this type.
      Returns:
      the symbol declaring this type.
    • erasure

      Type erasure()
      Erasure of this type.
      Returns:
      erased type.
    • 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

      List<Type> typeArguments()
      The arguments of a parameterized type, as a parameterization of a generic type.
      Returns:
      the ordered list of type arguments. Returns an empty lists for non-parameterized types.
      Since:
      SonarJava 6.3