public Collection < SQLSegment > extract ( final SQLAST ast ) { Collection < SQLSegment > result = new LinkedList <> ( ) ; Preconditions . checkState ( ast . getSQLStatementRule ( ) . isPresent ( ) ) ; Map < ParserRuleContext , Integer > parameterMarkerIndexes = getParameterMarkerIndexes ( ast . getParserRuleContext ( ) ) ; for ( SQLSegmentExtractor each : ast . getSQLStatementRule ( ) . get ( ) . getExtractors ( ) ) { if ( each instanceof OptionalSQLSegmentExtractor ) { Optional < ? extends SQLSegment > sqlSegment = ( ( OptionalSQLSegmentExtractor ) each ) . extract ( ast . getParserRuleContext ( ) , parameterMarkerIndexes ) ; if ( sqlSegment . isPresent ( ) ) { result . add ( sqlSegment . get ( ) ) ; } } else if ( each instanceof CollectionSQLSegmentExtractor ) { result . addAll ( ( ( CollectionSQLSegmentExtractor ) each ) . extract ( ast . getParserRuleContext ( ) , parameterMarkerIndexes ) ) ; } } return result ; }
Extract SQL segments .