fix: removed unsafeOverride, i had a brainfart

This commit is contained in:
zaaarf 2023-03-15 20:07:27 +01:00
parent d93f9388e8
commit a425ce62f9
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C

View file

@ -421,7 +421,7 @@ public class LilleroProcessor extends AbstractProcessor {
throw new AmbiguousDefinitionException(String.format("Unclear target for injector %s::%s!", cl.getSimpleName(), inj.getSimpleName()));
else toGenerate.put(
String.format("%sInjector%d", cl.getSimpleName(), iterationNumber),
new InjectorInfo(inj, findRealMethodFromStub(injectionTarget))
new InjectorInfo(inj, injectionTarget)
);
iterationNumber++;
}
@ -432,7 +432,7 @@ public class LilleroProcessor extends AbstractProcessor {
String targetMethodDescriptor = descriptorFromExecutableElement(toGenerate.get(injName).target);
String targetMethodName = findMemberName(targetClassFQN, toGenerate.get(injName).target.getSimpleName().toString(), targetMethodDescriptor, this.mapper);
MethodSpec stubOverride = unsafeOverriding(toGenerate.get(injName).target)
MethodSpec stubOverride = MethodSpec.overriding(toGenerate.get(injName).target)
.addStatement("throw new $T($S)", RuntimeException.class, "This is a stub and should not have been called")
.build();
@ -496,35 +496,6 @@ public class LilleroProcessor extends AbstractProcessor {
.build();
}
/**
* Identical to {@link MethodSpec#overriding(ExecutableElement)}, but does not check for
* the accessor level of the target method. May be used to override package-private methods
* that are technically classified as private, but may be accessed under certain conditions.
* @param target the method to override
* @return the built method spec
* @since 0.3.0
* @see MethodSpec#overriding(ExecutableElement)
*/
private static MethodSpec.Builder unsafeOverriding(ExecutableElement target) {
MethodSpec.Builder bd =
MethodSpec.methodBuilder(target.getSimpleName().toString())
.addAnnotation(Override.class)
.addModifiers(target.getModifiers())
.returns(TypeName.get(target.getReturnType()));
bd.modifiers.remove(Modifier.DEFAULT);
bd.modifiers.remove(Modifier.ABSTRACT);
for (TypeParameterElement typeParameterElement : target.getTypeParameters()) {
TypeVariable var = (TypeVariable) typeParameterElement.asType();
bd.addTypeVariable(TypeVariableName.get(var));
}
for(VariableElement p : target.getParameters())
bd.addParameter(TypeName.get(p.asType()), p.getSimpleName().toString(), p.getModifiers().toArray(new Modifier[0]));
bd.varargs(target.isVarArgs());
for(TypeMirror thrownType : target.getThrownTypes())
bd.addException(TypeName.get(thrownType));
return bd;
}
/**
* Finds any method annotated with {@link FindMethod} or {@link FindField} within the given
* class, and builds the {@link MethodSpec} necessary for building it.
@ -540,7 +511,7 @@ public class LilleroProcessor extends AbstractProcessor {
.filter(m -> !m.getModifiers().contains(Modifier.FINAL)) //in case someone is trying to be funny
.forEach(m -> {
ExecutableElement targetMethod = findRealMethodFromStub(m);
MethodSpec.Builder b = unsafeOverriding(m);
MethodSpec.Builder b = MethodSpec.overriding(m);
String targetParentFQN = findClassName(((TypeElement) targetMethod.getEnclosingElement()).getQualifiedName().toString(), mapper);
@ -569,7 +540,7 @@ public class LilleroProcessor extends AbstractProcessor {
.filter(m -> !m.getModifiers().contains(Modifier.FINAL))
.forEach(m -> {
VariableElement targetField = findField(m);
MethodSpec.Builder b = unsafeOverriding(m);
MethodSpec.Builder b = MethodSpec.overriding(m);
String targetParentFQN = findClassName(((TypeElement) targetField.getEnclosingElement()).getQualifiedName().toString(), mapper);