431 lines
18 KiB
Java
431 lines
18 KiB
Java
package lombok.core;
|
|
|
|
import java.lang.annotation.Annotation;
|
|
import java.lang.reflect.Array;
|
|
import java.lang.reflect.InvocationHandler;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Proxy;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import lombok.core.AST;
|
|
import lombok.permit.Permit;
|
|
/* loaded from: com.discord-118011.apk:lombok/core/AnnotationValues.SCL.lombok */
|
|
public class AnnotationValues<A extends Annotation> {
|
|
private final Class<A> type;
|
|
private final Map<String, AnnotationValue> values;
|
|
private final LombokNode<?, ?, ?> ast;
|
|
private A cachedInstance = null;
|
|
|
|
/* renamed from: lombok.core.AnnotationValues$1 reason: invalid class name */
|
|
/* loaded from: com.discord-118011.apk:lombok/core/AnnotationValues$1.SCL.lombok */
|
|
class AnonymousClass1 implements InvocationHandler {
|
|
AnonymousClass1() {
|
|
}
|
|
|
|
@Override // java.lang.reflect.InvocationHandler
|
|
public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
|
|
AnnotationValue annotationValue = (AnnotationValue) AnnotationValues.access$0(AnnotationValues.this).get(method.getName());
|
|
if (annotationValue == null) {
|
|
Object defaultValue = method.getDefaultValue();
|
|
if (defaultValue != null) {
|
|
return defaultValue;
|
|
}
|
|
throw AnnotationValues.access$1(annotationValue, method);
|
|
}
|
|
boolean z2 = false;
|
|
Class<?> returnType = method.getReturnType();
|
|
Object obj2 = null;
|
|
if (returnType.isArray()) {
|
|
z2 = true;
|
|
returnType = returnType.getComponentType();
|
|
obj2 = Array.newInstance(returnType, annotationValue.valueGuesses.size());
|
|
}
|
|
if (!z2 && annotationValue.valueGuesses.size() > 1) {
|
|
throw new AnnotationValueDecodeFail(annotationValue, "Expected a single value, but " + method.getName() + " has an array of values", -1);
|
|
} else if (annotationValue.valueGuesses.size() != 0 || z2) {
|
|
int i = 0;
|
|
Iterator<Object> it = annotationValue.valueGuesses.iterator();
|
|
while (it.hasNext()) {
|
|
Object next = it.next();
|
|
Object access$2 = next == null ? null : AnnotationValues.access$2(AnnotationValues.this, next, returnType, annotationValue, i);
|
|
if (!z2) {
|
|
if (access$2 != null) {
|
|
return access$2;
|
|
}
|
|
Object defaultValue2 = method.getDefaultValue();
|
|
if (defaultValue2 != null) {
|
|
return defaultValue2;
|
|
}
|
|
throw AnnotationValues.access$1(annotationValue, method);
|
|
} else if (access$2 != null) {
|
|
i++;
|
|
Array.set(obj2, i, access$2);
|
|
} else if (annotationValue.valueGuesses.size() == 1) {
|
|
Object defaultValue3 = method.getDefaultValue();
|
|
if (defaultValue3 != null) {
|
|
return defaultValue3;
|
|
}
|
|
throw AnnotationValues.access$1(annotationValue, method);
|
|
} else {
|
|
throw new AnnotationValueDecodeFail(annotationValue, "I can't make sense of this annotation value. Try using a fully qualified literal.", i);
|
|
}
|
|
}
|
|
return obj2;
|
|
} else {
|
|
Object defaultValue4 = method.getDefaultValue();
|
|
if (defaultValue4 != null) {
|
|
return defaultValue4;
|
|
}
|
|
throw AnnotationValues.access$1(annotationValue, method);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* loaded from: com.discord-118011.apk:lombok/core/AnnotationValues$AnnotationValue.SCL.lombok */
|
|
public static class AnnotationValue {
|
|
public final List<String> raws;
|
|
public final List<Object> valueGuesses;
|
|
public final List<Object> expressions;
|
|
private final LombokNode<?, ?, ?> node;
|
|
private final boolean isExplicit;
|
|
|
|
public AnnotationValue(LombokNode<?, ?, ?> lombokNode, List<String> list, List<Object> list2, List<Object> list3, boolean z2) {
|
|
this.node = lombokNode;
|
|
this.raws = list;
|
|
this.expressions = list2;
|
|
this.valueGuesses = list3;
|
|
this.isExplicit = z2;
|
|
}
|
|
|
|
public void setError(String str, int i) {
|
|
this.node.addError(str);
|
|
}
|
|
|
|
public void setWarning(String str, int i) {
|
|
this.node.addError(str);
|
|
}
|
|
|
|
public String toString() {
|
|
return "raws: " + this.raws + " valueGuesses: " + this.valueGuesses;
|
|
}
|
|
|
|
public boolean isExplicit() {
|
|
return this.isExplicit;
|
|
}
|
|
}
|
|
|
|
/* loaded from: com.discord-118011.apk:lombok/core/AnnotationValues$AnnotationValueDecodeFail.SCL.lombok */
|
|
public static class AnnotationValueDecodeFail extends RuntimeException {
|
|
private static final long serialVersionUID = 1;
|
|
public final int idx;
|
|
public final AnnotationValue owner;
|
|
|
|
public AnnotationValueDecodeFail(AnnotationValue annotationValue, String str, int i) {
|
|
super(str);
|
|
this.idx = i;
|
|
this.owner = annotationValue;
|
|
}
|
|
}
|
|
|
|
public AnnotationValues(Class<A> cls, Map<String, AnnotationValue> map, LombokNode<?, ?, ?> lombokNode) {
|
|
this.type = cls;
|
|
this.values = map;
|
|
this.ast = lombokNode;
|
|
}
|
|
|
|
public static <A extends Annotation> AnnotationValues<A> of(Class<A> cls) {
|
|
return new AnnotationValues<>(cls, Collections.emptyMap(), null);
|
|
}
|
|
|
|
public static <A extends Annotation> AnnotationValues<A> of(Class<A> cls, LombokNode<?, ?, ?> lombokNode) {
|
|
return new AnnotationValues<>(cls, Collections.emptyMap(), lombokNode);
|
|
}
|
|
|
|
private static AnnotationValueDecodeFail makeNoDefaultFail(AnnotationValue annotationValue, Method method) {
|
|
return new AnnotationValueDecodeFail(annotationValue, "No value supplied but " + method.getName() + " has no default either.", -1);
|
|
}
|
|
|
|
public List<String> getAsStringList(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue == null) {
|
|
return Collections.unmodifiableList(Arrays.asList((String[]) getDefaultIf(str, String[].class, new String[0])));
|
|
}
|
|
ArrayList arrayList = new ArrayList(annotationValue.valueGuesses.size());
|
|
Iterator<Object> it = annotationValue.valueGuesses.iterator();
|
|
while (it.hasNext()) {
|
|
Object next = it.next();
|
|
Object guessToType = next == null ? null : guessToType(next, String.class, annotationValue, 0);
|
|
if (guessToType != null) {
|
|
arrayList.add((String) guessToType);
|
|
} else if (annotationValue.valueGuesses.size() == 1) {
|
|
return Collections.unmodifiableList(Arrays.asList((String[]) getDefaultIf(str, String[].class, new String[0])));
|
|
} else {
|
|
throw new AnnotationValueDecodeFail(annotationValue, "I can't make sense of this annotation value. Try using a fully qualified literal.", 0);
|
|
}
|
|
}
|
|
return Collections.unmodifiableList(arrayList);
|
|
}
|
|
|
|
public String getAsString(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue == null || annotationValue.valueGuesses.size() != 1) {
|
|
return (String) getDefaultIf(str, String.class, "");
|
|
}
|
|
Object guessToType = guessToType(annotationValue.valueGuesses.get(0), String.class, annotationValue, 0);
|
|
return guessToType instanceof String ? (String) guessToType : (String) getDefaultIf(str, String.class, "");
|
|
}
|
|
|
|
public boolean getAsBoolean(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue == null || annotationValue.valueGuesses.size() != 1) {
|
|
return ((Boolean) getDefaultIf(str, Boolean.TYPE, false)).booleanValue();
|
|
}
|
|
Object guessToType = guessToType(annotationValue.valueGuesses.get(0), Boolean.TYPE, annotationValue, 0);
|
|
return guessToType instanceof Boolean ? ((Boolean) guessToType).booleanValue() : ((Boolean) getDefaultIf(str, Boolean.TYPE, false)).booleanValue();
|
|
}
|
|
|
|
public <T> T getDefaultIf(String str, Class<T> cls, T t) {
|
|
try {
|
|
return cls.cast(Permit.getMethod(cls, str, new Class[0]).getDefaultValue());
|
|
} catch (Exception unused) {
|
|
return t;
|
|
}
|
|
}
|
|
|
|
public A getInstance() {
|
|
if (this.cachedInstance != null) {
|
|
return this.cachedInstance;
|
|
}
|
|
A a = (A) ((Annotation) Proxy.newProxyInstance(this.type.getClassLoader(), new Class[]{this.type}, new AnonymousClass1()));
|
|
this.cachedInstance = a;
|
|
return a;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private Object guessToType(Object obj, Class<?> cls, AnnotationValue annotationValue, int i) {
|
|
Object[] enumConstants;
|
|
if ((cls == Integer.TYPE || cls == Integer.class) && ((obj instanceof Integer) || (obj instanceof Short) || (obj instanceof Byte))) {
|
|
return Integer.valueOf(((Number) obj).intValue());
|
|
}
|
|
if ((cls == Long.TYPE || cls == Long.class) && ((obj instanceof Long) || (obj instanceof Integer) || (obj instanceof Short) || (obj instanceof Byte))) {
|
|
return Long.valueOf(((Number) obj).longValue());
|
|
}
|
|
if ((cls == Short.TYPE || cls == Short.class) && ((obj instanceof Integer) || (obj instanceof Short) || (obj instanceof Byte))) {
|
|
int intValue = ((Number) obj).intValue();
|
|
short shortValue = ((Number) obj).shortValue();
|
|
if (shortValue == intValue) {
|
|
return Integer.valueOf(shortValue);
|
|
}
|
|
}
|
|
if ((cls == Byte.TYPE || cls == Byte.class) && ((obj instanceof Integer) || (obj instanceof Short) || (obj instanceof Byte))) {
|
|
int intValue2 = ((Number) obj).intValue();
|
|
byte byteValue = ((Number) obj).byteValue();
|
|
if (byteValue == intValue2) {
|
|
return Integer.valueOf(byteValue);
|
|
}
|
|
}
|
|
if ((cls == Double.TYPE || cls == Double.class) && (obj instanceof Number)) {
|
|
return Double.valueOf(((Number) obj).doubleValue());
|
|
}
|
|
if ((cls == Float.TYPE || cls == Float.class) && (obj instanceof Number)) {
|
|
return Float.valueOf(((Number) obj).floatValue());
|
|
}
|
|
if ((cls == Boolean.TYPE || cls == Boolean.class) && (obj instanceof Boolean)) {
|
|
return Boolean.valueOf(((Boolean) obj).booleanValue());
|
|
}
|
|
if ((cls == Character.TYPE || cls == Character.class) && (obj instanceof Character)) {
|
|
return Character.valueOf(((Character) obj).charValue());
|
|
}
|
|
if (cls == String.class && (obj instanceof String)) {
|
|
return obj;
|
|
}
|
|
if (Enum.class.isAssignableFrom(cls) && (obj instanceof FieldSelect)) {
|
|
String finalPart = ((FieldSelect) obj).getFinalPart();
|
|
for (Object[] objArr : cls.getEnumConstants()) {
|
|
if (((Enum) objArr).name().equals(finalPart)) {
|
|
return objArr;
|
|
}
|
|
}
|
|
throw new AnnotationValueDecodeFail(annotationValue, "Can't translate " + finalPart + " to an enum of type " + cls, i);
|
|
} else if (cls == Class.class && (obj instanceof ClassLiteral)) {
|
|
try {
|
|
return Class.forName(toFQ(((ClassLiteral) obj).getClassName()));
|
|
} catch (ClassNotFoundException unused) {
|
|
throw new AnnotationValueDecodeFail(annotationValue, "Can't translate " + obj + " to a class object.", i);
|
|
}
|
|
} else if (obj instanceof AnnotationValues) {
|
|
return ((AnnotationValues) obj).getInstance();
|
|
} else {
|
|
if (obj instanceof FieldSelect) {
|
|
throw new AnnotationValueDecodeFail(annotationValue, "You must use constant literals in lombok annotations; they cannot be references to (static) fields.", i);
|
|
}
|
|
throw new AnnotationValueDecodeFail(annotationValue, "Can't translate a " + obj.getClass() + " to the expected " + cls, i);
|
|
}
|
|
}
|
|
|
|
public List<String> getRawExpressions(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
return annotationValue == null ? Collections.emptyList() : annotationValue.raws;
|
|
}
|
|
|
|
public List<Object> getActualExpressions(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
return annotationValue == null ? Collections.emptyList() : annotationValue.expressions;
|
|
}
|
|
|
|
public boolean isExplicit(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
return annotationValue != null && annotationValue.isExplicit();
|
|
}
|
|
|
|
public String getRawExpression(String str) {
|
|
List<String> rawExpressions = getRawExpressions(str);
|
|
if (rawExpressions.isEmpty()) {
|
|
return null;
|
|
}
|
|
return rawExpressions.get(0);
|
|
}
|
|
|
|
public Object getActualExpression(String str) {
|
|
List<Object> actualExpressions = getActualExpressions(str);
|
|
if (actualExpressions.isEmpty()) {
|
|
return null;
|
|
}
|
|
return actualExpressions.get(0);
|
|
}
|
|
|
|
public Object getValueGuess(String str) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue == null || annotationValue.valueGuesses.isEmpty()) {
|
|
return null;
|
|
}
|
|
return annotationValue.valueGuesses.get(0);
|
|
}
|
|
|
|
public void setError(String str, String str2) {
|
|
setError(str, str2, -1);
|
|
}
|
|
|
|
public void setWarning(String str, String str2) {
|
|
setWarning(str, str2, -1);
|
|
}
|
|
|
|
public void setError(String str, String str2, int i) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue != null) {
|
|
annotationValue.setError(str2, i);
|
|
}
|
|
}
|
|
|
|
public void setWarning(String str, String str2, int i) {
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue != null) {
|
|
annotationValue.setWarning(str2, i);
|
|
}
|
|
}
|
|
|
|
public List<String> getProbableFQTypes(String str) {
|
|
ArrayList arrayList = new ArrayList();
|
|
AnnotationValue annotationValue = this.values.get(str);
|
|
if (annotationValue == null) {
|
|
return Collections.emptyList();
|
|
}
|
|
Iterator<Object> it = annotationValue.valueGuesses.iterator();
|
|
while (it.hasNext()) {
|
|
Object next = it.next();
|
|
arrayList.add(next == null ? null : toFQ(next.toString()));
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public String getProbableFQType(String str) {
|
|
List<String> probableFQTypes = getProbableFQTypes(str);
|
|
if (probableFQTypes.isEmpty()) {
|
|
return null;
|
|
}
|
|
return probableFQTypes.get(0);
|
|
}
|
|
|
|
private String toFQ(String str) {
|
|
Class<?> cls;
|
|
String fullyQualifiedNameForSimpleName;
|
|
String substring = str.indexOf(46) > -1 ? str.substring(0, str.indexOf(46)) : str;
|
|
LombokNode<?, ?, ?> lombokNode = this.ast;
|
|
while (true) {
|
|
if (lombokNode == null) {
|
|
break;
|
|
} else if (lombokNode.getKind() != AST.Kind.TYPE || !substring.equals(lombokNode.getName())) {
|
|
lombokNode = lombokNode.up();
|
|
} else {
|
|
ArrayList arrayList = new ArrayList();
|
|
LombokNode up = lombokNode.up();
|
|
if (up == null || up.getKind() == AST.Kind.COMPILATION_UNIT) {
|
|
StringBuilder sb = new StringBuilder();
|
|
if (this.ast.getPackageDeclaration() != null) {
|
|
sb.append(this.ast.getPackageDeclaration());
|
|
}
|
|
if (sb.length() > 0) {
|
|
sb.append('.');
|
|
}
|
|
Collections.reverse(arrayList);
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
sb.append((String) it.next()).append('.');
|
|
}
|
|
sb.append(str);
|
|
return sb.toString();
|
|
} else if (up.getKind() == AST.Kind.TYPE) {
|
|
arrayList.add(up.getName());
|
|
}
|
|
}
|
|
}
|
|
if (substring.equals(str) && (fullyQualifiedNameForSimpleName = this.ast.getImportList().getFullyQualifiedNameForSimpleName(str)) != null) {
|
|
return fullyQualifiedNameForSimpleName;
|
|
}
|
|
Iterator<String> it2 = this.ast.getImportList().applyNameToStarImports("java", str).iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
cls = Class.forName(it2.next());
|
|
} catch (Throwable unused) {
|
|
}
|
|
if (cls != null) {
|
|
return cls.getName();
|
|
}
|
|
continue;
|
|
}
|
|
if (str.indexOf(46) == -1) {
|
|
return inLocalPackage(this.ast, str);
|
|
}
|
|
char charAt = str.charAt(0);
|
|
return (Character.isTitleCase(charAt) || Character.isUpperCase(charAt)) ? inLocalPackage(this.ast, str) : str;
|
|
}
|
|
|
|
private static String inLocalPackage(LombokNode<?, ?, ?> lombokNode, String str) {
|
|
StringBuilder sb = new StringBuilder();
|
|
if (!(lombokNode == null || lombokNode.getPackageDeclaration() == null)) {
|
|
sb.append(lombokNode.getPackageDeclaration());
|
|
}
|
|
if (sb.length() > 0) {
|
|
sb.append('.');
|
|
}
|
|
sb.append(str);
|
|
return sb.toString();
|
|
}
|
|
|
|
static /* synthetic */ Map access$0(AnnotationValues annotationValues) {
|
|
return annotationValues.values;
|
|
}
|
|
|
|
static /* synthetic */ AnnotationValueDecodeFail access$1(AnnotationValue annotationValue, Method method) {
|
|
return makeNoDefaultFail(annotationValue, method);
|
|
}
|
|
|
|
static /* synthetic */ Object access$2(AnnotationValues annotationValues, Object obj, Class cls, AnnotationValue annotationValue, int i) {
|
|
return annotationValues.guessToType(obj, cls, annotationValue, i);
|
|
}
|
|
}
|