fix: restored isPrimitive() check before converting to string

This commit is contained in:
zaaarf 2023-03-18 20:08:16 +01:00
parent 9f9a9d9324
commit 1f0db87478
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
2 changed files with 30 additions and 18 deletions

View file

@ -341,24 +341,10 @@ public class LilleroProcessor extends AbstractProcessor {
if(isMethod) { if(isMethod) {
ExecutableElement targetMethod = (ExecutableElement) target; ExecutableElement targetMethod = (ExecutableElement) target;
for(VariableElement p : targetMethod.getParameters()) { for(VariableElement p : targetMethod.getParameters())
ArrayContainer param = new ArrayContainer(p.asType()); addTypeToProxyGenerator(b, "bd", "addParameter", p.asType());
b.addStatement( addTypeToProxyGenerator(b, "bd", "setReturnType", targetMethod.getReturnType());
"bd.addParameter($S, $L)", } else addTypeToProxyGenerator(b, "bd", "setType", target.asType());
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);
}
b.addStatement("return bd.build()"); b.addStatement("return bd.build()");

View file

@ -2,6 +2,8 @@ package ftbsc.lll.processor.tools;
import com.squareup.javapoet.*; import com.squareup.javapoet.*;
import ftbsc.lll.tools.DescriptorBuilder; 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.ExecutableElement;
import javax.lang.model.element.Modifier; import javax.lang.model.element.Modifier;
@ -109,4 +111,28 @@ public class JavaPoetUtils {
sb.append(")"); sb.append(")");
return sb.toString(); 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
);
}
}
} }