mirror of
https://github.com/zaaarf/lillero-processor.git
synced 2024-11-25 12:04:49 +01:00
feat: generate dummies for all abstract methods, not just targets
This commit is contained in:
parent
5973cf6d95
commit
527cef56e6
2 changed files with 19 additions and 16 deletions
|
@ -346,7 +346,7 @@ public class LilleroProcessor extends AbstractProcessor {
|
||||||
.addMethod(buildStringReturnMethod("targetClass", obfuscateInjectorMetadata ? targetClass.fqnObf : targetClass.fqn))
|
.addMethod(buildStringReturnMethod("targetClass", obfuscateInjectorMetadata ? targetClass.fqnObf : targetClass.fqn))
|
||||||
.addMethod(buildStringReturnMethod("methodName", obfuscateInjectorMetadata ? target.nameObf : target.name))
|
.addMethod(buildStringReturnMethod("methodName", obfuscateInjectorMetadata ? target.nameObf : target.name))
|
||||||
.addMethod(buildStringReturnMethod("methodDesc", obfuscateInjectorMetadata ? target.descriptorObf : target.descriptor))
|
.addMethod(buildStringReturnMethod("methodDesc", obfuscateInjectorMetadata ? target.descriptorObf : target.descriptor))
|
||||||
.addMethods(generateDummies(targets))
|
.addMethods(generateDummies(cl))
|
||||||
.addMethod(generateInjector(toGenerate.get(injName), this.processingEnv))
|
.addMethod(generateInjector(toGenerate.get(injName), this.processingEnv))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,7 @@ import ftbsc.lll.proxies.impl.FieldProxy;
|
||||||
import ftbsc.lll.proxies.impl.MethodProxy;
|
import ftbsc.lll.proxies.impl.MethodProxy;
|
||||||
|
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.*;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
|
||||||
import javax.lang.model.element.Modifier;
|
|
||||||
import javax.lang.model.element.VariableElement;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import static ftbsc.lll.processor.tools.ASTUtils.getProxyType;
|
import static ftbsc.lll.processor.tools.ASTUtils.getProxyType;
|
||||||
|
@ -121,19 +117,26 @@ public class JavaPoetUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a {@link HashSet} of dummy overrides given a {@link Collection} stubs.
|
* Generates a {@link HashSet} of dummy overrides for every abstract method in a given class,
|
||||||
* @param dummies the stubs
|
* represented as a {@link TypeElement}.
|
||||||
|
* @param clazz the given class
|
||||||
* @return a {@link HashSet} containing the generated {@link MethodSpec}s
|
* @return a {@link HashSet} containing the generated {@link MethodSpec}s
|
||||||
* @since 0.5.0
|
* @since 0.5.0
|
||||||
*/
|
*/
|
||||||
public static HashSet<MethodSpec> generateDummies(Collection<ExecutableElement> dummies) {
|
public static HashSet<MethodSpec> generateDummies(TypeElement clazz) {
|
||||||
HashSet<MethodSpec> specs = new HashSet<>();
|
HashSet<MethodSpec> specs = new HashSet<>();
|
||||||
for(ExecutableElement d : dummies)
|
clazz
|
||||||
if(d.getModifiers().contains(Modifier.ABSTRACT))
|
.getEnclosedElements()
|
||||||
specs.add(MethodSpec.overriding(d)
|
.stream()
|
||||||
|
.filter(e -> e instanceof ExecutableElement)
|
||||||
|
.map(e -> (ExecutableElement) e)
|
||||||
|
.forEach(e -> {
|
||||||
|
if(e.getModifiers().contains(Modifier.ABSTRACT))
|
||||||
|
specs.add(MethodSpec.overriding(e)
|
||||||
.addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
|
.addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
});
|
||||||
return specs;
|
return specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue