247 lines
11 KiB
Java
247 lines
11 KiB
Java
package lombok.javac;
|
|
|
|
import com.sun.source.util.Trees;
|
|
import com.sun.tools.javac.tree.JCTree;
|
|
import java.io.IOException;
|
|
import java.lang.annotation.Annotation;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.SortedSet;
|
|
import java.util.TreeSet;
|
|
import javax.annotation.processing.Messager;
|
|
import javax.tools.Diagnostic;
|
|
import lombok.core.AlreadyHandledAnnotations;
|
|
import lombok.core.AnnotationValues;
|
|
import lombok.core.HandlerPriority;
|
|
import lombok.core.SpiLoadUtil;
|
|
import lombok.core.TypeLibrary;
|
|
import lombok.core.TypeResolver;
|
|
import lombok.core.configuration.ConfigurationKeysLoader;
|
|
import lombok.javac.handlers.JavacHandlerUtil;
|
|
/* loaded from: com.discord-121110.apk:lombok/javac/HandlerLibrary.SCL.lombok */
|
|
public class HandlerLibrary {
|
|
private final TypeLibrary typeLibrary = new TypeLibrary();
|
|
private final Map<String, List<AnnotationHandlerContainer<?>>> annotationHandlers = new HashMap();
|
|
private final Collection<VisitorContainer> visitorHandlers = new ArrayList();
|
|
private final Messager messager;
|
|
private SortedSet<Long> priorities;
|
|
private SortedSet<Long> prioritiesRequiringResolutionReset;
|
|
|
|
/* loaded from: com.discord-121110.apk:lombok/javac/HandlerLibrary$AnnotationHandlerContainer.SCL.lombok */
|
|
private static class AnnotationHandlerContainer<T extends Annotation> {
|
|
private final JavacAnnotationHandler<T> handler;
|
|
private final Class<T> annotationClass;
|
|
private final long priority;
|
|
private final boolean resolutionResetNeeded;
|
|
private final boolean evenIfAlreadyHandled;
|
|
|
|
AnnotationHandlerContainer(JavacAnnotationHandler<T> javacAnnotationHandler, Class<T> cls) {
|
|
this.handler = javacAnnotationHandler;
|
|
this.annotationClass = cls;
|
|
HandlerPriority handlerPriority = (HandlerPriority) javacAnnotationHandler.getClass().getAnnotation(HandlerPriority.class);
|
|
this.priority = handlerPriority == null ? 0L : (handlerPriority.value() << 32) + handlerPriority.subValue();
|
|
this.resolutionResetNeeded = javacAnnotationHandler.getClass().isAnnotationPresent(ResolutionResetNeeded.class);
|
|
this.evenIfAlreadyHandled = javacAnnotationHandler.getClass().isAnnotationPresent(AlreadyHandledAnnotations.class);
|
|
}
|
|
|
|
public void handle(JavacNode javacNode) {
|
|
this.handler.handle(JavacHandlerUtil.createAnnotation(this.annotationClass, javacNode), javacNode.get(), javacNode);
|
|
}
|
|
|
|
public long getPriority() {
|
|
return this.priority;
|
|
}
|
|
|
|
public boolean isResolutionResetNeeded() {
|
|
return this.resolutionResetNeeded;
|
|
}
|
|
|
|
public boolean isEvenIfAlreadyHandled() {
|
|
return this.evenIfAlreadyHandled;
|
|
}
|
|
|
|
static /* synthetic */ Class access$0(AnnotationHandlerContainer annotationHandlerContainer) {
|
|
return annotationHandlerContainer.annotationClass;
|
|
}
|
|
|
|
static /* synthetic */ JavacAnnotationHandler access$1(AnnotationHandlerContainer annotationHandlerContainer) {
|
|
return annotationHandlerContainer.handler;
|
|
}
|
|
}
|
|
|
|
/* loaded from: com.discord-121110.apk:lombok/javac/HandlerLibrary$VisitorContainer.SCL.lombok */
|
|
private static class VisitorContainer {
|
|
private final JavacASTVisitor visitor;
|
|
private final long priority;
|
|
private final boolean resolutionResetNeeded;
|
|
|
|
VisitorContainer(JavacASTVisitor javacASTVisitor) {
|
|
this.visitor = javacASTVisitor;
|
|
HandlerPriority handlerPriority = (HandlerPriority) javacASTVisitor.getClass().getAnnotation(HandlerPriority.class);
|
|
this.priority = handlerPriority == null ? 0L : (handlerPriority.value() << 32) + handlerPriority.subValue();
|
|
this.resolutionResetNeeded = javacASTVisitor.getClass().isAnnotationPresent(ResolutionResetNeeded.class);
|
|
}
|
|
|
|
public long getPriority() {
|
|
return this.priority;
|
|
}
|
|
|
|
public boolean isResolutionResetNeeded() {
|
|
return this.resolutionResetNeeded;
|
|
}
|
|
|
|
static /* synthetic */ JavacASTVisitor access$0(VisitorContainer visitorContainer) {
|
|
return visitorContainer.visitor;
|
|
}
|
|
}
|
|
|
|
public HandlerLibrary(Messager messager) {
|
|
ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys();
|
|
this.messager = messager;
|
|
}
|
|
|
|
public SortedSet<Long> getPriorities() {
|
|
return this.priorities;
|
|
}
|
|
|
|
public SortedSet<Long> getPrioritiesRequiringResolutionReset() {
|
|
return this.prioritiesRequiringResolutionReset;
|
|
}
|
|
|
|
private void calculatePriorities() {
|
|
TreeSet treeSet = new TreeSet();
|
|
TreeSet treeSet2 = new TreeSet();
|
|
Iterator<List<AnnotationHandlerContainer<?>>> it = this.annotationHandlers.values().iterator();
|
|
while (it.hasNext()) {
|
|
Iterator<AnnotationHandlerContainer<?>> it2 = it.next().iterator();
|
|
while (it2.hasNext()) {
|
|
AnnotationHandlerContainer<?> next = it2.next();
|
|
treeSet.add(Long.valueOf(next.getPriority()));
|
|
if (next.isResolutionResetNeeded()) {
|
|
treeSet2.add(Long.valueOf(next.getPriority()));
|
|
}
|
|
}
|
|
}
|
|
Iterator<VisitorContainer> it3 = this.visitorHandlers.iterator();
|
|
while (it3.hasNext()) {
|
|
VisitorContainer next2 = it3.next();
|
|
treeSet.add(Long.valueOf(next2.getPriority()));
|
|
if (next2.isResolutionResetNeeded()) {
|
|
treeSet2.add(Long.valueOf(next2.getPriority()));
|
|
}
|
|
}
|
|
this.priorities = Collections.unmodifiableSortedSet(treeSet);
|
|
this.prioritiesRequiringResolutionReset = Collections.unmodifiableSortedSet(treeSet2);
|
|
}
|
|
|
|
public static HandlerLibrary load(Messager messager, Trees trees) {
|
|
HandlerLibrary handlerLibrary = new HandlerLibrary(messager);
|
|
try {
|
|
loadAnnotationHandlers(handlerLibrary, trees);
|
|
loadVisitorHandlers(handlerLibrary, trees);
|
|
} catch (IOException e) {
|
|
System.err.println("Lombok isn't running due to misconfigured SPI files: " + e);
|
|
}
|
|
handlerLibrary.calculatePriorities();
|
|
return handlerLibrary;
|
|
}
|
|
|
|
private static void loadAnnotationHandlers(HandlerLibrary handlerLibrary, Trees trees) throws IOException {
|
|
Iterator it = SpiLoadUtil.findServices(JavacAnnotationHandler.class, JavacAnnotationHandler.class.getClassLoader()).iterator();
|
|
while (it.hasNext()) {
|
|
JavacAnnotationHandler javacAnnotationHandler = (JavacAnnotationHandler) it.next();
|
|
javacAnnotationHandler.setTrees(trees);
|
|
AnnotationHandlerContainer<?> annotationHandlerContainer = new AnnotationHandlerContainer<>(javacAnnotationHandler, javacAnnotationHandler.getAnnotationHandledByThisHandler());
|
|
String replace = AnnotationHandlerContainer.access$0(annotationHandlerContainer).getName().replace("$", ".");
|
|
List<AnnotationHandlerContainer<?>> list = handlerLibrary.annotationHandlers.get(replace);
|
|
if (list == null) {
|
|
Map<String, List<AnnotationHandlerContainer<?>>> map = handlerLibrary.annotationHandlers;
|
|
ArrayList arrayList = new ArrayList(1);
|
|
list = arrayList;
|
|
map.put(replace, arrayList);
|
|
}
|
|
list.add(annotationHandlerContainer);
|
|
handlerLibrary.typeLibrary.addType(AnnotationHandlerContainer.access$0(annotationHandlerContainer).getName());
|
|
}
|
|
}
|
|
|
|
private static void loadVisitorHandlers(HandlerLibrary handlerLibrary, Trees trees) throws IOException {
|
|
Iterator it = SpiLoadUtil.findServices(JavacASTVisitor.class, JavacASTVisitor.class.getClassLoader()).iterator();
|
|
while (it.hasNext()) {
|
|
JavacASTVisitor javacASTVisitor = (JavacASTVisitor) it.next();
|
|
javacASTVisitor.setTrees(trees);
|
|
handlerLibrary.visitorHandlers.add(new VisitorContainer(javacASTVisitor));
|
|
}
|
|
}
|
|
|
|
public void javacWarning(String str) {
|
|
javacWarning(str, null);
|
|
}
|
|
|
|
public void javacWarning(String str, Throwable th) {
|
|
this.messager.printMessage(Diagnostic.Kind.WARNING, String.valueOf(str) + (th == null ? "" : ": " + th));
|
|
}
|
|
|
|
public void javacError(String str) {
|
|
javacError(str, null);
|
|
}
|
|
|
|
public void javacError(String str, Throwable th) {
|
|
this.messager.printMessage(Diagnostic.Kind.ERROR, String.valueOf(str) + (th == null ? "" : ": " + th));
|
|
if (th != null) {
|
|
th.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private boolean checkAndSetHandled(JCTree jCTree) {
|
|
return !JavacAugments.JCTree_handled.getAndSet(jCTree, true).booleanValue();
|
|
}
|
|
|
|
public void handleAnnotation(JCTree.JCCompilationUnit jCCompilationUnit, JavacNode javacNode, JCTree.JCAnnotation jCAnnotation, long j) {
|
|
List<AnnotationHandlerContainer<?>> list;
|
|
String typeRefToFullyQualifiedName = new TypeResolver(javacNode.getImportList()).typeRefToFullyQualifiedName(javacNode, this.typeLibrary, jCAnnotation.annotationType.toString());
|
|
if (typeRefToFullyQualifiedName != null && (list = this.annotationHandlers.get(typeRefToFullyQualifiedName)) != null) {
|
|
Iterator<AnnotationHandlerContainer<?>> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
AnnotationHandlerContainer<?> next = it.next();
|
|
try {
|
|
if (next.getPriority() == j) {
|
|
if (checkAndSetHandled(jCAnnotation)) {
|
|
next.handle(javacNode);
|
|
} else if (next.isEvenIfAlreadyHandled()) {
|
|
next.handle(javacNode);
|
|
}
|
|
}
|
|
} catch (AnnotationValues.AnnotationValueDecodeFail e) {
|
|
e.owner.setError(e.getMessage(), e.idx);
|
|
} catch (Throwable th) {
|
|
String str = "(unknown).java";
|
|
if (!(jCCompilationUnit == null || jCCompilationUnit.sourcefile == null)) {
|
|
str = jCCompilationUnit.sourcefile.getName();
|
|
}
|
|
javacError(String.format("Lombok annotation handler %s failed on " + str, AnnotationHandlerContainer.access$1(next).getClass()), th);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void callASTVisitors(JavacAST javacAST, long j) {
|
|
Iterator<VisitorContainer> it = this.visitorHandlers.iterator();
|
|
while (it.hasNext()) {
|
|
VisitorContainer next = it.next();
|
|
try {
|
|
if (next.getPriority() == j) {
|
|
javacAST.traverse(VisitorContainer.access$0(next));
|
|
}
|
|
} catch (Throwable th) {
|
|
javacError(String.format("Lombok visitor handler %s failed", VisitorContainer.access$0(next).getClass()), th);
|
|
}
|
|
}
|
|
}
|
|
}
|