public final class MoreTypes
extends java.lang.Object
TypeMirror
instances.Modifier and Type | Class and Description |
---|---|
private static class |
MoreTypes.CastingTypeVisitor<T> |
private static class |
MoreTypes.ComparedElements |
private static class |
MoreTypes.EqualVisitorParam |
Modifier and Type | Field and Description |
---|---|
private static javax.lang.model.type.TypeVisitor<javax.lang.model.element.Element,java.lang.Void> |
AS_ELEMENT_VISITOR |
private static javax.lang.model.type.TypeVisitor<java.lang.Boolean,MoreTypes.EqualVisitorParam> |
EQUAL_VISITOR |
private static java.lang.reflect.Method |
GET_BOUNDS |
private static int |
HASH_MULTIPLIER |
private static int |
HASH_SEED |
private static javax.lang.model.type.TypeVisitor<java.lang.Integer,java.util.Set<javax.lang.model.element.Element>> |
HASH_VISITOR |
private static java.lang.Class<?> |
INTERSECTION_TYPE |
private static com.google.common.base.Equivalence<javax.lang.model.type.TypeMirror> |
TYPE_EQUIVALENCE |
Modifier | Constructor and Description |
---|---|
private |
MoreTypes() |
Modifier and Type | Method and Description |
---|---|
static javax.lang.model.type.ArrayType |
asArray(javax.lang.model.type.TypeMirror maybeArrayType)
Returns a
ArrayType if the TypeMirror represents a primitive array or
throws an IllegalArgumentException . |
static javax.lang.model.type.DeclaredType |
asDeclared(javax.lang.model.type.TypeMirror maybeDeclaredType)
Returns a
DeclaredType if the TypeMirror represents a declared type such
as a class, interface, union/compound, or enum or throws an IllegalArgumentException . |
static javax.lang.model.element.Element |
asElement(javax.lang.model.type.TypeMirror typeMirror)
An alternate implementation of
Types.asElement(javax.lang.model.type.TypeMirror) that does not require a Types
instance with the notable difference that it will throw IllegalArgumentException
instead of returning null if the TypeMirror can not be converted to an Element . |
static javax.lang.model.type.ErrorType |
asError(javax.lang.model.type.TypeMirror maybeErrorType)
Returns a
ExecutableType if the TypeMirror represents an executable type such
as may result from missing code, or bad compiles or throws an IllegalArgumentException . |
static javax.lang.model.type.ExecutableType |
asExecutable(javax.lang.model.type.TypeMirror maybeExecutableType)
Returns a
ExecutableType if the TypeMirror represents an executable type such
as a method, constructor, or initializer or throws an IllegalArgumentException . |
static javax.lang.model.type.TypeMirror |
asMemberOf(javax.lang.model.util.Types types,
javax.lang.model.type.DeclaredType container,
javax.lang.model.element.VariableElement variable)
Resolves a
VariableElement parameter to a method or constructor based on the given
container, or a member of a class. |
static javax.lang.model.type.NoType |
asNoType(javax.lang.model.type.TypeMirror maybeNoType)
Returns a
NoType if the TypeMirror represents an non-type such
as void, or package, etc. |
static javax.lang.model.type.NullType |
asNullType(javax.lang.model.type.TypeMirror maybeNullType)
Returns a
NullType if the TypeMirror represents the null type
or throws an IllegalArgumentException . |
static javax.lang.model.type.PrimitiveType |
asPrimitiveType(javax.lang.model.type.TypeMirror maybePrimitiveType)
Returns a
PrimitiveType if the TypeMirror represents a primitive type
or throws an IllegalArgumentException . |
static javax.lang.model.element.TypeElement |
asTypeElement(javax.lang.model.type.TypeMirror mirror) |
static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> |
asTypeElements(java.lang.Iterable<? extends javax.lang.model.type.TypeMirror> mirrors) |
static javax.lang.model.type.TypeVariable |
asTypeVariable(javax.lang.model.type.TypeMirror maybeTypeVariable)
Returns a
TypeVariable if the TypeMirror represents a type variable
or throws an IllegalArgumentException . |
static javax.lang.model.type.WildcardType |
asWildcard(javax.lang.model.type.WildcardType maybeWildcardType)
Returns a
WildcardType if the TypeMirror represents a wildcard type
or throws an IllegalArgumentException . |
private static boolean |
equal(javax.lang.model.type.TypeMirror a,
javax.lang.model.type.TypeMirror b,
java.util.Set<MoreTypes.ComparedElements> visiting) |
private static boolean |
equalIntersectionTypes(javax.lang.model.type.TypeMirror a,
javax.lang.model.type.TypeMirror b,
java.util.Set<MoreTypes.ComparedElements> visiting) |
private static boolean |
equalLists(java.util.List<? extends javax.lang.model.type.TypeMirror> a,
java.util.List<? extends javax.lang.model.type.TypeMirror> b,
java.util.Set<MoreTypes.ComparedElements> visiting) |
static com.google.common.base.Equivalence<javax.lang.model.type.TypeMirror> |
equivalence() |
private static int |
hash(javax.lang.model.type.TypeMirror mirror,
java.util.Set<javax.lang.model.element.Element> visiting) |
private static int |
hashList(java.util.List<? extends javax.lang.model.type.TypeMirror> mirrors,
java.util.Set<javax.lang.model.element.Element> visiting) |
private static boolean |
isIntersectionType(javax.lang.model.type.TypeMirror t) |
static boolean |
isType(javax.lang.model.type.TypeMirror type)
Returns true if the raw type underlying the given
TypeMirror represents a type that can
be referenced by a Class . |
static boolean |
isTypeOf(java.lang.Class<?> clazz,
javax.lang.model.type.TypeMirror type)
Returns true if the raw type underlying the given
TypeMirror represents the
same raw type as the given Class and throws an IllegalArgumentException if the
TypeMirror does not represent a type that can be referenced by a Class |
static com.google.common.base.Optional<javax.lang.model.type.DeclaredType> |
nonObjectSuperclass(javax.lang.model.util.Types types,
javax.lang.model.util.Elements elements,
javax.lang.model.type.DeclaredType type)
Returns the non-object superclass of the type with the proper type parameters.
|
static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> |
referencedTypes(javax.lang.model.type.TypeMirror type)
Returns the set of types that are referenced by the given
TypeMirror . |
private static final com.google.common.base.Equivalence<javax.lang.model.type.TypeMirror> TYPE_EQUIVALENCE
private static final javax.lang.model.type.TypeVisitor<java.lang.Boolean,MoreTypes.EqualVisitorParam> EQUAL_VISITOR
private static final java.lang.Class<?> INTERSECTION_TYPE
private static final java.lang.reflect.Method GET_BOUNDS
private static final int HASH_SEED
private static final int HASH_MULTIPLIER
private static final javax.lang.model.type.TypeVisitor<java.lang.Integer,java.util.Set<javax.lang.model.element.Element>> HASH_VISITOR
private static final javax.lang.model.type.TypeVisitor<javax.lang.model.element.Element,java.lang.Void> AS_ELEMENT_VISITOR
public static com.google.common.base.Equivalence<javax.lang.model.type.TypeMirror> equivalence()
private static boolean equal(javax.lang.model.type.TypeMirror a, javax.lang.model.type.TypeMirror b, java.util.Set<MoreTypes.ComparedElements> visiting)
private static boolean isIntersectionType(javax.lang.model.type.TypeMirror t)
private static boolean equalIntersectionTypes(javax.lang.model.type.TypeMirror a, javax.lang.model.type.TypeMirror b, java.util.Set<MoreTypes.ComparedElements> visiting)
private static boolean equalLists(java.util.List<? extends javax.lang.model.type.TypeMirror> a, java.util.List<? extends javax.lang.model.type.TypeMirror> b, java.util.Set<MoreTypes.ComparedElements> visiting)
private static int hashList(java.util.List<? extends javax.lang.model.type.TypeMirror> mirrors, java.util.Set<javax.lang.model.element.Element> visiting)
private static int hash(javax.lang.model.type.TypeMirror mirror, java.util.Set<javax.lang.model.element.Element> visiting)
public static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> referencedTypes(javax.lang.model.type.TypeMirror type)
TypeMirror
.public static javax.lang.model.element.Element asElement(javax.lang.model.type.TypeMirror typeMirror)
Types.asElement(javax.lang.model.type.TypeMirror)
that does not require a Types
instance with the notable difference that it will throw IllegalArgumentException
instead of returning null if the TypeMirror
can not be converted to an Element
.java.lang.NullPointerException
- if typeMirror
is null
java.lang.IllegalArgumentException
- if typeMirror
cannot be converted to an
Element
public static javax.lang.model.element.TypeElement asTypeElement(javax.lang.model.type.TypeMirror mirror)
public static com.google.common.collect.ImmutableSet<javax.lang.model.element.TypeElement> asTypeElements(java.lang.Iterable<? extends javax.lang.model.type.TypeMirror> mirrors)
public static javax.lang.model.type.ArrayType asArray(javax.lang.model.type.TypeMirror maybeArrayType)
ArrayType
if the TypeMirror
represents a primitive array or
throws an IllegalArgumentException
.public static javax.lang.model.type.DeclaredType asDeclared(javax.lang.model.type.TypeMirror maybeDeclaredType)
DeclaredType
if the TypeMirror
represents a declared type such
as a class, interface, union/compound, or enum or throws an IllegalArgumentException
.public static javax.lang.model.type.ErrorType asError(javax.lang.model.type.TypeMirror maybeErrorType)
ExecutableType
if the TypeMirror
represents an executable type such
as may result from missing code, or bad compiles or throws an IllegalArgumentException
.public static javax.lang.model.type.ExecutableType asExecutable(javax.lang.model.type.TypeMirror maybeExecutableType)
ExecutableType
if the TypeMirror
represents an executable type such
as a method, constructor, or initializer or throws an IllegalArgumentException
.public static javax.lang.model.type.NoType asNoType(javax.lang.model.type.TypeMirror maybeNoType)
NoType
if the TypeMirror
represents an non-type such
as void, or package, etc. or throws an IllegalArgumentException
.public static javax.lang.model.type.NullType asNullType(javax.lang.model.type.TypeMirror maybeNullType)
NullType
if the TypeMirror
represents the null type
or throws an IllegalArgumentException
.public static javax.lang.model.type.PrimitiveType asPrimitiveType(javax.lang.model.type.TypeMirror maybePrimitiveType)
PrimitiveType
if the TypeMirror
represents a primitive type
or throws an IllegalArgumentException
.public static javax.lang.model.type.TypeVariable asTypeVariable(javax.lang.model.type.TypeMirror maybeTypeVariable)
TypeVariable
if the TypeMirror
represents a type variable
or throws an IllegalArgumentException
.public static javax.lang.model.type.WildcardType asWildcard(javax.lang.model.type.WildcardType maybeWildcardType)
WildcardType
if the TypeMirror
represents a wildcard type
or throws an IllegalArgumentException
.public static boolean isType(javax.lang.model.type.TypeMirror type)
TypeMirror
represents a type that can
be referenced by a Class
. If this returns true, then isTypeOf(java.lang.Class<?>, javax.lang.model.type.TypeMirror)
is guaranteed to
not throw.public static boolean isTypeOf(java.lang.Class<?> clazz, javax.lang.model.type.TypeMirror type)
TypeMirror
represents the
same raw type as the given Class
and throws an IllegalArgumentException if the
TypeMirror
does not represent a type that can be referenced by a Class
public static com.google.common.base.Optional<javax.lang.model.type.DeclaredType> nonObjectSuperclass(javax.lang.model.util.Types types, javax.lang.model.util.Elements elements, javax.lang.model.type.DeclaredType type)
public static javax.lang.model.type.TypeMirror asMemberOf(javax.lang.model.util.Types types, javax.lang.model.type.DeclaredType container, javax.lang.model.element.VariableElement variable)
VariableElement
parameter to a method or constructor based on the given
container, or a member of a class. For parameters to a method or constructor, the variable's
enclosing element must be a supertype of the container type. For example, given a
container
of type Set<String>
, and a variable corresponding to the E e
parameter in the Set.add(E e)
method, this will return a TypeMirror for String
.