public static void setInternalComments ( Node node , ParserRuleContext parserRuleContext , AdapterParameters adapterParameters ) { BufferedTokenStream tokens = adapterParameters . getTokens ( ) ; if ( node == null || parserRuleContext == null || tokens == null ) { throw new IllegalArgumentException ( "Parameters must not be null" ) ; } Token startToken = parserRuleContext . getStart ( ) ; Token stopToken = parserRuleContext . getStop ( ) ; List < Token > commentTokens ; List < Comment > internalCommentList = new LinkedList < Comment > ( ) ; // Checking to the right of the start token will check inside the statement commentTokens = tokens . getHiddenTokensToRight ( startToken . getTokenIndex ( ) , Java7Lexer . COMMENTS ) ; if ( commentTokens != null ) { for ( Token commentToken : commentTokens ) { // Skip already claimed comments (prevents comment repeats) if ( adapterParameters . isCommentTokenClaimed ( commentToken . getTokenIndex ( ) ) ) { continue ; } else { // Claim it adapterParameters . claimCommentToken ( commentToken . getTokenIndex ( ) ) ; } if ( commentToken . getText ( ) . startsWith ( "/**" ) ) { JavadocComment javadocComment = new JavadocComment ( commentToken . getText ( ) ) ; internalCommentList . add ( javadocComment ) ; } else if ( commentToken . getText ( ) . startsWith ( "/*" ) ) { BlockComment blockComment = new BlockComment ( commentToken . getText ( ) ) ; internalCommentList . add ( blockComment ) ; } else if ( commentToken . getText ( ) . startsWith ( "//" ) ) { LineComment lineComment = new LineComment ( commentToken . getText ( ) ) ; internalCommentList . add ( lineComment ) ; } } } if ( internalCommentList . size ( ) > 0 ) { if ( node . getInternalComments ( ) != null ) { node . getInternalComments ( ) . addAll ( internalCommentList ) ; } else { node . setInternalComments ( internalCommentList ) ; } } }
If there are no statements within a block we need a special method to grab any comments that might exist between braces .