diff --git a/common/api/src/main/java/com/dfsek/terra/api/util/reflection/TypeKey.java b/common/api/src/main/java/com/dfsek/terra/api/util/reflection/TypeKey.java index 5cbafe7d8..0bcc630e6 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/util/reflection/TypeKey.java +++ b/common/api/src/main/java/com/dfsek/terra/api/util/reflection/TypeKey.java @@ -7,17 +7,20 @@ import java.util.Objects; public class TypeKey { final Class rawType; final Type type; + + final AnnotatedType annotatedType; final int hashCode; @SuppressWarnings("unchecked") protected TypeKey() { this.type = getSuperclassTypeParameter(getClass()); + this.annotatedType = getAnnotatedSuperclassTypeParameter(getClass()); this.rawType = (Class) ReflectionUtil.getRawType(type); this.hashCode = type.hashCode(); } - static Type getSuperclassTypeParameter(Class subclass) { + private static Type getSuperclassTypeParameter(Class subclass) { Type superclass = subclass.getGenericSuperclass(); if(superclass instanceof Class) { throw new RuntimeException("Missing type parameter."); @@ -26,6 +29,15 @@ public class TypeKey { return parameterized.getActualTypeArguments()[0]; } + private static AnnotatedType getAnnotatedSuperclassTypeParameter(Class subclass) { + AnnotatedType superclass = subclass.getAnnotatedSuperclass(); + if(superclass.getType() instanceof Class) { + throw new RuntimeException("Missing type parameter."); + } + AnnotatedParameterizedType parameterized = (AnnotatedParameterizedType) superclass; + return parameterized.getAnnotatedActualTypeArguments()[0]; + } + /** * Returns the raw (non-generic) type for this type. */ @@ -40,6 +52,10 @@ public class TypeKey { return type; } + public AnnotatedType getAnnotatedType() { + return annotatedType; + } + @Override public final int hashCode() { return this.hashCode;