~ubuntu-branches/ubuntu/precise/cobertura/precise

« back to all changes in this revision

Viewing changes to src/net/sourceforge/cobertura/javancss/parser/debug/TokenMgrError.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. TokenMgrError.java Version 4.1 */
 
41
/* JavaCCOptions: */
 
42
//cobertura - put the import on its own line - otherwise, it messes up the script that changes the package.
 
43
package net.sourceforge.cobertura.javancss.parser.debug;
 
44
 
 
45
/** Token Manager Error. */
 
46
public class TokenMgrError extends Error
 
47
{
 
48
 
 
49
   /*
 
50
    * Ordinals for various reasons why an Error of this type can be thrown.
 
51
    */
 
52
 
 
53
   /**
 
54
    * Lexical error occurred.
 
55
    */
 
56
   static final int LEXICAL_ERROR = 0;
 
57
 
 
58
   /**
 
59
    * An attempt was made to create a second instance of a static token manager.
 
60
    */
 
61
   static final int STATIC_LEXER_ERROR = 1;
 
62
 
 
63
   /**
 
64
    * Tried to change to an invalid lexical state.
 
65
    */
 
66
   static final int INVALID_LEXICAL_STATE = 2;
 
67
 
 
68
   /**
 
69
    * Detected (and bailed out of) an infinite loop in the token manager.
 
70
    */
 
71
   static final int LOOP_DETECTED = 3;
 
72
 
 
73
   /**
 
74
    * Indicates the reason why the exception is thrown. It will have
 
75
    * one of the above 4 values.
 
76
    */
 
77
   int errorCode;
 
78
 
 
79
   /**
 
80
    * Replaces unprintable characters by their escaped (or unicode escaped)
 
81
    * equivalents in the given string
 
82
    */
 
83
   protected static final String addEscapes(String str) {
 
84
      StringBuffer retval = new StringBuffer();
 
85
      char ch;
 
86
      for (int i = 0; i < str.length(); i++) {
 
87
        switch (str.charAt(i))
 
88
        {
 
89
           case 0 :
 
90
              continue;
 
91
           case '\b':
 
92
              retval.append("\\b");
 
93
              continue;
 
94
           case '\t':
 
95
              retval.append("\\t");
 
96
              continue;
 
97
           case '\n':
 
98
              retval.append("\\n");
 
99
              continue;
 
100
           case '\f':
 
101
              retval.append("\\f");
 
102
              continue;
 
103
           case '\r':
 
104
              retval.append("\\r");
 
105
              continue;
 
106
           case '\"':
 
107
              retval.append("\\\"");
 
108
              continue;
 
109
           case '\'':
 
110
              retval.append("\\\'");
 
111
              continue;
 
112
           case '\\':
 
113
              retval.append("\\\\");
 
114
              continue;
 
115
           default:
 
116
              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
 
117
                 String s = "0000" + Integer.toString(ch, 16);
 
118
                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
 
119
              } else {
 
120
                 retval.append(ch);
 
121
              }
 
122
              continue;
 
123
        }
 
124
      }
 
125
      return retval.toString();
 
126
   }
 
127
 
 
128
   /**
 
129
    * Returns a detailed message for the Error when it is thrown by the
 
130
    * token manager to indicate a lexical error.
 
131
    * Parameters :
 
132
    *    EOFSeen     : indicates if EOF caused the lexical error
 
133
    *    curLexState : lexical state in which this error occurred
 
134
    *    errorLine   : line number when the error occurred
 
135
    *    errorColumn : column number when the error occurred
 
136
    *    errorAfter  : prefix that was seen before this error occurred
 
137
    *    curchar     : the offending character
 
138
    * Note: You can customize the lexical error message by modifying this method.
 
139
    */
 
140
   protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
 
141
      return("Lexical error at line " +
 
142
           errorLine + ", column " +
 
143
           errorColumn + ".  Encountered: " +
 
144
           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
 
145
           "after : \"" + addEscapes(errorAfter) + "\"");
 
146
   }
 
147
 
 
148
   /**
 
149
    * You can also modify the body of this method to customize your error messages.
 
150
    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
 
151
    * of end-users concern, so you can return something like :
 
152
    *
 
153
    *     "Internal Error : Please file a bug report .... "
 
154
    *
 
155
    * from this method for such cases in the release version of your parser.
 
156
    */
 
157
   public String getMessage() {
 
158
      return super.getMessage();
 
159
   }
 
160
 
 
161
   /*
 
162
    * Constructors of various flavors follow.
 
163
    */
 
164
 
 
165
   /** No arg constructor. */
 
166
   public TokenMgrError() {
 
167
   }
 
168
 
 
169
   /** Constructor with message and reason. */
 
170
   public TokenMgrError(String message, int reason) {
 
171
      super(message);
 
172
      errorCode = reason;
 
173
   }
 
174
 
 
175
   /** Full Constructor. */
 
176
   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
 
177
      this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
 
178
   }
 
179
}
 
180
/* JavaCC - OriginalChecksum=78b83ead2b9be6e85dfd6cf582647f66 (do not edit this line) */