diff options
author | zaaarf <zaaarf@proton.me> | 2023-04-12 19:26:22 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-04-12 19:26:22 +0200 |
commit | fbd3d0c35aea631fa69c453f933af4737158bb57 (patch) | |
tree | 0abe70a2dfd9963eacb3c2453988a73fdf92284d | |
parent | ee12ab20c13577424d36e913863364324d0ac6b9 (diff) |
fix: skip invalid bare injectors
-rw-r--r-- | src/main/java/ftbsc/lll/processor/LilleroProcessor.java | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index eb1a3a6..f70c58a 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -134,7 +134,7 @@ public class LilleroProcessor extends AbstractProcessor { */ @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { - for (TypeElement annotation : annotations) { + for(TypeElement annotation : annotations) { if(annotation.getQualifiedName().contentEquals(Patch.class.getName())) { Set<TypeElement> validInjectors = roundEnv.getElementsAnnotatedWith(annotation) @@ -145,17 +145,21 @@ public class LilleroProcessor extends AbstractProcessor { if(!validInjectors.isEmpty()) validInjectors.forEach(this::generateClasses); } else if(annotation.getQualifiedName().contentEquals(RegisterBareInjector.class.getName())) { - for(Element e : roundEnv.getElementsAnnotatedWith(annotation)) - this.generatedInjectors.add(((TypeElement) e).getQualifiedName().toString()); + TypeMirror injectorType = this.processingEnv.getElementUtils().getTypeElement("ftbsc.lll.IInjector").asType(); + for(Element e : roundEnv.getElementsAnnotatedWith(annotation)) { + if(this.processingEnv.getTypeUtils().isAssignable(e.asType(), injectorType)) + this.generatedInjectors.add(((TypeElement) e).getQualifiedName().toString()); + else this.processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, String.format( + "Class %s annotated with @RegisterBareInjector is not an instance of IInjector, skipping...", + ((TypeElement) e).getQualifiedName().toString() + )); + } } } - if (!this.generatedInjectors.isEmpty()) { generateServiceProvider(); return true; - } - - return false; + } else return false; } /** @@ -168,7 +172,7 @@ public class LilleroProcessor extends AbstractProcessor { private boolean isValidInjector(TypeElement elem) { TypeMirror classNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.ClassNode").asType(); TypeMirror methodNodeType = this.processingEnv.getElementUtils().getTypeElement("org.objectweb.asm.tree.MethodNode").asType(); - if (elem.getEnclosedElements().stream().anyMatch(e -> e.getAnnotation(Target.class) != null) + if(elem.getEnclosedElements().stream().anyMatch(e -> e.getAnnotation(Target.class) != null) && elem.getEnclosedElements().stream().filter(e -> e instanceof ExecutableElement).anyMatch(e -> { List<? extends TypeMirror> params = ((ExecutableType) e.asType()).getParameterTypes(); return e.getAnnotation(Injector.class) != null |