discord-jadx/app/src/main/java/b/i/d/q/a.java
2021-12-17 22:59:34 +01:00

414 lines
17 KiB
Java

package b.i.d.q;
import b.i.a.f.e.o.f;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Objects;
/* compiled from: $Gson$Types */
public final class a {
public static final Type[] a = new Type[0];
/* compiled from: $Gson$Types */
/* renamed from: b.i.d.q.a$a reason: collision with other inner class name */
public static final class C0149a implements GenericArrayType, Serializable {
private static final long serialVersionUID = 0;
private final Type componentType;
public C0149a(Type type) {
this.componentType = a.a(type);
}
@Override // java.lang.Object
public boolean equals(Object obj) {
return (obj instanceof GenericArrayType) && a.c(this, (GenericArrayType) obj);
}
@Override // java.lang.reflect.GenericArrayType
public Type getGenericComponentType() {
return this.componentType;
}
@Override // java.lang.Object
public int hashCode() {
return this.componentType.hashCode();
}
@Override // java.lang.Object
public String toString() {
return a.i(this.componentType) + "[]";
}
}
/* compiled from: $Gson$Types */
public static final class b implements ParameterizedType, Serializable {
private static final long serialVersionUID = 0;
private final Type ownerType;
private final Type rawType;
private final Type[] typeArguments;
public b(Type type, Type type2, Type... typeArr) {
if (type2 instanceof Class) {
Class cls = (Class) type2;
boolean z2 = true;
boolean z3 = Modifier.isStatic(cls.getModifiers()) || cls.getEnclosingClass() == null;
if (type == null && !z3) {
z2 = false;
}
f.v(z2);
}
this.ownerType = type == null ? null : a.a(type);
this.rawType = a.a(type2);
Type[] typeArr2 = (Type[]) typeArr.clone();
this.typeArguments = typeArr2;
int length = typeArr2.length;
for (int i = 0; i < length; i++) {
Objects.requireNonNull(this.typeArguments[i]);
a.b(this.typeArguments[i]);
Type[] typeArr3 = this.typeArguments;
typeArr3[i] = a.a(typeArr3[i]);
}
}
@Override // java.lang.Object
public boolean equals(Object obj) {
return (obj instanceof ParameterizedType) && a.c(this, (ParameterizedType) obj);
}
@Override // java.lang.reflect.ParameterizedType
public Type[] getActualTypeArguments() {
return (Type[]) this.typeArguments.clone();
}
@Override // java.lang.reflect.ParameterizedType
public Type getOwnerType() {
return this.ownerType;
}
@Override // java.lang.reflect.ParameterizedType
public Type getRawType() {
return this.rawType;
}
@Override // java.lang.Object
public int hashCode() {
int hashCode = Arrays.hashCode(this.typeArguments) ^ this.rawType.hashCode();
Type type = this.ownerType;
return hashCode ^ (type != null ? type.hashCode() : 0);
}
@Override // java.lang.Object
public String toString() {
int length = this.typeArguments.length;
if (length == 0) {
return a.i(this.rawType);
}
StringBuilder sb = new StringBuilder((length + 1) * 30);
sb.append(a.i(this.rawType));
sb.append("<");
sb.append(a.i(this.typeArguments[0]));
for (int i = 1; i < length; i++) {
sb.append(", ");
sb.append(a.i(this.typeArguments[i]));
}
sb.append(">");
return sb.toString();
}
}
/* compiled from: $Gson$Types */
public static final class c implements WildcardType, Serializable {
private static final long serialVersionUID = 0;
private final Type lowerBound;
private final Type upperBound;
public c(Type[] typeArr, Type[] typeArr2) {
boolean z2 = true;
f.v(typeArr2.length <= 1);
f.v(typeArr.length == 1);
if (typeArr2.length == 1) {
Objects.requireNonNull(typeArr2[0]);
a.b(typeArr2[0]);
f.v(typeArr[0] != Object.class ? false : z2);
this.lowerBound = a.a(typeArr2[0]);
this.upperBound = Object.class;
return;
}
Objects.requireNonNull(typeArr[0]);
a.b(typeArr[0]);
this.lowerBound = null;
this.upperBound = a.a(typeArr[0]);
}
@Override // java.lang.Object
public boolean equals(Object obj) {
return (obj instanceof WildcardType) && a.c(this, (WildcardType) obj);
}
@Override // java.lang.reflect.WildcardType
public Type[] getLowerBounds() {
Type type = this.lowerBound;
return type != null ? new Type[]{type} : a.a;
}
@Override // java.lang.reflect.WildcardType
public Type[] getUpperBounds() {
return new Type[]{this.upperBound};
}
@Override // java.lang.Object
public int hashCode() {
Type type = this.lowerBound;
return (type != null ? type.hashCode() + 31 : 1) ^ (this.upperBound.hashCode() + 31);
}
@Override // java.lang.Object
public String toString() {
if (this.lowerBound != null) {
StringBuilder R = b.d.b.a.a.R("? super ");
R.append(a.i(this.lowerBound));
return R.toString();
} else if (this.upperBound == Object.class) {
return "?";
} else {
StringBuilder R2 = b.d.b.a.a.R("? extends ");
R2.append(a.i(this.upperBound));
return R2.toString();
}
}
}
public static Type a(Type type) {
if (type instanceof Class) {
Class cls = (Class) type;
return cls.isArray() ? new C0149a(a(cls.getComponentType())) : cls;
} else if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
return new b(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments());
} else if (type instanceof GenericArrayType) {
return new C0149a(((GenericArrayType) type).getGenericComponentType());
} else {
if (!(type instanceof WildcardType)) {
return type;
}
WildcardType wildcardType = (WildcardType) type;
return new c(wildcardType.getUpperBounds(), wildcardType.getLowerBounds());
}
}
public static void b(Type type) {
f.v(!(type instanceof Class) || !((Class) type).isPrimitive());
}
public static boolean c(Type type, Type type2) {
if (type == type2) {
return true;
}
if (type instanceof Class) {
return type.equals(type2);
}
if (type instanceof ParameterizedType) {
if (!(type2 instanceof ParameterizedType)) {
return false;
}
ParameterizedType parameterizedType = (ParameterizedType) type;
ParameterizedType parameterizedType2 = (ParameterizedType) type2;
Type ownerType = parameterizedType.getOwnerType();
Type ownerType2 = parameterizedType2.getOwnerType();
return (ownerType == ownerType2 || (ownerType != null && ownerType.equals(ownerType2))) && parameterizedType.getRawType().equals(parameterizedType2.getRawType()) && Arrays.equals(parameterizedType.getActualTypeArguments(), parameterizedType2.getActualTypeArguments());
} else if (type instanceof GenericArrayType) {
if (!(type2 instanceof GenericArrayType)) {
return false;
}
return c(((GenericArrayType) type).getGenericComponentType(), ((GenericArrayType) type2).getGenericComponentType());
} else if (type instanceof WildcardType) {
if (!(type2 instanceof WildcardType)) {
return false;
}
WildcardType wildcardType = (WildcardType) type;
WildcardType wildcardType2 = (WildcardType) type2;
return Arrays.equals(wildcardType.getUpperBounds(), wildcardType2.getUpperBounds()) && Arrays.equals(wildcardType.getLowerBounds(), wildcardType2.getLowerBounds());
} else if (!(type instanceof TypeVariable) || !(type2 instanceof TypeVariable)) {
return false;
} else {
TypeVariable typeVariable = (TypeVariable) type;
TypeVariable typeVariable2 = (TypeVariable) type2;
return typeVariable.getGenericDeclaration() == typeVariable2.getGenericDeclaration() && typeVariable.getName().equals(typeVariable2.getName());
}
}
public static Type d(Type type, Class<?> cls, Class<?> cls2) {
if (cls2 == cls) {
return type;
}
if (cls2.isInterface()) {
Class<?>[] interfaces = cls.getInterfaces();
int length = interfaces.length;
for (int i = 0; i < length; i++) {
if (interfaces[i] == cls2) {
return cls.getGenericInterfaces()[i];
}
if (cls2.isAssignableFrom(interfaces[i])) {
return d(cls.getGenericInterfaces()[i], interfaces[i], cls2);
}
}
}
if (!cls.isInterface()) {
while (cls != Object.class) {
Class<? super Object> superclass = cls.getSuperclass();
if (superclass == cls2) {
return cls.getGenericSuperclass();
}
if (cls2.isAssignableFrom(superclass)) {
return d(cls.getGenericSuperclass(), superclass, cls2);
}
cls = superclass;
}
}
return cls2;
}
public static Class<?> e(Type type) {
if (type instanceof Class) {
return (Class) type;
}
if (type instanceof ParameterizedType) {
Type rawType = ((ParameterizedType) type).getRawType();
f.v(rawType instanceof Class);
return (Class) rawType;
} else if (type instanceof GenericArrayType) {
return Array.newInstance(e(((GenericArrayType) type).getGenericComponentType()), 0).getClass();
} else {
if (type instanceof TypeVariable) {
return Object.class;
}
if (type instanceof WildcardType) {
return e(((WildcardType) type).getUpperBounds()[0]);
}
String name = type == null ? "null" : type.getClass().getName();
throw new IllegalArgumentException("Expected a Class, ParameterizedType, or GenericArrayType, but <" + type + "> is of type " + name);
}
}
public static Type f(Type type, Class<?> cls, Class<?> cls2) {
if (type instanceof WildcardType) {
type = ((WildcardType) type).getUpperBounds()[0];
}
f.v(cls2.isAssignableFrom(cls));
return g(type, cls, d(type, cls, cls2));
}
public static Type g(Type type, Class<?> cls, Type type2) {
return h(type, cls, type2, new HashSet());
}
/* JADX DEBUG: Failed to insert an additional move for type inference into block B:85:? */
/* JADX DEBUG: Failed to insert an additional move for type inference into block B:83:0x004b */
public static Type h(Type type, Class<?> cls, Type type2, Collection<TypeVariable> collection) {
TypeVariable typeVariable;
do {
int i = 0;
if (type2 instanceof TypeVariable) {
typeVariable = (TypeVariable) type2;
if (collection.contains(typeVariable)) {
return type2;
}
collection.add(typeVariable);
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
Class cls2 = genericDeclaration instanceof Class ? (Class) genericDeclaration : null;
if (cls2 != null) {
Type d = d(type, cls, cls2);
if (d instanceof ParameterizedType) {
TypeVariable[] typeParameters = cls2.getTypeParameters();
int length = typeParameters.length;
while (i < length) {
if (typeVariable.equals(typeParameters[i])) {
type2 = ((ParameterizedType) d).getActualTypeArguments()[i];
continue;
} else {
i++;
}
}
throw new NoSuchElementException();
}
}
type2 = typeVariable;
continue;
} else {
if (type2 instanceof Class) {
Class cls3 = (Class) type2;
if (cls3.isArray()) {
Class<?> componentType = cls3.getComponentType();
Type h = h(type, cls, componentType, collection);
return componentType == h ? cls3 : new C0149a(h);
}
}
if (type2 instanceof GenericArrayType) {
GenericArrayType genericArrayType = (GenericArrayType) type2;
Type genericComponentType = genericArrayType.getGenericComponentType();
Type h2 = h(type, cls, genericComponentType, collection);
return genericComponentType == h2 ? genericArrayType : new C0149a(h2);
} else if (type2 instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type2;
Type ownerType = parameterizedType.getOwnerType();
Type h3 = h(type, cls, ownerType, collection);
boolean z2 = h3 != ownerType;
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
int length2 = actualTypeArguments.length;
while (i < length2) {
Type h4 = h(type, cls, actualTypeArguments[i], collection);
if (h4 != actualTypeArguments[i]) {
if (!z2) {
actualTypeArguments = (Type[]) actualTypeArguments.clone();
z2 = true;
}
actualTypeArguments[i] = h4;
}
i++;
}
return z2 ? new b(h3, parameterizedType.getRawType(), actualTypeArguments) : parameterizedType;
} else {
boolean z3 = type2 instanceof WildcardType;
WildcardType wildcardType = type2;
if (z3) {
WildcardType wildcardType2 = (WildcardType) type2;
Type[] lowerBounds = wildcardType2.getLowerBounds();
Type[] upperBounds = wildcardType2.getUpperBounds();
if (lowerBounds.length == 1) {
Type h5 = h(type, cls, lowerBounds[0], collection);
wildcardType = wildcardType2;
if (h5 != lowerBounds[0]) {
return new c(new Type[]{Object.class}, h5 instanceof WildcardType ? ((WildcardType) h5).getLowerBounds() : new Type[]{h5});
}
} else {
wildcardType = wildcardType2;
if (upperBounds.length == 1) {
Type h6 = h(type, cls, upperBounds[0], collection);
wildcardType = wildcardType2;
if (h6 != upperBounds[0]) {
return new c(h6 instanceof WildcardType ? ((WildcardType) h6).getUpperBounds() : new Type[]{h6}, a);
}
}
}
}
return wildcardType;
}
}
} while (type2 != typeVariable);
return type2;
}
public static String i(Type type) {
return type instanceof Class ? ((Class) type).getName() : type.toString();
}
}