mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-22 03:24:49 +01:00
feat: allow to register manually written IInjectors
This commit is contained in:
parent
abd9954ed3
commit
3344fd766f
2 changed files with 31 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {}
|
Loading…
Reference in a new issue