From bee16a300dd2d2a691ecc4625e2922ee1ad9b94d Mon Sep 17 00:00:00 2001 From: zaaarf Date: Fri, 25 Aug 2023 02:16:50 +0200 Subject: fix: can't access the ProcessingEnv before init() --- .../java/ftbsc/geb/processor/GEBProcessor.java | 47 +++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/java/ftbsc/geb/processor/GEBProcessor.java b/src/main/java/ftbsc/geb/processor/GEBProcessor.java index 79633ce..926173a 100644 --- a/src/main/java/ftbsc/geb/processor/GEBProcessor.java +++ b/src/main/java/ftbsc/geb/processor/GEBProcessor.java @@ -9,6 +9,7 @@ import ftbsc.geb.exceptions.BadListenerArgumentsException; import ftbsc.geb.exceptions.MissingInterfaceException; import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.element.*; @@ -40,6 +41,34 @@ public class GEBProcessor extends AbstractProcessor { */ private final Set generatedClasses = new HashSet<>(); + /** + * A {@link TypeMirror} representing the {@link IListener} interface. + */ + private TypeMirror listenerInterface; + + /** + * A {@link TypeMirror} representing the {@link IEvent} interface. + */ + private TypeMirror eventInterface; + + /** + * A {@link TypeMirror} representing the {@link IEventDispatcher} interface. + */ + private TypeMirror dispatcherInterface; + + /** + * Initializes the processor with the given environment. + * Also takes carae of initializing the TypeMirror "constants" for later use. + * @param env the environment + */ + @Override + public synchronized void init(ProcessingEnvironment env) { + super.init(env); + listenerInterface = env.getElementUtils().getTypeElement("ftbsc.geb.api.IListener").asType(); + eventInterface = env.getElementUtils().getTypeElement("ftbsc.geb.api.IEvent").asType(); + dispatcherInterface = env.getElementUtils().getTypeElement("ftbsc.geb.api.IEventDispatcher").asType(); + } + /** * The starting point of the processor. * It calls {@link #processListener(Element)} on all elements annotated with @@ -66,24 +95,6 @@ public class GEBProcessor extends AbstractProcessor { return claimed; } - /** - * A {@link TypeMirror} representing the {@link IListener} interface. - */ - private final TypeMirror listenerInterface = this.processingEnv.getElementUtils() - .getTypeElement("ftbsc.geb.api.IListener").asType(); - - /** - * A {@link TypeMirror} representing the {@link IEvent} interface. - */ - private final TypeMirror eventInterface = this.processingEnv.getElementUtils() - .getTypeElement("ftbsc.geb.api.IEvent").asType(); - - /** - * A {@link TypeMirror} representing the {@link IEventDispatcher} interface. - */ - private final TypeMirror dispatcherInterface = this.processingEnv.getElementUtils() - .getTypeElement("ftbsc.geb.api.IEventDispatcher").asType(); - /** * Verifies that the annotated method is valid and, if it is, adds it to * the list. See the annotation's javadoc for details on what's considered -- cgit v1.2.3-56-ga3b1