FileDocCategorySizeDatePackage
MismatchedTokenException.javaAPI DocGlassfish v2 API6031Wed Aug 30 15:34:08 BST 2006persistence.antlr

MismatchedTokenException

public class MismatchedTokenException extends RecognitionException

Fields Summary
String[]
tokenNames
public Token
token
public AST
node
String
tokenText
public static final int
TOKEN
public static final int
NOT_TOKEN
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
expecting
public int
upper
public BitSet
set
Constructors Summary
public MismatchedTokenException()
Looking for AST wildcard, didn't find it


            
      
        super("Mismatched Token: expecting any AST node", "<AST>", -1, -1);
    
public MismatchedTokenException(String[] tokenNames_, AST node_, int lower, int upper_, boolean matchNot)

        super("Mismatched Token", "<AST>", node_==null? -1:node_.getLine(), node_==null? -1:node_.getColumn());
        tokenNames = tokenNames_;
        node = node_;
        if (node_ == null) {
            tokenText = "<empty tree>";
        }
        else {
            tokenText = node_.toString();
        }
        mismatchType = matchNot ? NOT_RANGE : RANGE;
        expecting = lower;
        upper = upper_;
    
public MismatchedTokenException(String[] tokenNames_, AST node_, int expecting_, boolean matchNot)

		super("Mismatched Token", "<AST>", node_==null? -1:node_.getLine(), node_==null? -1:node_.getColumn());
        tokenNames = tokenNames_;
        node = node_;
        if (node_ == null) {
            tokenText = "<empty tree>";
        }
        else {
            tokenText = node_.toString();
        }
        mismatchType = matchNot ? NOT_TOKEN : TOKEN;
        expecting = expecting_;
    
public MismatchedTokenException(String[] tokenNames_, AST node_, BitSet set_, boolean matchNot)

		super("Mismatched Token", "<AST>", node_==null? -1:node_.getLine(), node_==null? -1:node_.getColumn());
        tokenNames = tokenNames_;
        node = node_;
        if (node_ == null) {
            tokenText = "<empty tree>";
        }
        else {
            tokenText = node_.toString();
        }
        mismatchType = matchNot ? NOT_SET : SET;
        set = set_;
    
public MismatchedTokenException(String[] tokenNames_, Token token_, int lower, int upper_, boolean matchNot, String fileName_)

        super("Mismatched Token", fileName_, token_.getLine(), token_.getColumn());
        tokenNames = tokenNames_;
        token = token_;
        tokenText = token_.getText();
        mismatchType = matchNot ? NOT_RANGE : RANGE;
        expecting = lower;
        upper = upper_;
    
public MismatchedTokenException(String[] tokenNames_, Token token_, int expecting_, boolean matchNot, String fileName_)

        super("Mismatched Token", fileName_, token_.getLine(), token_.getColumn());
        tokenNames = tokenNames_;
        token = token_;
        tokenText = token_.getText();
        mismatchType = matchNot ? NOT_TOKEN : TOKEN;
        expecting = expecting_;
    
public MismatchedTokenException(String[] tokenNames_, Token token_, BitSet set_, boolean matchNot, String fileName_)

        super("Mismatched Token", fileName_, token_.getLine(), token_.getColumn());
        tokenNames = tokenNames_;
        token = token_;
        tokenText = token_.getText();
        mismatchType = matchNot ? NOT_SET : SET;
        set = set_;
    
Methods Summary
public java.lang.StringgetMessage()
Returns a clean error message (no line number/column information)

        StringBuffer sb = new StringBuffer();

        switch (mismatchType) {
            case TOKEN:
                sb.append("expecting " + tokenName(expecting) + ", found '" + tokenText + "'");
                break;
            case NOT_TOKEN:
                sb.append("expecting anything but " + tokenName(expecting) + "; got it anyway");
                break;
            case RANGE:
                sb.append("expecting token in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'");
                break;
            case NOT_RANGE:
                sb.append("expecting token NOT in range: " + tokenName(expecting) + ".." + tokenName(upper) + ", found '" + tokenText + "'");
                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++) {
                    sb.append(" ");
                    sb.append(tokenName(elems[i]));
                }
                sb.append("), found '" + tokenText + "'");
                break;
            default :
                sb.append(super.getMessage());
                break;
        }

        return sb.toString();
    
private java.lang.StringtokenName(int tokenType)

        if (tokenType == Token.INVALID_TYPE) {
            return "<Set of tokens>";
        }
        else if (tokenType < 0 || tokenType >= tokenNames.length) {
            return "<" + String.valueOf(tokenType) + ">";
        }
        else {
            return tokenNames[tokenType];
        }