aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse
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/eclipse
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/eclipse')
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index a2dd5057..d5ecfeaf 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -36,6 +36,7 @@ import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
import org.eclipse.jdt.internal.compiler.ast.Argument;
+import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.Assignment;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
@@ -918,7 +919,20 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
FieldDeclaration fd = (FieldDeclaration) fieldNode.get();
out.returnType = copyType(fd.type, source);
- out.statements = new Statement[] {new ReturnStatement(fd.initialization, pS, pE)};
+
+ // Convert short array initializers from `{1,2}` to `new int[]{1,2}`
+ Expression initialization;
+ if (fd.initialization instanceof ArrayInitializer) {
+ ArrayAllocationExpression arrayAllocationExpression = new ArrayAllocationExpression();
+ arrayAllocationExpression.initializer = (ArrayInitializer) fd.initialization;
+ arrayAllocationExpression.type = generateQualifiedTypeRef(fd, fd.type.getTypeName());
+ arrayAllocationExpression.dimensions = new Expression[fd.type.dimensions()];
+ initialization = arrayAllocationExpression;
+ } else {
+ initialization = fd.initialization;
+ }
+
+ out.statements = new Statement[] {new ReturnStatement(initialization, pS, pE)};
fd.initialization = null;
out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) fieldNode.up().get()).scope);