Source Code Cross Referenced for MismatchedTokenException.java in  » Database-ORM » toplink » persistence » antlr » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » toplink » persistence.antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package persistence.antlr;
002:
003:        /* ANTLR Translator Generator
004:         * Project led by Terence Parr at http://www.jGuru.com
005:         * Software rights: http://www.antlr.org/license.html
006:         *
007:         */
008:
009:        import persistence.antlr.collections.impl.BitSet;
010:        import persistence.antlr.collections.AST;
011:
012:        public class MismatchedTokenException extends RecognitionException {
013:            // Token names array for formatting
014:            String[] tokenNames;
015:            // The token that was encountered
016:            public Token token;
017:            // The offending AST node if tree walking
018:            public AST node;
019:
020:            String tokenText = null; // taken from node or token object
021:
022:            // Types of tokens
023:            public static final int TOKEN = 1;
024:            public static final int NOT_TOKEN = 2;
025:            public static final int RANGE = 3;
026:            public static final int NOT_RANGE = 4;
027:            public static final int SET = 5;
028:            public static final int NOT_SET = 6;
029:            // One of the above
030:            public int mismatchType;
031:
032:            // For TOKEN/NOT_TOKEN and RANGE/NOT_RANGE
033:            public int expecting;
034:
035:            // For RANGE/NOT_RANGE (expecting is lower bound of range)
036:            public int upper;
037:
038:            // For SET/NOT_SET
039:            public BitSet set;
040:
041:            /** Looking for AST wildcard, didn't find it */
042:            public MismatchedTokenException() {
043:                super ("Mismatched Token: expecting any AST node", "<AST>", -1,
044:                        -1);
045:            }
046:
047:            // Expected range / not range
048:            public MismatchedTokenException(String[] tokenNames_, AST node_,
049:                    int lower, int upper_, boolean matchNot) {
050:                super ("Mismatched Token", "<AST>", node_ == null ? -1 : node_
051:                        .getLine(), node_ == null ? -1 : node_.getColumn());
052:                tokenNames = tokenNames_;
053:                node = node_;
054:                if (node_ == null) {
055:                    tokenText = "<empty tree>";
056:                } else {
057:                    tokenText = node_.toString();
058:                }
059:                mismatchType = matchNot ? NOT_RANGE : RANGE;
060:                expecting = lower;
061:                upper = upper_;
062:            }
063:
064:            // Expected token / not token
065:            public MismatchedTokenException(String[] tokenNames_, AST node_,
066:                    int expecting_, boolean matchNot) {
067:                super ("Mismatched Token", "<AST>", node_ == null ? -1 : node_
068:                        .getLine(), node_ == null ? -1 : node_.getColumn());
069:                tokenNames = tokenNames_;
070:                node = node_;
071:                if (node_ == null) {
072:                    tokenText = "<empty tree>";
073:                } else {
074:                    tokenText = node_.toString();
075:                }
076:                mismatchType = matchNot ? NOT_TOKEN : TOKEN;
077:                expecting = expecting_;
078:            }
079:
080:            // Expected BitSet / not BitSet
081:            public MismatchedTokenException(String[] tokenNames_, AST node_,
082:                    BitSet set_, boolean matchNot) {
083:                super ("Mismatched Token", "<AST>", node_ == null ? -1 : node_
084:                        .getLine(), node_ == null ? -1 : node_.getColumn());
085:                tokenNames = tokenNames_;
086:                node = node_;
087:                if (node_ == null) {
088:                    tokenText = "<empty tree>";
089:                } else {
090:                    tokenText = node_.toString();
091:                }
092:                mismatchType = matchNot ? NOT_SET : SET;
093:                set = set_;
094:            }
095:
096:            // Expected range / not range
097:            public MismatchedTokenException(String[] tokenNames_, Token token_,
098:                    int lower, int upper_, boolean matchNot, String fileName_) {
099:                super ("Mismatched Token", fileName_, token_.getLine(), token_
100:                        .getColumn());
101:                tokenNames = tokenNames_;
102:                token = token_;
103:                tokenText = token_.getText();
104:                mismatchType = matchNot ? NOT_RANGE : RANGE;
105:                expecting = lower;
106:                upper = upper_;
107:            }
108:
109:            // Expected token / not token
110:            public MismatchedTokenException(String[] tokenNames_, Token token_,
111:                    int expecting_, boolean matchNot, String fileName_) {
112:                super ("Mismatched Token", fileName_, token_.getLine(), token_
113:                        .getColumn());
114:                tokenNames = tokenNames_;
115:                token = token_;
116:                tokenText = token_.getText();
117:                mismatchType = matchNot ? NOT_TOKEN : TOKEN;
118:                expecting = expecting_;
119:            }
120:
121:            // Expected BitSet / not BitSet
122:            public MismatchedTokenException(String[] tokenNames_, Token token_,
123:                    BitSet set_, boolean matchNot, String fileName_) {
124:                super ("Mismatched Token", fileName_, token_.getLine(), token_
125:                        .getColumn());
126:                tokenNames = tokenNames_;
127:                token = token_;
128:                tokenText = token_.getText();
129:                mismatchType = matchNot ? NOT_SET : SET;
130:                set = set_;
131:            }
132:
133:            /**
134:             * Returns a clean error message (no line number/column information)
135:             */
136:            public String getMessage() {
137:                StringBuffer sb = new StringBuffer();
138:
139:                switch (mismatchType) {
140:                case TOKEN:
141:                    sb.append("expecting " + tokenName(expecting) + ", found '"
142:                            + tokenText + "'");
143:                    break;
144:                case NOT_TOKEN:
145:                    sb.append("expecting anything but " + tokenName(expecting)
146:                            + "; got it anyway");
147:                    break;
148:                case RANGE:
149:                    sb.append("expecting token in range: "
150:                            + tokenName(expecting) + ".." + tokenName(upper)
151:                            + ", found '" + tokenText + "'");
152:                    break;
153:                case NOT_RANGE:
154:                    sb.append("expecting token NOT in range: "
155:                            + tokenName(expecting) + ".." + tokenName(upper)
156:                            + ", found '" + tokenText + "'");
157:                    break;
158:                case SET:
159:                case NOT_SET:
160:                    sb.append("expecting "
161:                            + (mismatchType == NOT_SET ? "NOT " : "")
162:                            + "one of (");
163:                    int[] elems = set.toArray();
164:                    for (int i = 0; i < elems.length; i++) {
165:                        sb.append(" ");
166:                        sb.append(tokenName(elems[i]));
167:                    }
168:                    sb.append("), found '" + tokenText + "'");
169:                    break;
170:                default:
171:                    sb.append(super .getMessage());
172:                    break;
173:                }
174:
175:                return sb.toString();
176:            }
177:
178:            private String tokenName(int tokenType) {
179:                if (tokenType == Token.INVALID_TYPE) {
180:                    return "<Set of tokens>";
181:                } else if (tokenType < 0 || tokenType >= tokenNames.length) {
182:                    return "<" + String.valueOf(tokenType) + ">";
183:                } else {
184:                    return tokenNames[tokenType];
185:                }
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.