2022-03-02 20:59:20 +00:00
|
|
|
package lombok.core;
|
|
|
|
|
|
|
|
import com.adjust.sdk.Constants;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
|
import java.lang.reflect.Type;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
2022-03-23 22:38:16 +00:00
|
|
|
/* loaded from: com.discord-119011.apk:lombok/core/SpiLoadUtil.SCL.lombok */
|
2022-03-02 20:59:20 +00:00
|
|
|
public class SpiLoadUtil {
|
|
|
|
|
|
|
|
/* renamed from: lombok.core.SpiLoadUtil$1 reason: invalid class name */
|
2022-03-23 22:38:16 +00:00
|
|
|
/* loaded from: com.discord-119011.apk:lombok/core/SpiLoadUtil$1.SCL.lombok */
|
2022-03-02 20:59:20 +00:00
|
|
|
class AnonymousClass1 implements Iterable<C> {
|
|
|
|
private final /* synthetic */ Iterator val$names;
|
|
|
|
private final /* synthetic */ Class val$target;
|
|
|
|
private final /* synthetic */ ClassLoader val$fLoader;
|
|
|
|
|
|
|
|
/* renamed from: lombok.core.SpiLoadUtil$1$1 reason: invalid class name and collision with other inner class name */
|
2022-03-23 22:38:16 +00:00
|
|
|
/* loaded from: com.discord-119011.apk:lombok/core/SpiLoadUtil$1$1.SCL.lombok */
|
2022-03-02 20:59:20 +00:00
|
|
|
class C04141 implements Iterator<C> {
|
|
|
|
private final /* synthetic */ Iterator val$names;
|
|
|
|
private final /* synthetic */ Class val$target;
|
|
|
|
private final /* synthetic */ ClassLoader val$fLoader;
|
|
|
|
|
|
|
|
C04141(Iterator it, Class cls, ClassLoader classLoader) {
|
|
|
|
this.val$names = it;
|
|
|
|
this.val$target = cls;
|
|
|
|
this.val$fLoader = classLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.util.Iterator
|
|
|
|
public boolean hasNext() {
|
|
|
|
return this.val$names.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.util.Iterator
|
|
|
|
public C next() {
|
|
|
|
try {
|
|
|
|
return this.val$target.cast(Class.forName((String) this.val$names.next(), true, this.val$fLoader).getConstructor(new Class[0]).newInstance(new Object[0]));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e = e;
|
|
|
|
if (e instanceof InvocationTargetException) {
|
|
|
|
e = e.getCause();
|
|
|
|
}
|
|
|
|
if (e instanceof RuntimeException) {
|
|
|
|
throw ((RuntimeException) e);
|
|
|
|
} else if (e instanceof Error) {
|
|
|
|
throw ((Error) e);
|
|
|
|
} else {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.util.Iterator
|
|
|
|
public void remove() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AnonymousClass1(Iterator it, Class cls, ClassLoader classLoader) {
|
|
|
|
this.val$names = it;
|
|
|
|
this.val$target = cls;
|
|
|
|
this.val$fLoader = classLoader;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // java.lang.Iterable
|
|
|
|
public Iterator<C> iterator() {
|
|
|
|
return new C04141(this.val$names, this.val$target, this.val$fLoader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private SpiLoadUtil() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> List<T> readAllFromIterator(Iterable<T> iterable) {
|
|
|
|
ArrayList arrayList = new ArrayList();
|
|
|
|
Iterator<T> it = iterable.iterator();
|
|
|
|
while (it.hasNext()) {
|
|
|
|
arrayList.add(it.next());
|
|
|
|
}
|
|
|
|
return arrayList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <C> Iterable<C> findServices(Class<C> cls) throws IOException {
|
|
|
|
return findServices(cls, Thread.currentThread().getContextClassLoader());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <C> Iterable<C> findServices(Class<C> cls, ClassLoader classLoader) throws IOException {
|
|
|
|
if (classLoader == null) {
|
|
|
|
classLoader = ClassLoader.getSystemClassLoader();
|
|
|
|
}
|
|
|
|
Enumeration<URL> resources = classLoader.getResources("META-INF/services/" + cls.getName());
|
|
|
|
LinkedHashSet linkedHashSet = new LinkedHashSet();
|
|
|
|
while (resources.hasMoreElements()) {
|
|
|
|
readServicesFromUrl(linkedHashSet, resources.nextElement());
|
|
|
|
}
|
|
|
|
return new AnonymousClass1(linkedHashSet.iterator(), cls, classLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void readServicesFromUrl(Collection<String> collection, URL url) throws IOException {
|
|
|
|
InputStream openStream = url.openStream();
|
|
|
|
BufferedReader bufferedReader = null;
|
|
|
|
if (openStream == null) {
|
|
|
|
if (0 != 0) {
|
|
|
|
try {
|
|
|
|
bufferedReader.close();
|
|
|
|
} catch (Throwable unused) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (openStream != null) {
|
|
|
|
openStream.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
bufferedReader = new BufferedReader(new InputStreamReader(openStream, Constants.ENCODING));
|
|
|
|
while (true) {
|
|
|
|
String readLine = bufferedReader.readLine();
|
|
|
|
if (readLine == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int indexOf = readLine.indexOf(35);
|
|
|
|
if (indexOf != -1) {
|
|
|
|
readLine = readLine.substring(0, indexOf);
|
|
|
|
}
|
|
|
|
String trim = readLine.trim();
|
|
|
|
if (trim.length() != 0) {
|
|
|
|
collection.add(trim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
try {
|
|
|
|
bufferedReader.close();
|
|
|
|
} catch (Throwable unused2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (openStream != null) {
|
|
|
|
openStream.close();
|
|
|
|
}
|
|
|
|
} catch (Throwable th) {
|
|
|
|
if (bufferedReader != null) {
|
|
|
|
try {
|
|
|
|
bufferedReader.close();
|
|
|
|
} catch (Throwable unused3) {
|
|
|
|
throw th;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (openStream != null) {
|
|
|
|
openStream.close();
|
|
|
|
}
|
|
|
|
throw th;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Class<? extends Annotation> findAnnotationClass(Class<?> cls, Class<?> cls2) {
|
|
|
|
if (cls == Object.class || cls == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Class<? extends Annotation> findAnnotationHelper = findAnnotationHelper(cls2, cls.getGenericSuperclass());
|
|
|
|
if (findAnnotationHelper != null) {
|
|
|
|
return findAnnotationHelper;
|
|
|
|
}
|
|
|
|
for (Type type : cls.getGenericInterfaces()) {
|
|
|
|
Class<? extends Annotation> findAnnotationHelper2 = findAnnotationHelper(cls2, type);
|
|
|
|
if (findAnnotationHelper2 != null) {
|
|
|
|
return findAnnotationHelper2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Class<? extends Annotation> findAnnotationClass = findAnnotationClass(cls.getSuperclass(), cls2);
|
|
|
|
if (findAnnotationClass != null) {
|
|
|
|
return findAnnotationClass;
|
|
|
|
}
|
|
|
|
for (Class<?> cls3 : cls.getInterfaces()) {
|
|
|
|
Class<? extends Annotation> findAnnotationClass2 = findAnnotationClass(cls3, cls2);
|
|
|
|
if (findAnnotationClass2 != null) {
|
|
|
|
return findAnnotationClass2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Class<? extends Annotation> findAnnotationHelper(Class<?> cls, Type type) {
|
|
|
|
if (!(type instanceof ParameterizedType)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
ParameterizedType parameterizedType = (ParameterizedType) type;
|
|
|
|
if (!cls.equals(parameterizedType.getRawType())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Type type2 = parameterizedType.getActualTypeArguments()[0];
|
|
|
|
if ((type2 instanceof Class) && Annotation.class.isAssignableFrom((Class) type2)) {
|
|
|
|
return (Class) type2;
|
|
|
|
}
|
|
|
|
throw new ClassCastException("Not an annotation type: " + type2);
|
|
|
|
}
|
|
|
|
}
|