From 458fcec48fb36ab6926a376d20ea0f4fe608bed6 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Wed, 12 Jun 2024 17:26:31 +0200 Subject: [PATCH] Fix some new array dimensions --- .../eclipse/jdt/core/dom/JavacConverter.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java index f05d3f40c61..383267db12a 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacConverter.java @@ -1500,7 +1500,24 @@ private Expression convertExpressionImpl(JCExpression javac) { if (type instanceof ArrayType childArrayType) { arrayType = childArrayType; if( this.ast.apiLevel >= AST.JLS8_INTERNAL) { - arrayType.dimensions().addFirst(this.ast.newDimension()); + var extraDimensions = jcNewArray.getDimAnnotations().stream() + .map(annotations -> annotations.stream().map(this::convert).toList()) + .map(annotations -> { + Dimension dim = this.ast.newDimension(); + dim.annotations().addAll(annotations); + int startOffset = annotations.stream().mapToInt(Annotation::getStartPosition).min().orElse(-1); + int endOffset = annotations.stream().mapToInt(ann -> ann.getStartPosition() + ann.getLength()).max().orElse(-1); + dim.setSourceRange(startOffset, endOffset - startOffset); + return dim; + }) + .toList(); + if (arrayType.dimensions().isEmpty()) { + arrayType.dimensions().addAll(extraDimensions); + } else { + var lastDimension = arrayType.dimensions().removeFirst(); + arrayType.dimensions().addAll(extraDimensions); + arrayType.dimensions().add(lastDimension); + } } else { arrayType = this.ast.newArrayType(childArrayType); } @@ -2429,7 +2446,8 @@ Type convertToType(JCTree javac) { res = this.ast.newSimpleType(convertName(simpleType.getName())); commonSettings(res, javac); } - } else { + } + if (res == null) { // nothing specific res = convertToType(jcAnnotatedType.getUnderlyingType()); } if (res instanceof AnnotatableType annotatableType && this.ast.apiLevel() >= AST.JLS8) {