JCExpression arrayCreatorRest(int newpos, JCExpression elemtype) {
        List<JCAnnotation> annos = typeAnnotationsOpt();

        accept(LBRACKET);
        if (token.kind == RBRACKET) {
            accept(RBRACKET);
            elemtype = bracketsOpt(elemtype, annos);
            if (token.kind == LBRACE) {
                JCNewArray na = (JCNewArray)arrayInitializer(newpos, elemtype);
                if (annos.nonEmpty()) {
                    // when an array initializer is present then
                    // the parsed annotations should target the
                    // new array tree
                    // bracketsOpt inserts the annotation in
                    // elemtype, and it needs to be corrected
                    //
                    JCAnnotatedType annotated = (JCAnnotatedType)elemtype;
                    assert annotated.annotations == annos;
                    na.annotations = annotated.annotations;
                    na.elemtype = annotated.underlyingType;
                }
                return na;
            } else {
                JCExpression t = toP(F.at(newpos).NewArray(elemtype, List.nil(), null));
                return syntaxError(token.pos, List.of(t), "array.dimension.missing");
            }
        } else {
            ListBuffer<JCExpression> dims = new ListBuffer<>();

            // maintain array dimension type annotations
            ListBuffer<List<JCAnnotation>> dimAnnotations = new ListBuffer<>();
            dimAnnotations.append(annos);

            dims.append(parseExpression());
            accept(RBRACKET);
            while (token.kind == LBRACKET
                    || token.kind == MONKEYS_AT) {
                List<JCAnnotation> maybeDimAnnos = typeAnnotationsOpt();
                int pos = token.pos;
                nextToken();
                if (token.kind == RBRACKET) {
                    elemtype = bracketsOptCont(elemtype, pos, maybeDimAnnos);
                } else {
                    if (token.kind == RBRACKET) { // no dimension
                        elemtype = bracketsOptCont(elemtype, pos, maybeDimAnnos);
                    } else {
                        dimAnnotations.append(maybeDimAnnos);
                        dims.append(parseExpression());
                        accept(RBRACKET);
                    }
                }
            }

            JCNewArray na = toP(F.at(newpos).NewArray(elemtype, dims.toList(), null));
            na.dimAnnotations = dimAnnotations.toList();
            return na;
        }
    }
JCExpression arrayCreatorRest ( int newpos , JCExpression elemtype ) { List < JCAnnotation > annos = typeAnnotationsOpt ( ) ; accept ( LBRACKET ) ; if ( token . kind == RBRACKET ) { accept ( RBRACKET ) ; elemtype = bracketsOpt ( elemtype , annos ) ; if ( token . kind == LBRACE ) { JCNewArray na = ( JCNewArray ) arrayInitializer ( newpos , elemtype ) ; if ( annos . nonEmpty ( ) ) { JCAnnotatedType annotated = ( JCAnnotatedType ) elemtype ; assert annotated . annotations == annos ; na . annotations = annotated . annotations ; na . elemtype = annotated . underlyingType ; } return na ; } else { JCExpression t = toP ( F . at ( newpos ) . NewArray ( elemtype , List . nil ( ) , null ) ) ; return syntaxError ( token . pos , List . of ( t ) , "array.dimension.missing" ) ; } } else { ListBuffer < JCExpression > dims = new ListBuffer < > ( ) ; ListBuffer < List < JCAnnotation > > dimAnnotations = new ListBuffer < > ( ) ; dimAnnotations . append ( annos ) ; dims . append ( parseExpression ( ) ) ; accept ( RBRACKET ) ; while ( token . kind == LBRACKET || token . kind == MONKEYS_AT ) { List < JCAnnotation > maybeDimAnnos = typeAnnotationsOpt ( ) ; int pos = token . pos ; nextToken ( ) ; if ( token . kind == RBRACKET ) { elemtype = bracketsOptCont ( elemtype , pos , maybeDimAnnos ) ; } else { if ( token . kind == RBRACKET ) { elemtype = bracketsOptCont ( elemtype , pos , maybeDimAnnos ) ; } else { dimAnnotations . append ( maybeDimAnnos ) ; dims . append ( parseExpression ( ) ) ; accept ( RBRACKET ) ; } } } JCNewArray na = toP ( F . at ( newpos ) . NewArray ( elemtype , dims . toList ( ) , null ) ) ; na . dimAnnotations = dimAnnotations . toList ( ) ; return na ; } }
ArrayCreatorRest = [Annotations] "[" ( "]" BracketsOpt ArrayInitializer
| Expression "]" {[Annotations]  "[" Expression "]"} BracketsOpt )