public final class Util extends Object
Modifier and Type | Method and Description |
---|---|
static void |
fillAllSuperInterfaces(Types types,
TypeMirror type,
List<TypeMirror> result) |
static void |
fillAllSuperTypes(Types types,
TypeMirror type,
List<TypeMirror> result)
Similar to
getAllSuperTypes(javax.lang.model.util.Types, javax.lang.model.type.TypeMirror) but avoids
instantiation of a new list. |
static TypeElement |
findTypeByBinaryName(Elements elements,
String binaryName)
Tries to find a type element using the provided Elements helper given its binary name.
|
static List<TypeMirror> |
getAllSuperClasses(Types types,
TypeMirror type)
Returns all the super classes of given type.
|
static List<TypeMirror> |
getAllSuperInterfaces(Types types,
TypeMirror type) |
static List<TypeMirror> |
getAllSuperTypes(Types types,
TypeMirror type)
Similar to
getAllSuperClasses(javax.lang.model.util.Types, javax.lang.model.type.TypeMirror) but
returns all super types including implemented interfaces. |
static boolean |
isEqual(AnnotationValue oldVal,
AnnotationValue newVal) |
static boolean |
isSameType(TypeMirror t1,
TypeMirror t2)
To be used to compare types from different compilations (which are not comparable by standard means in Types).
|
static boolean |
isSubtype(TypeMirror type,
List<? extends TypeMirror> superTypes,
Types typeEnvironment)
Checks whether given type is a sub type or is equal to one of the provided types.
|
static Map<String,Map.Entry<? extends ExecutableElement,? extends AnnotationValue>> |
keyAnnotationAttributesByName(Map<? extends ExecutableElement,? extends AnnotationValue> attributes)
Extracts the names of the attributes from the executable elements that represents them in the given map and
returns a map keyed by those names.
|
static String |
toHumanReadableString(AnnotatedConstruct construct)
Constructs a human readable representation of the supplied element or type mirror.
|
static String |
toHumanReadableString(AnnotationMirror v) |
static String |
toHumanReadableString(AnnotationValue v) |
static String |
toUniqueString(AnnotationValue v) |
static String |
toUniqueString(TypeMirror t)
Represents the type mirror as a string in such a way that it can be used for equality comparisons.
|
public static boolean isSameType(@Nonnull TypeMirror t1, @Nonnull TypeMirror t2)
t1
- first typet2
- second type@Nonnull public static String toHumanReadableString(@Nonnull AnnotatedConstruct construct)
ExecutableType
for which there is no way
of getting reliably at the method name or the type declaring the method.construct
- the element or type mirror to render@Nonnull public static String toUniqueString(@Nonnull TypeMirror t)
t
- type to convert to string@Nonnull public static String toUniqueString(@Nonnull AnnotationValue v)
@Nonnull public static String toHumanReadableString(@Nonnull AnnotationValue v)
@Nonnull public static String toHumanReadableString(@Nonnull AnnotationMirror v)
@Nonnull public static List<TypeMirror> getAllSuperClasses(@Nonnull Types types, @Nonnull TypeMirror type)
types
- the Types instance of the compilation environment from which the type comes fromtype
- the type@Nonnull public static List<TypeMirror> getAllSuperTypes(@Nonnull Types types, @Nonnull TypeMirror type)
getAllSuperClasses(javax.lang.model.util.Types, javax.lang.model.type.TypeMirror)
but
returns all super types including implemented interfaces.types
- the Types instance of the compilation environment from which the type comes fromtype
- the typepublic static void fillAllSuperTypes(@Nonnull Types types, @Nonnull TypeMirror type, @Nonnull List<TypeMirror> result)
getAllSuperTypes(javax.lang.model.util.Types, javax.lang.model.type.TypeMirror)
but avoids
instantiation of a new list.types
- the Types instance of the compilation environment from which the type comes fromtype
- the typeresult
- the list to add the results to.@Nonnull public static List<TypeMirror> getAllSuperInterfaces(@Nonnull Types types, @Nonnull TypeMirror type)
public static void fillAllSuperInterfaces(@Nonnull Types types, @Nonnull TypeMirror type, @Nonnull List<TypeMirror> result)
public static boolean isSubtype(@Nonnull TypeMirror type, @Nonnull List<? extends TypeMirror> superTypes, @Nonnull Types typeEnvironment)
type
- the type to checksuperTypes
- the list of supposed super typestypeEnvironment
- the environment in which the type lives@Nonnull public static Map<String,Map.Entry<? extends ExecutableElement,? extends AnnotationValue>> keyAnnotationAttributesByName(@Nonnull Map<? extends ExecutableElement,? extends AnnotationValue> attributes)
I.e. while representing annotation attributes on an annotation type by executable elements is technically correct it is more convenient to address them simply by their names, which, in case of annotation types, are unique (i.e. you cannot overload an annotation attribute, because they cannot have method parameters).
attributes
- the attributes as obtained by
AnnotationMirror.getElementValues()
public static boolean isEqual(@Nonnull AnnotationValue oldVal, @Nonnull AnnotationValue newVal)
public static TypeElement findTypeByBinaryName(Elements elements, String binaryName)
elements
- the elements instance to search the classpathbinaryName
- the binary name of the classCopyright © 2014-2021 Lukas Krejci. All Rights Reserved.