mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
add TypeKey#getAnnotatedType
This commit is contained in:
@@ -7,17 +7,20 @@ import java.util.Objects;
|
||||
public class TypeKey<T> {
|
||||
final Class<? super T> 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<? super T>) 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<T> {
|
||||
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<T> {
|
||||
return type;
|
||||
}
|
||||
|
||||
public AnnotatedType getAnnotatedType() {
|
||||
return annotatedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return this.hashCode;
|
||||
|
||||
Reference in New Issue
Block a user