summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-08-25 02:16:50 +0200
committer zaaarf <zaaarf@proton.me>2023-08-25 02:16:50 +0200
commitbee16a300dd2d2a691ecc4625e2922ee1ad9b94d (patch)
treeb67dd52505da30699c8e446eda92a4a88ec7cc4f /src
parentf5cf9ae2362f119af59c0c8c4bb97af9f572f0ba (diff)
fix: can't access the ProcessingEnv before init()0.1.1
Diffstat (limited to 'src')
-rw-r--r--src/main/java/ftbsc/geb/processor/GEBProcessor.java47
1 files 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.*;
@@ -41,6 +42,34 @@ public class GEBProcessor extends AbstractProcessor {
private final Set<String> 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
* the {@link Listen} annotation.
@@ -67,24 +96,6 @@ public class GEBProcessor extends AbstractProcessor {
}
/**
- * 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
* a valid listener.