From 3f730c69d3360ae7af030e9e5a4ebd065f8bb05a Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sun, 11 Jun 2023 15:55:22 +0200 Subject: [PATCH] fix: don't call processingEnv before it's initialised --- .../ftbsc/lll/processor/LilleroProcessor.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index b1d1f1e..0e170ee 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -48,7 +48,7 @@ public class LilleroProcessor extends AbstractProcessor { /** * An object representing the various options passed to the processor. */ - public final ProcessorOptions options = new ProcessorOptions(processingEnv); + private ProcessorOptions options = null; /** * Method overriding default implementation to manually pass supported options. @@ -59,6 +59,16 @@ public class LilleroProcessor extends AbstractProcessor { return ProcessorOptions.SUPPORTED; } + /** + * Returns the {@link ProcessorOptions} for this instance, creating the object if + * it hasn't been already. + * @return the {@link ProcessorOptions} for this instance + */ + public ProcessorOptions getProcessorOptions() { + if(this.options == null) this.options = new ProcessorOptions(this.processingEnv); + return this.options; + } + /** * Where the actual processing happens. * It filters through whatever annotated class it's fed, and checks whether it contains @@ -90,7 +100,7 @@ public class LilleroProcessor extends AbstractProcessor { } } } - if (!this.options.noServiceProvider && !this.injectors.isEmpty()) { + if (!this.getProcessorOptions().noServiceProvider && !this.injectors.isEmpty()) { generateServiceProvider(); return true; } else return false; @@ -134,7 +144,7 @@ public class LilleroProcessor extends AbstractProcessor { //find class information Patch patchAnn = cl.getAnnotation(Patch.class); ClassContainer targetClass = ClassContainer.from( - patchAnn, Patch::value, patchAnn.innerName(), this.options + patchAnn, Patch::value, patchAnn.innerName(), this.getProcessorOptions() ); //find package information Element packageElement = cl.getEnclosingElement(); @@ -165,10 +175,10 @@ public class LilleroProcessor extends AbstractProcessor { if(type == ProxyType.TYPE) { //find and validate ClassContainer clazz = ClassContainer.findOrFallback( - ClassContainer.from(cl, this.options), + ClassContainer.from(cl, this.getProcessorOptions()), patchAnn, proxyVar.getAnnotation(Find.class), - this.options + this.getProcessorOptions() ); //types can be generated with a single instruction constructorBuilder.addStatement( @@ -184,7 +194,7 @@ public class LilleroProcessor extends AbstractProcessor { null, null, constructorBuilder, - this.options + this.getProcessorOptions() ); } @@ -243,7 +253,7 @@ public class LilleroProcessor extends AbstractProcessor { matchedInjectors.add(injector); toGenerate.put( String.format("%sInjector%d", cl.getSimpleName(), iterationNumber), - new InjectorInfo(injector, tg, targetAnn, this.options) + new InjectorInfo(injector, tg, targetAnn, this.getProcessorOptions()) ); iterationNumber++; //increment is only used by injectors } else { @@ -255,7 +265,7 @@ public class LilleroProcessor extends AbstractProcessor { tg, targetAnn, constructorBuilder, - this.options + this.getProcessorOptions() ); } } @@ -280,9 +290,9 @@ public class LilleroProcessor extends AbstractProcessor { .addMethod(constructorBuilder.build()) .addMethod(buildStringReturnMethod("name", injName)) .addMethod(buildStringReturnMethod("reason", toGenerate.get(injName).reason)) - .addMethod(buildStringReturnMethod("targetClass", this.options.obfuscateInjectorMetadata ? targetClass.fqnObf : targetClass.fqn)) - .addMethod(buildStringReturnMethod("methodName", this.options.obfuscateInjectorMetadata ? target.nameObf : target.name)) - .addMethod(buildStringReturnMethod("methodDesc", this.options.obfuscateInjectorMetadata ? target.descriptorObf : target.descriptor)) + .addMethod(buildStringReturnMethod("targetClass", this.getProcessorOptions().obfuscateInjectorMetadata ? targetClass.fqnObf : targetClass.fqn)) + .addMethod(buildStringReturnMethod("methodName", this.getProcessorOptions().obfuscateInjectorMetadata ? target.nameObf : target.name)) + .addMethod(buildStringReturnMethod("methodDesc", this.getProcessorOptions().obfuscateInjectorMetadata ? target.descriptorObf : target.descriptor)) .addMethods(generateDummies(cl)) .addMethod(generateInjector(toGenerate.get(injName), this.processingEnv)) .build();