@@ -304,26 +304,30 @@ export function printClassType(
304304 path : AstPath < JavaNonTerminal & { children : ClassTypeCtx } > ,
305305 print : JavaPrintFn
306306) {
307- return flatMap (
308- path ,
309- childPath => {
310- const { node, isLast } = childPath ;
311- const child = [ print ( childPath ) ] ;
312- if ( isTerminal ( node ) ) {
313- if ( ! isLast ) {
314- child . push ( "." ) ;
307+ const { children } = path . node ;
308+ return definedKeys ( children , [ "annotation" , "Identifier" , "typeArguments" ] )
309+ . flatMap ( child =>
310+ children [ child ] ! . map ( ( node , index ) => ( {
311+ child,
312+ index,
313+ startOffset : parser . locStart ( node )
314+ } ) )
315+ )
316+ . sort ( ( a , b ) => a . startOffset - b . startOffset )
317+ . flatMap ( ( { child, index : childIndex } , index , array ) => {
318+ const node = children [ child ] ! [ childIndex ] ;
319+ const next = array . at ( index + 1 ) ;
320+ const nextNode = next && children [ next . child ] ! [ next . index ] ;
321+ const docs = [ call ( path , print , child , childIndex ) ] ;
322+ if ( nextNode ) {
323+ if ( isNonTerminal ( node ) ) {
324+ docs . push ( node . name === "annotation" ? " " : "." ) ;
325+ } else if ( isTerminal ( nextNode ) || nextNode . name === "annotation" ) {
326+ docs . push ( "." ) ;
315327 }
316- } else if ( node . name === "annotation" ) {
317- child . push ( " " ) ;
318328 }
319- return child ;
320- } ,
321- definedKeys ( path . node . children , [
322- "annotation" ,
323- "Identifier" ,
324- "typeArguments"
325- ] )
326- ) ;
329+ return docs ;
330+ } ) ;
327331}
328332
329333export function isBinaryExpression ( expression : ExpressionCstNode ) {
0 commit comments