discord-jadx/app/src/main/java/lombok/core/handlers/InclusionExclusionUtils.java

246 lines
12 KiB
Java

package lombok.core.handlers;
import com.discord.models.domain.ModelAuditLogEntry;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.core.AST;
import lombok.core.AnnotationValues;
import lombok.core.LombokNode;
/* loaded from: com.discord-117113.apk:lombok/core/handlers/InclusionExclusionUtils.SCL.lombok */
public class InclusionExclusionUtils {
/* renamed from: lombok.core.handlers.InclusionExclusionUtils$1 reason: invalid class name */
/* loaded from: com.discord-117113.apk:lombok/core/handlers/InclusionExclusionUtils$1.SCL.lombok */
class AnonymousClass1 implements Comparator<Included<L, ToString.Include>> {
AnonymousClass1() {
}
public int compare(Included<L, ToString.Include> included, Included<L, ToString.Include> included2) {
return InclusionExclusionUtils.access$0(included.getInc() == null ? 0 : included.getInc().rank(), included2.getInc() == null ? 0 : included2.getInc().rank(), (LombokNode) included.getNode(), (LombokNode) included2.getNode());
}
}
/* renamed from: lombok.core.handlers.InclusionExclusionUtils$2 reason: invalid class name */
/* loaded from: com.discord-117113.apk:lombok/core/handlers/InclusionExclusionUtils$2.SCL.lombok */
class AnonymousClass2 implements Comparator<Included<L, EqualsAndHashCode.Include>> {
AnonymousClass2() {
}
public int compare(Included<L, EqualsAndHashCode.Include> included, Included<L, EqualsAndHashCode.Include> included2) {
return InclusionExclusionUtils.access$0(included.hasExplicitRank() ? included.getInc().rank() : HandlerUtil.defaultEqualsAndHashcodeIncludeRank(((LombokNode) Included.access$0(included)).fieldOrMethodBaseType()), included2.hasExplicitRank() ? included2.getInc().rank() : HandlerUtil.defaultEqualsAndHashcodeIncludeRank(((LombokNode) Included.access$0(included2)).fieldOrMethodBaseType()), (LombokNode) included.getNode(), (LombokNode) included2.getNode());
}
}
/* loaded from: com.discord-117113.apk:lombok/core/handlers/InclusionExclusionUtils$Included.SCL.lombok */
public static class Included<L, I extends Annotation> {
private final L node;
private final I inc;
private final boolean defaultInclude;
private final boolean explicitRank;
public Included(L l, I i, boolean z2, boolean z3) {
this.node = l;
this.inc = i;
this.defaultInclude = z2;
this.explicitRank = z3;
}
public L getNode() {
return this.node;
}
public I getInc() {
return this.inc;
}
public boolean isDefaultInclude() {
return this.defaultInclude;
}
public boolean hasExplicitRank() {
return this.explicitRank;
}
static /* synthetic */ Object access$0(Included included) {
return included.node;
}
}
private static List<Integer> createListOfNonExistentFields(List<String> list, LombokNode<?, ?, ?> lombokNode, boolean z2, boolean z3) {
boolean[] zArr = new boolean[list.size()];
Iterator<?> it = lombokNode.down().iterator();
while (it.hasNext()) {
LombokNode lombokNode2 = (LombokNode) it.next();
if (list.isEmpty()) {
break;
} else if (lombokNode2.getKind() == AST.Kind.FIELD && (!z2 || (!lombokNode2.isStatic() && !lombokNode2.getName().startsWith("$")))) {
if (!z3 || !lombokNode2.isTransient()) {
int indexOf = list.indexOf(lombokNode2.getName());
if (indexOf > -1) {
zArr[indexOf] = true;
}
}
}
}
ArrayList arrayList = new ArrayList();
for (int i = 0; i < list.size(); i++) {
if (!zArr[i]) {
arrayList.add(Integer.valueOf(i));
}
}
return arrayList;
}
public static void checkForBogusFieldNames(LombokNode<?, ?, ?> lombokNode, AnnotationValues<?> annotationValues, List<String> list, List<String> list2) {
if (list != null && !list.isEmpty()) {
Iterator<Integer> it = createListOfNonExistentFields(list, lombokNode, true, false).iterator();
while (it.hasNext()) {
int intValue = it.next().intValue();
if (annotationValues != null) {
annotationValues.setWarning("exclude", "This field does not exist, or would have been excluded anyway.", intValue);
}
}
}
if (list2 != null && !list2.isEmpty()) {
Iterator<Integer> it2 = createListOfNonExistentFields(list2, lombokNode, false, false).iterator();
while (it2.hasNext()) {
int intValue2 = it2.next().intValue();
if (annotationValues != null) {
annotationValues.setWarning("of", "This field does not exist.", intValue2);
}
}
}
}
private static String innerAnnName(Class<? extends Annotation> cls) {
String simpleName = cls.getSimpleName();
for (Class<?> enclosingClass = cls.getEnclosingClass(); enclosingClass != null; enclosingClass = enclosingClass.getEnclosingClass()) {
simpleName = String.valueOf(enclosingClass.getSimpleName()) + "." + simpleName;
}
return simpleName;
}
private static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N, I extends Annotation> List<Included<L, I>> handleIncludeExcludeMarking(Class<I> cls, String str, Class<? extends Annotation> cls2, LombokNode<A, L, N> lombokNode, AnnotationValues<?> annotationValues, LombokNode<A, L, N> lombokNode2, boolean z2) {
List<String> asStringList = (annotationValues == null || !annotationValues.isExplicit("exclude")) ? null : annotationValues.getAsStringList("exclude");
List<String> asStringList2 = (annotationValues == null || !annotationValues.isExplicit("of")) ? null : annotationValues.getAsStringList("of");
boolean asBoolean = annotationValues != null ? annotationValues.getAsBoolean("onlyExplicitlyIncluded") : false;
boolean z3 = asBoolean;
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
if (lombokNode == null || lombokNode.getKind() != AST.Kind.TYPE) {
return null;
}
checkForBogusFieldNames(lombokNode, annotationValues, asStringList, asStringList2);
if (!(asStringList == null || asStringList2 == null)) {
asStringList = null;
if (annotationValues != null) {
annotationValues.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
}
}
Iterator<L> it = lombokNode.down().iterator();
while (it.hasNext()) {
L next = it.next();
boolean z4 = next.getKind() == AST.Kind.FIELD && next.hasAnnotation(cls2);
AnnotationValues annotationValues2 = null;
if (next.getKind() == AST.Kind.FIELD || next.getKind() == AST.Kind.METHOD) {
annotationValues2 = next.findAnnotation(cls);
}
if (z4 || annotationValues2 != null) {
z3 = true;
}
if (annotationValues2 != null && z4) {
next.addError("@" + innerAnnName(cls2) + " and @" + innerAnnName(cls) + " are mutually exclusive; the @Include annotation will be ignored");
annotationValues2 = null;
}
String name = next.getName();
if (z4) {
if (asBoolean) {
next.addWarning("The @Exclude annotation is not needed; 'onlyExplicitlyIncluded' is set, so this member would be excluded anyway");
} else if (next.isStatic()) {
next.addWarning("The @Exclude annotation is not needed; static fields aren't included anyway");
} else if (name.startsWith("$")) {
next.addWarning("The @Exclude annotation is not needed; fields that start with $ aren't included anyway");
}
} else if (asStringList == null || !asStringList.contains(name)) {
if (annotationValues2 != null) {
Annotation instance = annotationValues2.getInstance();
if (next.getKind() == AST.Kind.METHOD) {
if (next.countMethodParameters() > 0) {
next.addError("Methods included with @" + innerAnnName(cls) + " must have no arguments; it will not be included");
} else {
String asString = str != null ? annotationValues2.getAsString(str) : "";
if (asString.isEmpty()) {
asString = name;
}
arrayList2.add(asString);
}
}
arrayList.add(new Included(next, instance, false, annotationValues2.isExplicit("rank")));
} else if (!asBoolean) {
if (asStringList2 != null) {
if (next.getKind() == AST.Kind.FIELD && asStringList2.contains(name)) {
arrayList.add(new Included(next, null, false, false));
}
} else if (next.getKind() == AST.Kind.FIELD && !next.isStatic() && (!next.isTransient() || z2)) {
if (!name.startsWith("$") && !next.isEnumMember()) {
arrayList.add(new Included(next, null, true, false));
}
}
}
}
}
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
Included included = (Included) it2.next();
if (included.isDefaultInclude() && arrayList2.contains(((LombokNode) included.getNode()).getName())) {
it2.remove();
}
}
if (annotationValues == null || !annotationValues.isExplicit("exclude")) {
asStringList = null;
}
if (annotationValues == null || !annotationValues.isExplicit("of")) {
asStringList2 = null;
}
if (!z3 || (asStringList == null && asStringList2 == null)) {
return arrayList;
}
lombokNode2.addError("The old-style 'exclude/of' parameter cannot be used together with the new-style @Include / @Exclude annotations.");
return null;
}
public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, ToString.Include>> handleToStringMarking(LombokNode<A, L, N> lombokNode, AnnotationValues<ToString> annotationValues, LombokNode<A, L, N> lombokNode2) {
List<Included<L, ToString.Include>> handleIncludeExcludeMarking = handleIncludeExcludeMarking(ToString.Include.class, ModelAuditLogEntry.CHANGE_KEY_NAME, ToString.Exclude.class, lombokNode, annotationValues, lombokNode2, true);
Collections.sort(handleIncludeExcludeMarking, new AnonymousClass1());
return handleIncludeExcludeMarking;
}
public static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> List<Included<L, EqualsAndHashCode.Include>> handleEqualsAndHashCodeMarking(LombokNode<A, L, N> lombokNode, AnnotationValues<EqualsAndHashCode> annotationValues, LombokNode<A, L, N> lombokNode2) {
List<Included<L, EqualsAndHashCode.Include>> handleIncludeExcludeMarking = handleIncludeExcludeMarking(EqualsAndHashCode.Include.class, "replaces", EqualsAndHashCode.Exclude.class, lombokNode, annotationValues, lombokNode2, false);
Collections.sort(handleIncludeExcludeMarking, new AnonymousClass2());
return handleIncludeExcludeMarking;
}
private static <A extends AST<A, L, N>, L extends LombokNode<A, L, N>, N> int compareRankOrPosition(int i, int i2, LombokNode<A, L, N> lombokNode, LombokNode<A, L, N> lombokNode2) {
int startPos;
int startPos2;
if (i < i2) {
return 1;
}
if (i <= i2 && (startPos = lombokNode.getStartPos()) >= (startPos2 = lombokNode2.getStartPos())) {
return startPos > startPos2 ? 1 : 0;
}
return -1;
}
static /* synthetic */ int access$0(int i, int i2, LombokNode lombokNode, LombokNode lombokNode2) {
return compareRankOrPosition(i, i2, lombokNode, lombokNode2);
}
}