public void replaceRight ( Pattern aPattern , String aReplacement ) { Object lastChild = this . children . get ( this . children . size ( ) - 1 ) ; if ( lastChild instanceof SourceNode ) { ( ( SourceNode ) lastChild ) . replaceRight ( aPattern , aReplacement ) ; } else if ( lastChild instanceof String ) { this . children . set ( this . children . size ( ) - 1 , aPattern . matcher ( ( ( String ) lastChild ) ) . replaceFirst ( aReplacement ) ) ; } else { this . children . add ( aPattern . matcher ( "" ) . replaceFirst ( aReplacement ) ) ; } }
Call String . prototype . replace on the very right - most source snippet . Useful for trimming whitespace from the end of a source node etc .