mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-22 10:04:51 +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.AmbiguousDefinitionException;
|
||||||
import ftbsc.lll.exceptions.InvalidResourceException;
|
import ftbsc.lll.exceptions.InvalidResourceException;
|
||||||
import ftbsc.lll.exceptions.OrphanElementException;
|
import ftbsc.lll.exceptions.OrphanElementException;
|
||||||
import ftbsc.lll.processor.annotations.Find;
|
import ftbsc.lll.processor.annotations.*;
|
||||||
import ftbsc.lll.processor.annotations.Injector;
|
|
||||||
import ftbsc.lll.processor.annotations.Patch;
|
|
||||||
import ftbsc.lll.processor.annotations.Target;
|
|
||||||
import ftbsc.lll.processor.tools.containers.ClassContainer;
|
import ftbsc.lll.processor.tools.containers.ClassContainer;
|
||||||
import ftbsc.lll.processor.tools.containers.MethodContainer;
|
import ftbsc.lll.processor.tools.containers.MethodContainer;
|
||||||
import ftbsc.lll.processor.tools.obfuscation.ObfuscationMapper;
|
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.
|
* The actual annotation processor behind the magic.
|
||||||
* It (implicitly) implements the {@link Processor} interface by extending {@link AbstractProcessor}.
|
* 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)
|
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
||||||
@SupportedOptions({"mappingsFile", "anonymousClassWarning", "obfuscateInjectorMetadata"})
|
@SupportedOptions({"mappingsFile", "anonymousClassWarning", "obfuscateInjectorMetadata"})
|
||||||
public class LilleroProcessor extends AbstractProcessor {
|
public class LilleroProcessor extends AbstractProcessor {
|
||||||
|
@ -144,15 +141,19 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
.map(e -> (TypeElement) e)
|
.map(e -> (TypeElement) e)
|
||||||
.filter(this::isValidInjector)
|
.filter(this::isValidInjector)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
if(!validInjectors.isEmpty()) {
|
if(!validInjectors.isEmpty())
|
||||||
validInjectors.forEach(this::generateClasses);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.generatedInjectors.isEmpty()) {
|
if (!this.generatedInjectors.isEmpty()) {
|
||||||
generateServiceProvider();
|
generateServiceProvider();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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