Package com.google.auto.common
Class MoreTypes
java.lang.Object
com.google.auto.common.MoreTypes
Utilities related to
TypeMirror instances.- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final classprivate static classprivate static classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final classprivate static final class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ArrayTypeasArray(TypeMirror maybeArrayType) Returns aArrayTypeif theTypeMirrorrepresents a primitive array or throws anIllegalArgumentException.static DeclaredTypeasDeclared(TypeMirror maybeDeclaredType) Returns aDeclaredTypeif theTypeMirrorrepresents a declared type such as a class, interface, union/compound, or enum or throws anIllegalArgumentException.static ElementasElement(TypeMirror typeMirror) An alternate implementation ofTypes.asElement(javax.lang.model.type.TypeMirror)that does not require aTypesinstance with the notable difference that it will throwIllegalArgumentExceptioninstead of returning null if theTypeMirrorcan not be converted to anElement.static ErrorTypeasError(TypeMirror maybeErrorType) Returns aExecutableTypeif theTypeMirrorrepresents an executable type such as may result from missing code, or bad compiles or throws anIllegalArgumentException.static ExecutableTypeasExecutable(TypeMirror maybeExecutableType) Returns aExecutableTypeif theTypeMirrorrepresents an executable type such as a method, constructor, or initializer or throws anIllegalArgumentException.static TypeMirrorasMemberOf(Types types, DeclaredType container, VariableElement variable) Resolves aVariableElementparameter to a method or constructor based on the given container, or a member of a class.static NoTypeasNoType(TypeMirror maybeNoType) Returns aNoTypeif theTypeMirrorrepresents an non-type such as void, or package, etc.static NullTypeasNullType(TypeMirror maybeNullType) Returns aNullTypeif theTypeMirrorrepresents the null type or throws anIllegalArgumentException.static PrimitiveTypeasPrimitiveType(TypeMirror maybePrimitiveType) Returns aPrimitiveTypeif theTypeMirrorrepresents a primitive type or throws anIllegalArgumentException.static TypeElementasTypeElement(TypeMirror mirror) static com.google.common.collect.ImmutableSet<TypeElement> asTypeElements(Iterable<? extends TypeMirror> mirrors) static TypeVariableasTypeVariable(TypeMirror maybeTypeVariable) Returns aTypeVariableif theTypeMirrorrepresents a type variable or throws anIllegalArgumentException.static WildcardTypeasWildcard(TypeMirror maybeWildcardType) Returns aWildcardTypeif theTypeMirrorrepresents a wildcard type or throws anIllegalArgumentException.private static TypeMirrorReturns the type of the innermost enclosing instance, or null if there is none.private static booleanequal(TypeMirror a, TypeMirror b, Set<MoreTypes.ComparedElements> visiting) private static booleanequalIntersectionTypes(TypeMirror a, TypeMirror b, Set<MoreTypes.ComparedElements> visiting) private static booleanequalLists(List<? extends TypeMirror> a, List<? extends TypeMirror> b, Set<MoreTypes.ComparedElements> visiting) static com.google.common.base.Equivalence<TypeMirror> private static inthash(TypeMirror mirror, Set<Element> visiting) private static inthashList(List<? extends TypeMirror> mirrors, Set<Element> visiting) private static booleanstatic booleanisType(TypeMirror type) Returns true if the raw type underlying the givenTypeMirrorrepresents a type that can be referenced by aClass.static booleanisTypeOf(Class<?> clazz, TypeMirror type) Returns true if the raw type underlying the givenTypeMirrorrepresents the same raw type as the givenClassand throws an IllegalArgumentException if theTypeMirrordoes not represent a type that can be referenced by aClassstatic com.google.common.base.Optional<DeclaredType> nonObjectSuperclass(Types types, Elements elements, DeclaredType type) Returns the non-object superclass of the type with the proper type parameters.static com.google.common.collect.ImmutableSet<TypeElement> referencedTypes(TypeMirror type) Returns the set of types that are referenced by the givenTypeMirror.
-
Field Details
-
INTERSECTION_TYPE
-
GET_BOUNDS
-
HASH_SEED
private static final int HASH_SEED- See Also:
-
HASH_MULTIPLIER
private static final int HASH_MULTIPLIER- See Also:
-
-
Constructor Details
-
MoreTypes
private MoreTypes()
-
-
Method Details
-
equivalence
-
equal
-
enclosingType
Returns the type of the innermost enclosing instance, or null if there is none. This is the same asDeclaredType.getEnclosingType()except that it returns null rather than NoType for a static type. We need this because of this bug whereby the Eclipse compiler returns a value for static classes that is not NoType. -
isIntersectionType
-
equalIntersectionTypes
private static boolean equalIntersectionTypes(TypeMirror a, TypeMirror b, Set<MoreTypes.ComparedElements> visiting) -
equalLists
private static boolean equalLists(List<? extends TypeMirror> a, List<? extends TypeMirror> b, Set<MoreTypes.ComparedElements> visiting) -
hashList
-
hash
-
referencedTypes
Returns the set of types that are referenced by the givenTypeMirror. -
asElement
An alternate implementation ofTypes.asElement(javax.lang.model.type.TypeMirror)that does not require aTypesinstance with the notable difference that it will throwIllegalArgumentExceptioninstead of returning null if theTypeMirrorcan not be converted to anElement.- Throws:
NullPointerException- iftypeMirrorisnullIllegalArgumentException- iftypeMirrorcannot be converted to anElement
-
asTypeElement
-
asTypeElements
public static com.google.common.collect.ImmutableSet<TypeElement> asTypeElements(Iterable<? extends TypeMirror> mirrors) -
asArray
Returns aArrayTypeif theTypeMirrorrepresents a primitive array or throws anIllegalArgumentException. -
asDeclared
Returns aDeclaredTypeif theTypeMirrorrepresents a declared type such as a class, interface, union/compound, or enum or throws anIllegalArgumentException. -
asError
Returns aExecutableTypeif theTypeMirrorrepresents an executable type such as may result from missing code, or bad compiles or throws anIllegalArgumentException. -
asExecutable
Returns aExecutableTypeif theTypeMirrorrepresents an executable type such as a method, constructor, or initializer or throws anIllegalArgumentException. -
asNoType
Returns aNoTypeif theTypeMirrorrepresents an non-type such as void, or package, etc. or throws anIllegalArgumentException. -
asNullType
Returns aNullTypeif theTypeMirrorrepresents the null type or throws anIllegalArgumentException. -
asPrimitiveType
Returns aPrimitiveTypeif theTypeMirrorrepresents a primitive type or throws anIllegalArgumentException. -
asTypeVariable
Returns aTypeVariableif theTypeMirrorrepresents a type variable or throws anIllegalArgumentException. -
asWildcard
Returns aWildcardTypeif theTypeMirrorrepresents a wildcard type or throws anIllegalArgumentException. -
isType
Returns true if the raw type underlying the givenTypeMirrorrepresents a type that can be referenced by aClass. If this returns true, thenisTypeOf(java.lang.Class<?>, javax.lang.model.type.TypeMirror)is guaranteed to not throw. -
isTypeOf
Returns true if the raw type underlying the givenTypeMirrorrepresents the same raw type as the givenClassand throws an IllegalArgumentException if theTypeMirrordoes not represent a type that can be referenced by aClass -
nonObjectSuperclass
public static com.google.common.base.Optional<DeclaredType> nonObjectSuperclass(Types types, Elements elements, DeclaredType type) Returns the non-object superclass of the type with the proper type parameters. An absent Optional is returned if there is no non-Object superclass. -
asMemberOf
Resolves aVariableElementparameter 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 acontainerof typeSet<String>, and a variable corresponding to theE eparameter in theSet.add(E e)method, this will return a TypeMirror forString.
-