aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2023-01-07 10:10:33 +0100
committerRawi01 <Rawi01@users.noreply.github.com>2023-01-07 10:10:33 +0100
commitf13b4dbbfccfe5a6bb72906c84c2e640e05d7788 (patch)
tree72f59210e43e960e93644b7485be3a90aec266b2 /src/core/lombok/javac
parent731bb185077918af8bc1e6a9e6bb538b2d3fbbd8 (diff)
downloadlombok-f13b4dbbfccfe5a6bb72906c84c2e640e05d7788.tar.gz
lombok-f13b4dbbfccfe5a6bb72906c84c2e640e05d7788.tar.bz2
lombok-f13b4dbbfccfe5a6bb72906c84c2e640e05d7788.zip
[fixes #3306] Convert short array initializers to long version
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/HandleBuilder.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/core/lombok/javac/handlers/HandleBuilder.java b/src/core/lombok/javac/handlers/HandleBuilder.java
index 854c8524..ed7d2844 100644
--- a/src/core/lombok/javac/handlers/HandleBuilder.java
+++ b/src/core/lombok/javac/handlers/HandleBuilder.java
@@ -45,6 +45,7 @@ import com.sun.tools.javac.tree.JCTree.JCLiteral;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
import com.sun.tools.javac.tree.JCTree.JCModifiers;
+import com.sun.tools.javac.tree.JCTree.JCNewArray;
import com.sun.tools.javac.tree.JCTree.JCNewClass;
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree;
import com.sun.tools.javac.tree.JCTree.JCReturn;
@@ -817,6 +818,14 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
JCBlock body = maker.Block(0, List.<JCStatement>of(statement));
int modifiers = Flags.PRIVATE | Flags.STATIC;
JCMethodDecl defaultProvider = maker.MethodDef(maker.Modifiers(modifiers), methodName, cloneType(maker, field.vartype, fieldNode), copyTypeParams(fieldNode, params), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
+ // ... then we convert short array initializers from `{1,2}` to `new int[]{1,2}` ...
+ if (init instanceof JCNewArray && field.vartype instanceof JCArrayTypeTree) {
+ JCNewArray arrayInitializer = (JCNewArray) init;
+ JCArrayTypeTree fieldType = (JCArrayTypeTree) field.vartype;
+ if (arrayInitializer.elemtype == null) {
+ arrayInitializer.elemtype = cloneType(maker, fieldType.elemtype, fieldNode);
+ }
+ }
// ... then we set positions for everything else ...
recursiveSetGeneratedBy(defaultProvider, job.sourceNode);
// ... and finally add back the original expression