From 1f0db874780948f4483845284a2c5b57a0f2df4e Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sat, 18 Mar 2023 20:08:16 +0100 Subject: fix: restored isPrimitive() check before converting to string --- .../java/ftbsc/lll/processor/LilleroProcessor.java | 22 ++++-------------- .../ftbsc/lll/processor/tools/JavaPoetUtils.java | 26 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) (limited to 'src/main/java/ftbsc/lll') 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 + ); + } + } } -- cgit v1.2.3-56-ga3b1