diff options
author | zaaarf <zaaarf@proton.me> | 2023-03-15 20:07:27 +0100 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-03-15 20:07:27 +0100 |
commit | a425ce62f9c9db49dde81c3bc437451c69f0a363 (patch) | |
tree | 4ed87dcd3232c533f59197ff679b3a0bfefe753f /src/main/java/ftbsc/lll | |
parent | d93f9388e80af18ef1729c1ff47eaa7f88bf00fc (diff) |
fix: removed unsafeOverride, i had a brainfart
Diffstat (limited to 'src/main/java/ftbsc/lll')
-rw-r--r-- | src/main/java/ftbsc/lll/processor/LilleroProcessor.java | 37 |
1 files changed, 4 insertions, 33 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index 1e3bf40..2040f20 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -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(); @@ -497,35 +497,6 @@ public class LilleroProcessor extends AbstractProcessor { } /** - * 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. * @param cl the class to search @@ -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); |