diff options
author | zaaarf <zaaarf@proton.me> | 2023-03-18 20:08:16 +0100 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-03-18 20:08:16 +0100 |
commit | 1f0db874780948f4483845284a2c5b57a0f2df4e (patch) | |
tree | e1d8c0918c0f275144862e60bf8a4b14c8ce528e /src/main | |
parent | 9f9a9d9324d4941b57c204c9d06ca5771fc5a04f (diff) |
fix: restored isPrimitive() check before converting to string
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/ftbsc/lll/processor/LilleroProcessor.java | 22 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java | 26 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java index c3d686e..c1c8c16 100644 --- a/src/main/java/ftbsc/lll/processor/LilleroProcessor.java +++ b/src/main/java/ftbsc/lll/processor/LilleroProcessor.java @@ -341,24 +341,10 @@ public class LilleroProcessor extends AbstractProcessor { if(isMethod) { ExecutableElement targetMethod = (ExecutableElement) target; - for(VariableElement p : targetMethod.getParameters()) { - ArrayContainer param = new ArrayContainer(p.asType()); - b.addStatement( - "bd.addParameter($S, $L)", - param.innermostComponent, - param.arrayLevel - ); - } - ArrayContainer ret = new ArrayContainer(targetMethod.getReturnType()); - b.addStatement( - "bd.setReturnType($S, $L)", - ret.innermostComponent, - ret.arrayLevel - ); - } else { - ArrayContainer arr = new ArrayContainer(target.asType()); - b.addStatement("bd.setType($S, $L)", arr.innermostComponent, arr.arrayLevel); - } + for(VariableElement p : targetMethod.getParameters()) + addTypeToProxyGenerator(b, "bd", "addParameter", p.asType()); + addTypeToProxyGenerator(b, "bd", "setReturnType", targetMethod.getReturnType()); + } else addTypeToProxyGenerator(b, "bd", "setType", target.asType()); b.addStatement("return bd.build()"); diff --git a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java index fe64488..51f058b 100644 --- a/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java +++ b/src/main/java/ftbsc/lll/processor/tools/JavaPoetUtils.java @@ -2,6 +2,8 @@ package ftbsc.lll.processor.tools; import com.squareup.javapoet.*; import ftbsc.lll.tools.DescriptorBuilder; +import ftbsc.lll.proxies.MethodProxy; +import ftbsc.lll.proxies.FieldProxy; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; @@ -109,4 +111,28 @@ public class JavaPoetUtils { sb.append(")"); return sb.toString(); } + + /** + * Adds to the given {@link MethodSpec.Builder} the given line of code, + * containing a call to a method of a {@link MethodProxy.Builder} or a + * {@link FieldProxy.Builder}. + * @param b the {@link MethodSpec.Builder} + * @param proxyBuilderName the name of the proxy builder + * @param proxyBuilderMethod the method to call + * @param t the {@link TypeMirror} to add + * @since 0.4.0 + */ + public static void addTypeToProxyGenerator(MethodSpec.Builder b, String proxyBuilderName, String proxyBuilderMethod, TypeMirror t) { + String insn = String.format("%s.%s", proxyBuilderName, proxyBuilderMethod); + if(t.getKind().isPrimitive()) + b.addStatement(insn + "($T.class)", t); + else { + ArrayContainer arr = new ArrayContainer(t); + b.addStatement( + insn + "($S, $L)", + arr.innermostComponent, + arr.arrayLevel + ); + } + } } |