KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > groovy > syntax > lexer > UnexpectedCharacterException


1 package org.codehaus.groovy.syntax.lexer;
2
3 public class UnexpectedCharacterException extends LexerException {
4     private char c;
5     private char[] expected;
6     private String JavaDoc message;
7
8     public UnexpectedCharacterException(int line, int column, char c, String JavaDoc message) {
9         super("unexpected character: " + c + (message == null ? "" : "; " + message), line, column);
10         this.c = c;
11         this.expected = null;
12         this.message = message;
13     }
14
15     public UnexpectedCharacterException(int line, int column, char c, char[] expected) {
16         super("unexpected character: " + c, line, column);
17         this.c = c;
18         this.expected = expected;
19         this.message = null;
20     }
21
22     public char getCharacter() {
23         return this.c;
24     }
25
26     public char[] getExpected() {
27         return this.expected;
28     }
29
30     public String JavaDoc getMessage() {
31         StringBuffer JavaDoc message = new StringBuffer JavaDoc();
32
33         if( this.message != null ) {
34             message.append( message );
35         }
36         else if( this.expected != null ) {
37             message.append("expected ");
38             if (this.expected.length == 1) {
39                 message.append("'" + this.expected[0] + "'");
40             }
41             else {
42                 message.append("one of {");
43
44                 for (int i = 0; i < this.expected.length; ++i) {
45                     message.append("'" + this.expected[i] + "'");
46
47                     if (i < (this.expected.length - 1)) {
48                         message.append(", ");
49                     }
50                 }
51
52                 message.append("}");
53             }
54         }
55
56         message.append( "; found '" ).append( c ).append( "'" );
57
58         return message.toString();
59     }
60 }
61
Popular Tags