diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2023-01-12 02:04:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-12 02:04:20 +0100 |
commit | 9e6f66c557205bff3c87eefb4c7a7631d0b89ff0 (patch) | |
tree | caa14a97db0852d16444575892db6d0761cc18de /src/core/lombok/eclipse/handlers | |
parent | 8bb4dc5daa8792e718e88c596812f232a2b73e6e (diff) | |
parent | f13b4dbbfccfe5a6bb72906c84c2e640e05d7788 (diff) | |
download | lombok-9e6f66c557205bff3c87eefb4c7a7631d0b89ff0.tar.gz lombok-9e6f66c557205bff3c87eefb4c7a7631d0b89ff0.tar.bz2 lombok-9e6f66c557205bff3c87eefb4c7a7631d0b89ff0.zip |
Merge pull request #3325 from Rawi01/builder-default-array
Convert short array initializers to long version
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rwxr-xr-x | src/core/lombok/eclipse/handlers/HandleBuilder.java | 16 |
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 bb9b6dda..57c3afde 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); |