@@ -1642,14 +1642,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
16421642 arrayType = childArrayType ;
16431643 var extraDimensions = jcNewArray .getDimAnnotations ().stream ()
16441644 .map (annotations -> annotations .stream ().map (this ::convert ).toList ())
1645- .map (annotations -> {
1646- Dimension dim = this .ast .newDimension ();
1647- dim .annotations ().addAll (annotations );
1648- int startOffset = annotations .stream ().mapToInt (Annotation ::getStartPosition ).min ().orElse (-1 );
1649- int endOffset = annotations .stream ().mapToInt (ann -> ann .getStartPosition () + ann .getLength ()).max ().orElse (-1 );
1650- dim .setSourceRange (startOffset , endOffset - startOffset );
1651- return dim ;
1652- })
1645+ .map (this ::wrapAsDimension )
16531646 .toList ();
16541647 if (arrayType .dimensions ().isEmpty ()) {
16551648 arrayType .dimensions ().addAll (extraDimensions );
@@ -1686,17 +1679,21 @@ private Expression convertExpressionImpl(JCExpression javac) {
16861679 }
16871680 }
16881681 }
1689- } else if (jcNewArray .dims != null && jcNewArray .dims .size () > 0 ){
1690- // Child is not array type
1691- arrayType = this .ast .newArrayType (type );
1692- int dims = jcNewArray .dims .size ();
1693- for ( int i = 0 ; i < dims - 1 ; i ++ ) {
1694- // TODO, this dimension needs source range
1695- arrayType .dimensions ().addFirst (this .ast .newDimension ());
1696- }
16971682 } else {
1698- // Child is not array type, and 0 dims for underlying
16991683 arrayType = this .ast .newArrayType (type );
1684+ arrayType .dimensions ().clear ();
1685+ if (!jcNewArray .getAnnotations ().isEmpty ()) {
1686+ arrayType .dimensions ().add (wrapAsDimension (jcNewArray .getAnnotations ().stream ()
1687+ .map (this ::convert )
1688+ .toList ()));
1689+ } else if (!jcNewArray .getDimAnnotations ().isEmpty ()) {
1690+ jcNewArray .getDimAnnotations ().stream ()
1691+ .map (dimAnnotations -> dimAnnotations .stream ().map (this ::convert ).toList ())
1692+ .map (this ::wrapAsDimension )
1693+ .forEach (arrayType .dimensions ()::add );
1694+ } else {
1695+ arrayType .dimensions ().add (this .ast .newDimension ());
1696+ }
17001697 }
17011698 commonSettings (arrayType , jcNewArray .getType ());
17021699 res .setType (arrayType );
@@ -1788,6 +1785,15 @@ private SingleVariableDeclaration convertToSingleVarDecl(JCPattern jcPattern) {
17881785 return null ;
17891786 }
17901787
1788+ private Dimension wrapAsDimension (List <Annotation > annotations ) {
1789+ Dimension dim = this .ast .newDimension ();
1790+ dim .annotations ().addAll (annotations );
1791+ int startOffset = annotations .stream ().mapToInt (Annotation ::getStartPosition ).min ().orElse (-1 );
1792+ int endOffset = annotations .stream ().mapToInt (ann -> ann .getStartPosition () + ann .getLength ()).max ().orElse (-1 );
1793+ dim .setSourceRange (startOffset , endOffset - startOffset );
1794+ return dim ;
1795+ }
1796+
17911797 private List <JCExpression > consecutiveInfixExpressionsWithEqualOps (JCBinary binary , Tag opcode ) {
17921798 return consecutiveInfixExpressionsWithEqualOps (binary , opcode , new ArrayList <JCExpression >());
17931799 }
0 commit comments