static String formatParseException ( String pExpressionString , ParseException pExc ) { // Generate the String of expected tokens StringBuffer expectedBuf = new StringBuffer ( ) ; int maxSize = 0 ; boolean printedOne = false ; if ( pExc . expectedTokenSequences == null ) { return pExc . toString ( ) ; } for ( int i = 0 ; i < pExc . expectedTokenSequences . length ; i ++ ) { if ( maxSize < pExc . expectedTokenSequences [ i ] . length ) { maxSize = pExc . expectedTokenSequences [ i ] . length ; } for ( int j = 0 ; j < pExc . expectedTokenSequences [ i ] . length ; j ++ ) { if ( printedOne ) { expectedBuf . append ( ", " ) ; } expectedBuf . append ( pExc . tokenImage [ pExc . expectedTokenSequences [ i ] [ j ] ] ) ; printedOne = true ; } } String expected = expectedBuf . toString ( ) ; // Generate the String of encountered tokens StringBuffer encounteredBuf = new StringBuffer ( ) ; Token tok = pExc . currentToken . next ; for ( int i = 0 ; i < maxSize ; i ++ ) { if ( i != 0 ) { encounteredBuf . append ( " " ) ; } if ( tok . kind == 0 ) { encounteredBuf . append ( pExc . tokenImage [ 0 ] ) ; break ; } encounteredBuf . append ( addEscapes ( tok . image ) ) ; tok = tok . next ; } String encountered = encounteredBuf . toString ( ) ; // Format the error message return MessageFormat . format ( Constants . PARSE_EXCEPTION , new Object [ ] { expected , encountered , } ) ; }
Formats a ParseException into an error message suitable for displaying on a web page