diff options
author | zaaarf <zaaarf@proton.me> | 2023-04-12 14:04:25 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-04-12 14:04:25 +0200 |
commit | 3344fd766f6e7e0e405c3c2b4c02a8b7e05c7e3c (patch) | |
tree | 6813abeda018dab1fbaaa442cc46f00e0daff29c /src/main/java/ftbsc/lll/processor | |
parent | abd9954ed3250f99a77f770fcdf9d41c75fd90a4 (diff) |
feat: allow to register manually written IInjectors
Diffstat (limited to 'src/main/java/ftbsc/lll/processor')
-rw-r--r-- | src/main/java/ftbsc/lll/processor/LilleroProcessor.java | 25 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/processor/annotations/RegisterBareInjector.java | 18 |
2 files changed, 31 insertions, 12 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index 9f1b996..15e1cd3 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -5,10 +5,7 @@ import ftbsc.lll.IInjector; import ftbsc.lll.exceptions.AmbiguousDefinitionException; import ftbsc.lll.exceptions.InvalidResourceException; import ftbsc.lll.exceptions.OrphanElementException; -import ftbsc.lll.processor.annotations.Find; -import ftbsc.lll.processor.annotations.Injector; -import ftbsc.lll.processor.annotations.Patch; -import ftbsc.lll.processor.annotations.Target; +import ftbsc.lll.processor.annotations.*; import ftbsc.lll.processor.tools.containers.ClassContainer; import ftbsc.lll.processor.tools.containers.MethodContainer; import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper; @@ -38,7 +35,7 @@ import static ftbsc.lll.processor.tools.JavaPoetUtils.*; * The actual annotation processor behind the magic. * It (implicitly) implements the {@link Processor} interface by extending {@link AbstractProcessor}. */ -@SupportedAnnotationTypes("ftbsc.lll.processor.annotations.Patch") +@SupportedAnnotationTypes({"ftbsc.lll.processor.annotations.Patch", "ftbsc.lll.processor.annotations.RegisterBareInjector"}) @SupportedSourceVersion(SourceVersion.RELEASE_8) @SupportedOptions({"mappingsFile", "anonymousClassWarning", "obfuscateInjectorMetadata"}) public class LilleroProcessor extends AbstractProcessor { @@ -144,15 +141,19 @@ public class LilleroProcessor extends AbstractProcessor { .map(e -> (TypeElement) e) .filter(this::isValidInjector) .collect(Collectors.toSet()); - if(!validInjectors.isEmpty()) { + if(!validInjectors.isEmpty()) validInjectors.forEach(this::generateClasses); - if (!this.generatedInjectors.isEmpty()) { - generateServiceProvider(); - return true; - } - } + } else if(annotation.getQualifiedName().contentEquals(RegisterBareInjector.class.getName())) { + for(Element e : roundEnv.getElementsAnnotatedWith(annotation)) + this.generatedInjectors.add(((TypeElement) e).getQualifiedName().toString()); } } + + if (!this.generatedInjectors.isEmpty()) { + generateServiceProvider(); + return true; + } + return false; } @@ -437,4 +438,4 @@ public class LilleroProcessor extends AbstractProcessor { this.target = MethodContainer.from(targetStub, targetAnn, null, processingEnv, mapper); } } -}
\ No newline at end of file +} diff --git a/src/main/java/ftbsc/lll/processor/annotations/RegisterBareInjector.java b/src/main/java/ftbsc/lll/processor/annotations/RegisterBareInjector.java new file mode 100644 index 0000000..1340bf7 --- /dev/null +++ b/src/main/java/ftbsc/lll/processor/annotations/RegisterBareInjector.java @@ -0,0 +1,18 @@ +package ftbsc.lll.processor.annotations; + +import ftbsc.lll.IInjector; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Marks the class in question as a class to be added to the service provider file + * (META-INF/services/ftbsc.lll.IInjector) without actually processing it. This can + * be used to mix in a same project regular {@link IInjector}s and those generated + * by the processor. + * @since 0.6.0 + */ +@Retention(RetentionPolicy.CLASS) +@java.lang.annotation.Target(ElementType.TYPE) +public @interface RegisterBareInjector {} |