org.stjs.generator.javac
Class TypesUtils

java.lang.Object
  extended by org.stjs.generator.javac.TypesUtils

public final class TypesUtils
extends Object

A utility class that helps with TypeMirrors.


Method Summary
static boolean areSamePrimitiveTypes(TypeMirror left, TypeMirror right)
          Returns true iff the arguments are both the same primitive types.
static ArrayType createArrayType(Types types, TypeMirror componentType)
          Returns an ArrayType with elements of type componentType.
static Name getQualifiedName(DeclaredType type)
          Gets the fully qualified name for a provided type.
static boolean isBooleanType(TypeMirror type)
          Checks if the type represents a boolean type, that is either boolean (primitive type) or java.lang.Boolean.
static boolean isBoxedPrimitive(TypeMirror type)
           
static boolean isClass(TypeMirror type)
          Checks if the type represents a java.lang.Class declared type.
static boolean isDeclaredOfName(TypeMirror type, CharSequence qualifiedName)
          Check if the type represent a declared type of the given qualified name
static boolean isFloating(TypeMirror type)
          Returns true iff the argument is a floating point type.
static boolean isIntegral(TypeMirror type)
          Returns true iff the argument is an integral type.
static boolean isNumeric(TypeMirror type)
          Returns true iff the argument is a primitive numeric type.
static boolean isObject(TypeMirror type)
          Checks if the type represents a java.lang.Object declared type.
static boolean isPrimitive(TypeMirror type)
          Returns true iff the argument is a primitive type.
static boolean isString(TypeMirror type)
          Checks if the type represents a java.lang.String declared type.
static boolean isThrowable(TypeMirror type)
           
static TypeMirror typeFromClass(Types types, Elements elements, Class<?> clazz)
          Returns the TypeMirror for a given Class.
static TypeMirror upperBound(TypeMirror type)
          If the argument is a bounded TypeVariable or WildcardType, return its non-variable, non-wildcard upper bound.
static TypeKind widenedNumericType(TypeMirror left, TypeMirror right)
          Returns the widened numeric type for an arithmetic operation performed on a value of the left type and the right type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getQualifiedName

public static Name getQualifiedName(DeclaredType type)
Gets the fully qualified name for a provided type. It returns an empty name if type is an anonymous type.

Parameters:
type - the declared type
Returns:
the name corresponding to that type

isObject

public static boolean isObject(TypeMirror type)
Checks if the type represents a java.lang.Object declared type.

Parameters:
type - the type
Returns:
true iff type represents java.lang.Object

isClass

public static boolean isClass(TypeMirror type)
Checks if the type represents a java.lang.Class declared type.

Parameters:
type - the type
Returns:
true iff type represents java.lang.Class

isString

public static boolean isString(TypeMirror type)
Checks if the type represents a java.lang.String declared type. TODO: it would be cleaner to use String.class.getCanonicalName(), but the two existing methods above don't do that, I guess for performance reasons.

Parameters:
type - the type
Returns:
true iff type represents java.lang.String

isBooleanType

public static boolean isBooleanType(TypeMirror type)
Checks if the type represents a boolean type, that is either boolean (primitive type) or java.lang.Boolean.

Parameters:
type - the type to test
Returns:
true iff type represents a boolean type

isDeclaredOfName

public static boolean isDeclaredOfName(TypeMirror type,
                                       CharSequence qualifiedName)
Check if the type represent a declared type of the given qualified name

Parameters:
type - the type
Returns:
type iff type represents a declared type of the qualified name

isBoxedPrimitive

public static boolean isBoxedPrimitive(TypeMirror type)

isThrowable

public static boolean isThrowable(TypeMirror type)
Returns:
type represents a Throwable type (e.g. Exception, Error)

isPrimitive

public static boolean isPrimitive(TypeMirror type)
Returns true iff the argument is a primitive type.

Returns:
whether the argument is a primitive type

areSamePrimitiveTypes

public static boolean areSamePrimitiveTypes(TypeMirror left,
                                            TypeMirror right)
Returns true iff the arguments are both the same primitive types.

Returns:
whether the arguments are the same primitive types

isNumeric

public static boolean isNumeric(TypeMirror type)
Returns true iff the argument is a primitive numeric type.

Returns:
whether the argument is a primitive numeric type

isIntegral

public static boolean isIntegral(TypeMirror type)
Returns true iff the argument is an integral type.

Returns:
whether the argument is an integral type

isFloating

public static boolean isFloating(TypeMirror type)
Returns true iff the argument is a floating point type.

Returns:
whether the argument is a floating point type

widenedNumericType

public static TypeKind widenedNumericType(TypeMirror left,
                                          TypeMirror right)
Returns the widened numeric type for an arithmetic operation performed on a value of the left type and the right type. Defined in JLS 5.6.2. We return a TypeKind because creating a TypeMirror requires a Types object from the ProcessingEnvironment.

Returns:
the result of widening numeric conversion, or NONE when the conversion cannot be performed

upperBound

public static TypeMirror upperBound(TypeMirror type)
If the argument is a bounded TypeVariable or WildcardType, return its non-variable, non-wildcard upper bound. Otherwise, return the type itself.

Parameters:
type - a type
Returns:
the non-variable, non-wildcard upper bound of a type, if it has one, or itself if it has no bounds

typeFromClass

public static TypeMirror typeFromClass(Types types,
                                       Elements elements,
                                       Class<?> clazz)
Returns the TypeMirror for a given Class.


createArrayType

public static ArrayType createArrayType(Types types,
                                        TypeMirror componentType)
Returns an ArrayType with elements of type componentType.



Copyright © 2014. All Rights Reserved.