FileDocCategorySizeDatePackage
MismatchedCharException.javaAPI DocGlassfish v2 API4412Wed Aug 30 15:34:08 BST 2006persistence.antlr

MismatchedCharException

public class MismatchedCharException extends RecognitionException

Fields Summary
public static final int
CHAR
public static final int
NOT_CHAR
public static final int
RANGE
public static final int
NOT_RANGE
public static final int
SET
public static final int
NOT_SET
public int
mismatchType
public int
foundChar
public int
expecting
public int
upper
public BitSet
set
public CharScanner
scanner
Constructors Summary
public MismatchedCharException()
MismatchedCharException constructor comment.


            
      
        super("Mismatched char");
    
public MismatchedCharException(char c, char lower, char upper_, boolean matchNot, CharScanner scanner_)

        super("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn());
        mismatchType = matchNot ? NOT_RANGE : RANGE;
        foundChar = c;
        expecting = lower;
        upper = upper_;
        scanner = scanner_;
    
public MismatchedCharException(char c, char expecting_, boolean matchNot, CharScanner scanner_)

        super("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn());
        mismatchType = matchNot ? NOT_CHAR : CHAR;
        foundChar = c;
        expecting = expecting_;
        scanner = scanner_;
    
public MismatchedCharException(char c, BitSet set_, boolean matchNot, CharScanner scanner_)

        super("Mismatched char", scanner_.getFilename(), scanner_.getLine(), scanner_.getColumn());
        mismatchType = matchNot ? NOT_SET : SET;
        foundChar = c;
        set = set_;
        scanner = scanner_;
    
Methods Summary
private voidappendCharName(java.lang.StringBuffer sb, int c)
Append a char to the msg buffer. If special, then show escaped version

        switch (c) {
		case 65535 :
			// 65535 = (char) -1 = EOF
            sb.append("'<EOF>'");
			break;
		case '\n" :
			sb.append("'\\n'");
			break;
		case '\r" :
			sb.append("'\\r'");
			break;
		case '\t" :
			sb.append("'\\t'");
			break;
		default :
            sb.append('\'");
            sb.append((char) c);
            sb.append('\'");
			break;
        }
    
public java.lang.StringgetMessage()
Returns a clean error message (no line number/column information)

        StringBuffer sb = new StringBuffer();

        switch (mismatchType) {
            case CHAR:
                sb.append("expecting ");   appendCharName(sb, expecting);
                sb.append(", found ");     appendCharName(sb, foundChar);
                break;
            case NOT_CHAR:
                sb.append("expecting anything but '");
                appendCharName(sb, expecting);
                sb.append("'; got it anyway");
                break;
            case RANGE:
            case NOT_RANGE:
                sb.append("expecting token ");
                if (mismatchType == NOT_RANGE)
                    sb.append("NOT ");
                sb.append("in range: ");
                appendCharName(sb, expecting);
                sb.append("..");
                appendCharName(sb, upper);
                sb.append(", found ");
                appendCharName(sb, foundChar);
                break;
            case SET:
            case NOT_SET:
                sb.append("expecting " + (mismatchType == NOT_SET ? "NOT " : "") + "one of (");
                int[] elems = set.toArray();
                for (int i = 0; i < elems.length; i++) {
                    appendCharName(sb, elems[i]);
                }
                sb.append("), found ");
                appendCharName(sb, foundChar);
                break;
            default :
                sb.append(super.getMessage());
                break;
        }

        return sb.toString();