Package google.registry.util
Class TypeUtils
java.lang.Object
google.registry.util.TypeUtils
Utilities methods related to reflection.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ATypeToken
that removes an ugly cast in the common cases of getting a known type. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkNoInheritanceRelationships
(com.google.common.collect.ImmutableSet<Class<?>> resourceClasses) static <T> Class
<T> getClassFromString
(String className, Class<T> expectedSuperType) Returns the class referred to by a fully qualified class name string.static <T> com.google.common.collect.ImmutableMap
<String, T> getTypesafeEnumMapping
(Class<T> clazz) Aggregates enum "values" in a typesafe enum pattern into a string->field map.hasAnnotation
(Class<? extends Annotation> annotation) Returns a predicate that tests whether classes are annotated with the given annotation.static <T> T
instantiate
(Class<? extends T> clazz) static <T,
U> T instantiate
(Class<? extends T> clazz, U arg) Instantiate a class with the specified constructor argument.
-
Method Details
-
instantiate
-
instantiate
Instantiate a class with the specified constructor argument.Because we use
arg
's type to look up the constructor, this only works if arg1's class is exactly the same type as the constructor argument. Subtypes are not allowed. -
getClassFromString
Returns the class referred to by a fully qualified class name string.Throws an error if the loaded class is not assignable from the expected super type class.
-
getTypesafeEnumMapping
public static <T> com.google.common.collect.ImmutableMap<String,T> getTypesafeEnumMapping(Class<T> clazz) Aggregates enum "values" in a typesafe enum pattern into a string->field map. -
hasAnnotation
Returns a predicate that tests whether classes are annotated with the given annotation. -
checkNoInheritanceRelationships
public static void checkNoInheritanceRelationships(com.google.common.collect.ImmutableSet<Class<?>> resourceClasses)
-