~ubuntu-branches/ubuntu/trusty/cobertura/trusty

« back to all changes in this revision

Viewing changes to src/net/sourceforge/cobertura/javancss/parser/ParseException.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-05-11 19:21:46 UTC
  • mfrom: (0.1.4 sid) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100511192146-j742v5jsl89ztndu
Tags: 1.9.4.1+dfsg-2
* Now Build-Depends on libservlet2.5-java and add a missing Depends
  on the same package. (Closes: #580842). 
* Simplify list of JRE dependences for cobertura and drop JRE dependences for
  libcobertura-java as Java libraries are no longer required to depend on a
  JVM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cobertura - http://cobertura.sourceforge.net/
 
3
 *
 
4
 * This file was taken from JavaNCSS
 
5
 * http://www.kclee.com/clemens/java/javancss/
 
6
 * Copyright (C) 2000 Chr. Clemens Lee <clemens a.t kclee d.o.t com>
 
7
 *
 
8
 * Cobertura is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published
 
10
 * by the Free Software Foundation; either version 2 of the License,
 
11
 * or (at your option) any later version.
 
12
 *
 
13
 * Cobertura is distributed in the hope that it will be useful, but
 
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with Cobertura; if not, write to the Free Software
 
20
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
21
 * USA
 
22
 */
 
23
 
 
24
 
 
25
/*
 
26
 *
 
27
 * WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING  
 
28
 *
 
29
 * WARNING TO COBERTURA DEVELOPERS
 
30
 *
 
31
 * DO NOT MODIFY THIS FILE!
 
32
 *
 
33
 * MODIFY THE FILES UNDER THE JAVANCSS DIRECTORY LOCATED AT THE ROOT OF THE COBERTURA PROJECT.
 
34
 *
 
35
 * FOLLOW THE PROCEDURE FOR MERGING THE LATEST JAVANCSS INTO COBERTURA LOCATED AT
 
36
 * javancss/coberturaREADME.txt
 
37
 *
 
38
 * WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   WARNING   
 
39
 */
 
40
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 4.1 */
 
41
/* JavaCCOptions:KEEP_LINE_COL=null */
 
42
package net.sourceforge.cobertura.javancss.parser;
 
43
 
 
44
/**
 
45
 * This exception is thrown when parse errors are encountered.
 
46
 * You can explicitly create objects of this exception type by
 
47
 * calling the method generateParseException in the generated
 
48
 * parser.
 
49
 *
 
50
 * You can modify this class to customize your error reporting
 
51
 * mechanisms so long as you retain the public fields.
 
52
 */
 
53
public class ParseException extends Exception {
 
54
 
 
55
  /**
 
56
   * This constructor is used by the method "generateParseException"
 
57
   * in the generated parser.  Calling this constructor generates
 
58
   * a new object of this type with the fields "currentToken",
 
59
   * "expectedTokenSequences", and "tokenImage" set.  The boolean
 
60
   * flag "specialConstructor" is also set to true to indicate that
 
61
   * this constructor was used to create this object.
 
62
   * This constructor calls its super class with the empty string
 
63
   * to force the "toString" method of parent class "Throwable" to
 
64
   * print the error message in the form:
 
65
   *     ParseException: <result of getMessage>
 
66
   */
 
67
  public ParseException(Token currentTokenVal,
 
68
                        int[][] expectedTokenSequencesVal,
 
69
                        String[] tokenImageVal
 
70
                       )
 
71
  {
 
72
    super("");
 
73
    specialConstructor = true;
 
74
    currentToken = currentTokenVal;
 
75
    expectedTokenSequences = expectedTokenSequencesVal;
 
76
    tokenImage = tokenImageVal;
 
77
  }
 
78
 
 
79
  /**
 
80
   * The following constructors are for use by you for whatever
 
81
   * purpose you can think of.  Constructing the exception in this
 
82
   * manner makes the exception behave in the normal way - i.e., as
 
83
   * documented in the class "Throwable".  The fields "errorToken",
 
84
   * "expectedTokenSequences", and "tokenImage" do not contain
 
85
   * relevant information.  The JavaCC generated code does not use
 
86
   * these constructors.
 
87
   */
 
88
 
 
89
  public ParseException() {
 
90
    super();
 
91
    specialConstructor = false;
 
92
  }
 
93
 
 
94
  /** Constructor with message. */
 
95
  public ParseException(String message) {
 
96
    super(message);
 
97
    specialConstructor = false;
 
98
  }
 
99
 
 
100
  /**
 
101
   * This variable determines which constructor was used to create
 
102
   * this object and thereby affects the semantics of the
 
103
   * "getMessage" method (see below).
 
104
   */
 
105
  protected boolean specialConstructor;
 
106
 
 
107
  /**
 
108
   * This is the last token that has been consumed successfully.  If
 
109
   * this object has been created due to a parse error, the token
 
110
   * followng this token will (therefore) be the first error token.
 
111
   */
 
112
  public Token currentToken;
 
113
 
 
114
  /**
 
115
   * Each entry in this array is an array of integers.  Each array
 
116
   * of integers represents a sequence of tokens (by their ordinal
 
117
   * values) that is expected at this point of the parse.
 
118
   */
 
119
  public int[][] expectedTokenSequences;
 
120
 
 
121
  /**
 
122
   * This is a reference to the "tokenImage" array of the generated
 
123
   * parser within which the parse error occurred.  This array is
 
124
   * defined in the generated ...Constants interface.
 
125
   */
 
126
  public String[] tokenImage;
 
127
 
 
128
  /**
 
129
   * This method has the standard behavior when this object has been
 
130
   * created using the standard constructors.  Otherwise, it uses
 
131
   * "currentToken" and "expectedTokenSequences" to generate a parse
 
132
   * error message and returns it.  If this object has been created
 
133
   * due to a parse error, and you do not catch it (it gets thrown
 
134
   * from the parser), then this method is called during the printing
 
135
   * of the final stack trace, and hence the correct error message
 
136
   * gets displayed.
 
137
   */
 
138
  public String getMessage() {
 
139
    if (!specialConstructor) {
 
140
      return super.getMessage();
 
141
    }
 
142
    StringBuffer expected = new StringBuffer();
 
143
    int maxSize = 0;
 
144
    for (int i = 0; i < expectedTokenSequences.length; i++) {
 
145
      if (maxSize < expectedTokenSequences[i].length) {
 
146
        maxSize = expectedTokenSequences[i].length;
 
147
      }
 
148
      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
 
149
        expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
 
150
      }
 
151
      if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
 
152
        expected.append("...");
 
153
      }
 
154
      expected.append(eol).append("    ");
 
155
    }
 
156
    String retval = "Encountered \"";
 
157
    Token tok = currentToken.next;
 
158
    for (int i = 0; i < maxSize; i++) {
 
159
      if (i != 0) retval += " ";
 
160
      if (tok.kind == 0) {
 
161
        retval += tokenImage[0];
 
162
        break;
 
163
      }
 
164
      retval += " " + tokenImage[tok.kind];
 
165
      retval += " \"";
 
166
      retval += add_escapes(tok.image);
 
167
      retval += " \"";
 
168
      tok = tok.next;
 
169
    }
 
170
    retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
 
171
    retval += "." + eol;
 
172
    if (expectedTokenSequences.length == 1) {
 
173
      retval += "Was expecting:" + eol + "    ";
 
174
    } else {
 
175
      retval += "Was expecting one of:" + eol + "    ";
 
176
    }
 
177
    retval += expected.toString();
 
178
    return retval;
 
179
  }
 
180
 
 
181
  /**
 
182
   * The end of line string for this machine.
 
183
   */
 
184
  protected String eol = System.getProperty("line.separator", "\n");
 
185
 
 
186
  /**
 
187
   * Used to convert raw characters to their escaped version
 
188
   * when these raw version cannot be used as part of an ASCII
 
189
   * string literal.
 
190
   */
 
191
  protected String add_escapes(String str) {
 
192
      StringBuffer retval = new StringBuffer();
 
193
      char ch;
 
194
      for (int i = 0; i < str.length(); i++) {
 
195
        switch (str.charAt(i))
 
196
        {
 
197
           case 0 :
 
198
              continue;
 
199
           case '\b':
 
200
              retval.append("\\b");
 
201
              continue;
 
202
           case '\t':
 
203
              retval.append("\\t");
 
204
              continue;
 
205
           case '\n':
 
206
              retval.append("\\n");
 
207
              continue;
 
208
           case '\f':
 
209
              retval.append("\\f");
 
210
              continue;
 
211
           case '\r':
 
212
              retval.append("\\r");
 
213
              continue;
 
214
           case '\"':
 
215
              retval.append("\\\"");
 
216
              continue;
 
217
           case '\'':
 
218
              retval.append("\\\'");
 
219
              continue;
 
220
           case '\\':
 
221
              retval.append("\\\\");
 
222
              continue;
 
223
           default:
 
224
              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
 
225
                 String s = "0000" + Integer.toString(ch, 16);
 
226
                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
 
227
              } else {
 
228
                 retval.append(ch);
 
229
              }
 
230
              continue;
 
231
        }
 
232
      }
 
233
      return retval.toString();
 
234
   }
 
235
 
 
236
}
 
237
/* JavaCC - OriginalChecksum=849b618d99607c5b3309cfe8560c9c1d (do not edit this line) */