Skip to content

Commit

Permalink
android-record: Adapt generic types returned by Android reflection to…
Browse files Browse the repository at this point in the history
… follow Java behavior.
  • Loading branch information
HelloOO7 committed Sep 3, 2024
1 parent 032b52e commit fb007fd
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,21 @@ static Class<?> arrayTypeCompat(Class<?> componentType) {

static Type fixAndroidGenericType(Type type) {
if (type instanceof GenericArrayType) {
//recurse into component type
Type componentType = fixAndroidGenericType(((GenericArrayType) type).getGenericComponentType());
if (componentType instanceof Class<?>) { //if it isn't generic, return the raw array type
if (componentType instanceof Class<?>) {
return arrayTypeCompat((Class<?>) componentType);
}
}
else if (type instanceof ParameterizedType) {
//if the parameterized type is not actually parameterized, deduce the raw type
ParameterizedType parameterizedType = (ParameterizedType) type;
Type rawType = parameterizedType.getRawType();
if (rawType instanceof Class<?>) {
Class<?> rawComponentClass = (Class<?>) rawType;
if (rawComponentClass.getTypeParameters().length == 0) {
return rawComponentClass;
if (parameterizedType.getOwnerType() == null) {
Type rawType = parameterizedType.getRawType();
if (rawType instanceof Class<?>) {
Class<?> rawComponentClass = (Class<?>) rawType;
if (rawComponentClass.getTypeParameters().length == 0) {
return rawComponentClass;
}
}
}
}
Expand Down

0 comments on commit fb007fd

Please sign in to comment.