discord-jadx/app/src/main/java/lombok/core/AST.java

392 lines
13 KiB
Java

package lombok.core;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import lombok.Lombok;
import lombok.core.AST;
import lombok.core.LombokNode;
import lombok.core.configuration.ConfigurationKey;
import lombok.core.debug.HistogramTracker;
import lombok.permit.Permit;
/* loaded from: com.discord-118107.apk:lombok/core/AST.SCL.lombok */
public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> {
private L top;
private final String fileName;
private final String packageDeclaration;
private final ImportList imports;
private TypeResolver importsAsResolver;
Map<N, N> identityDetector = new IdentityHashMap();
private Map<N, L> nodeMap = new IdentityHashMap();
private boolean changed = false;
private final Collection<Class<? extends N>> statementTypes;
private static final HistogramTracker configTracker;
private static final ConcurrentMap<Class<?>, FieldAccess[]> fieldsOfASTClasses;
/* loaded from: com.discord-118107.apk:lombok/core/AST$FieldAccess.SCL.lombok */
protected static class FieldAccess {
public final Field field;
public final int dim;
FieldAccess(Field field, int i) {
this.field = field;
this.dim = i;
}
}
/* loaded from: com.discord-118107.apk:lombok/core/AST$Kind.SCL.lombok */
public enum Kind {
COMPILATION_UNIT,
TYPE,
FIELD,
INITIALIZER,
METHOD,
ANNOTATION,
ARGUMENT,
LOCAL,
STATEMENT,
TYPE_USE
}
static {
configTracker = System.getProperty("lombok.timeConfig") == null ? null : new HistogramTracker("lombok.config");
fieldsOfASTClasses = new ConcurrentHashMap();
}
protected AST(String str, String str2, ImportList importList, Collection<Class<? extends N>> collection) {
this.fileName = str == null ? "(unknown).java" : str;
this.packageDeclaration = str2;
this.imports = importList;
this.statementTypes = collection;
}
public abstract URI getAbsoluteFileLocation();
public void setChanged() {
this.changed = true;
}
protected void clearChanged() {
this.changed = false;
}
public boolean isChanged() {
return this.changed;
}
protected void setTop(L l) {
this.top = l;
}
public final String getPackageDeclaration() {
return this.packageDeclaration;
}
public final ImportList getImportList() {
return this.imports;
}
public final TypeResolver getImportListAsTypeResolver() {
if (this.importsAsResolver != null) {
return this.importsAsResolver;
}
TypeResolver typeResolver = new TypeResolver(getImportList());
this.importsAsResolver = typeResolver;
return typeResolver;
}
/* JADX WARN: Multi-variable type inference failed */
protected L putInMap(L l) {
this.nodeMap.put(l.get(), l);
this.identityDetector.put(l.get(), l.get());
return l;
}
protected Map<N, L> getNodeMap() {
return this.nodeMap;
}
protected void clearState() {
this.identityDetector = new IdentityHashMap();
this.nodeMap = new IdentityHashMap();
}
protected boolean setAndGetAsHandled(N n) {
return this.identityDetector.put(n, n) != null;
}
public String getFileName() {
return this.fileName;
}
public L top() {
return this.top;
}
public L get(N n) {
return this.nodeMap.get(n);
}
public int getSourceVersion() {
return 6;
}
public int getLatestJavaSpecSupported() {
return 6;
}
L replaceNewWithExistingOld(Map<N, L> map, L l) {
L l2 = map.get(l.get());
L l3 = l2 == null ? l : l2;
ArrayList arrayList = new ArrayList();
Iterator<L> it = l.children.iterator();
while (it.hasNext()) {
L replaceNewWithExistingOld = replaceNewWithExistingOld(map, it.next());
arrayList.add(replaceNewWithExistingOld);
replaceNewWithExistingOld.parent = l3;
}
l3.children = LombokImmutableList.copyOf((Collection) arrayList);
return l3;
}
protected abstract L buildTree(N n, Kind kind);
protected FieldAccess[] fieldsOf(Class<?> cls) {
FieldAccess[] fieldAccessArr = fieldsOfASTClasses.get(cls);
if (fieldAccessArr != null) {
return fieldAccessArr;
}
ArrayList arrayList = new ArrayList();
getFields(cls, arrayList);
fieldsOfASTClasses.putIfAbsent(cls, (FieldAccess[]) arrayList.toArray(new FieldAccess[0]));
return fieldsOfASTClasses.get(cls);
}
private void getFields(Class<?> cls, Collection<FieldAccess> collection) {
Field[] declaredFields;
if (!(cls == Object.class || cls == null)) {
for (Field field : cls.getDeclaredFields()) {
if (!Modifier.isStatic(field.getModifiers())) {
Class<?> type = field.getType();
int i = 0;
if (type.isArray()) {
while (type.isArray()) {
i++;
type = type.getComponentType();
}
} else {
while (Collection.class.isAssignableFrom(type)) {
i++;
type = getComponentType(field.getGenericType());
}
}
if (shouldDrill(cls, type, field.getName())) {
Permit.setAccessible(field);
collection.add(new FieldAccess(field, i));
}
}
}
getFields(cls.getSuperclass(), collection);
}
}
private Class<?> getComponentType(Type type) {
if (!(type instanceof ParameterizedType)) {
return Object.class;
}
Type type2 = ((ParameterizedType) type).getActualTypeArguments()[0];
return type2 instanceof Class ? (Class) type2 : Object.class;
}
private boolean shouldDrill(Class<?> cls, Class<?> cls2, String str) {
Iterator<Class<? extends N>> it = this.statementTypes.iterator();
while (it.hasNext()) {
if (it.next().isAssignableFrom(cls2)) {
return true;
}
}
return false;
}
protected Collection<L> buildWithField(Class<L> cls, N n, FieldAccess fieldAccess) {
ArrayList arrayList = new ArrayList();
buildWithField0(cls, n, fieldAccess, arrayList);
return arrayList;
}
protected boolean replaceStatementInNode(N n, N n2, N n3) {
for (FieldAccess fieldAccess : fieldsOf(n.getClass())) {
if (replaceStatementInField(fieldAccess, n, n2, n3)) {
return true;
}
}
return false;
}
private boolean replaceStatementInField(FieldAccess fieldAccess, N n, N n2, N n3) {
try {
Object obj = fieldAccess.field.get(n);
if (obj == null) {
return false;
}
if (obj == n2) {
fieldAccess.field.set(n, n3);
return true;
} else if (fieldAccess.dim <= 0) {
return false;
} else {
if (obj.getClass().isArray()) {
return replaceStatementInArray(obj, n2, n3);
}
if (Collection.class.isInstance(obj)) {
return replaceStatementInCollection(fieldAccess.field, n, new ArrayList(), (Collection) obj, n2, n3);
}
return false;
}
} catch (IllegalAccessException e) {
throw Lombok.sneakyThrow(e);
}
}
private boolean replaceStatementInCollection(Field field, Object obj, List<Collection<?>> list, Collection<?> collection, N n, N n2) throws IllegalAccessException {
if (collection == null) {
return false;
}
int i = -1;
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
Object next = it.next();
i++;
if (next != null) {
if (Collection.class.isInstance(next)) {
Collection<?> collection2 = (Collection) next;
ArrayList arrayList = new ArrayList(list);
arrayList.add(collection2);
if (replaceStatementInCollection(field, obj, arrayList, collection2, n, n2)) {
return true;
}
}
if (next == n) {
setElementInASTCollection(field, obj, list, collection, i, n2);
return true;
}
}
}
return false;
}
protected void setElementInASTCollection(Field field, Object obj, List<Collection<?>> list, Collection<?> collection, int i, N n) throws IllegalAccessException {
if (collection instanceof List) {
((List) collection).set(i, n);
}
}
private boolean replaceStatementInArray(Object obj, N n, N n2) {
if (obj == null) {
return false;
}
int length = Array.getLength(obj);
for (int i = 0; i < length; i++) {
Object obj2 = Array.get(obj, i);
if (obj2 != null) {
if (obj2.getClass().isArray()) {
if (replaceStatementInArray(obj2, n, n2)) {
return true;
}
} else if (obj2 == n) {
Array.set(obj, i, n2);
return true;
}
}
}
return false;
}
/* JADX WARN: Multi-variable type inference failed */
private void buildWithField0(Class<L> cls, N n, FieldAccess fieldAccess, Collection<L> collection) {
try {
Object obj = fieldAccess.field.get(n);
if (obj != null) {
if (fieldAccess.dim == 0) {
LombokNode buildTree = buildTree(obj, Kind.STATEMENT);
if (buildTree != null) {
collection.add(cls.cast(buildTree));
}
} else if (obj.getClass().isArray()) {
buildWithArray(cls, obj, collection, fieldAccess.dim);
} else if (Collection.class.isInstance(obj)) {
buildWithCollection(cls, obj, collection, fieldAccess.dim);
}
}
} catch (IllegalAccessException e) {
throw Lombok.sneakyThrow(e);
}
}
/* JADX WARN: Multi-variable type inference failed */
private void buildWithArray(Class<L> cls, Object obj, Collection<L> collection, int i) {
Object obj2;
Object[] objArr;
LombokNode buildTree;
if (i == 1) {
for (Object obj3 : (Object[]) obj) {
if (!(obj3 == null || (buildTree = buildTree(obj3, Kind.STATEMENT)) == null)) {
collection.add(cls.cast(buildTree));
}
}
return;
}
Object[] objArr2 = (Object[]) obj;
int length = objArr2.length;
for (int i2 = 0; i2 < length && (obj2 = objArr2[i2]) != null; i2++) {
buildWithArray(cls, obj2, collection, i - 1);
}
}
/* JADX WARN: Multi-variable type inference failed */
private void buildWithCollection(Class<L> cls, Object obj, Collection<L> collection, int i) {
LombokNode buildTree;
if (i == 1) {
Iterator it = ((Collection) obj).iterator();
while (it.hasNext()) {
Object next = it.next();
if (!(next == null || (buildTree = buildTree(next, Kind.STATEMENT)) == null)) {
collection.add(cls.cast(buildTree));
}
}
return;
}
Iterator it2 = ((Collection) obj).iterator();
while (it2.hasNext()) {
buildWithCollection(cls, it2.next(), collection, i - 1);
}
}
public final <T> T readConfiguration(ConfigurationKey<T> configurationKey) {
long start = configTracker == null ? 0L : configTracker.start();
try {
T t = (T) LombokConfiguration.read((ConfigurationKey<Object>) configurationKey, (AST<?, ?, ?>) this);
if (configTracker != null) {
configTracker.end(start);
}
return t;
} catch (Throwable th) {
if (configTracker != null) {
configTracker.end(start);
}
throw th;
}
}
}