TokenMgrError.java

1
/*
2
 * Copyright 2006 - 2013
3
 *     Stefan Balev     <stefan.balev@graphstream-project.org>
4
 *     Julien Baudry    <julien.baudry@graphstream-project.org>
5
 *     Antoine Dutot    <antoine.dutot@graphstream-project.org>
6
 *     Yoann Pign��      <yoann.pigne@graphstream-project.org>
7
 *     Guilhelm Savin   <guilhelm.savin@graphstream-project.org>
8
 * 
9
 * This file is part of GraphStream <http://graphstream-project.org>.
10
 * 
11
 * GraphStream is a library whose purpose is to handle static or dynamic
12
 * graph, create them from scratch, file or any source and display them.
13
 * 
14
 * This program is free software distributed under the terms of two licenses, the
15
 * CeCILL-C license that fits European law, and the GNU Lesser General Public
16
 * License. You can  use, modify and/ or redistribute the software under the terms
17
 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
18
 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
19
 * the Free Software Foundation, either version 3 of the License, or (at your
20
 * option) any later version.
21
 * 
22
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
23
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
24
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
25
 * 
26
 * You should have received a copy of the GNU Lesser General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 * 
29
 * The fact that you are presently reading this means that you have had
30
 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
31
 */
32
package org.graphstream.util.parser;
33
34
/** Token Manager Error. */
35
public class TokenMgrError extends Error {
36
37
	/**
38
	 * The version identifier for this Serializable class. Increment only if the
39
	 * <i>serialized</i> form of the class changes.
40
	 */
41
	private static final long serialVersionUID = 1L;
42
43
	/*
44
	 * Ordinals for various reasons why an Error of this type can be thrown.
45
	 */
46
47
	/**
48
	 * Lexical error occurred.
49
	 */
50
	public static final int LEXICAL_ERROR = 0;
51
52
	/**
53
	 * An attempt was made to create a second instance of a static token
54
	 * manager.
55
	 */
56
	public static final int STATIC_LEXER_ERROR = 1;
57
58
	/**
59
	 * Tried to change to an invalid lexical state.
60
	 */
61
	public static final int INVALID_LEXICAL_STATE = 2;
62
63
	/**
64
	 * Detected (and bailed out of) an infinite loop in the token manager.
65
	 */
66
	public static final int LOOP_DETECTED = 3;
67
68
	/**
69
	 * Indicates the reason why the exception is thrown. It will have one of the
70
	 * above 4 values.
71
	 */
72
	int errorCode;
73
74
	/**
75
	 * Replaces unprintable characters by their escaped (or unicode escaped)
76
	 * equivalents in the given string
77
	 */
78
	protected static final String addEscapes(String str) {
79
		StringBuffer retval = new StringBuffer();
80
		char ch;
81 3 1. addEscapes : changed conditional boundary → NO_COVERAGE
2. addEscapes : Changed increment from 1 to -1 → NO_COVERAGE
3. addEscapes : negated conditional → NO_COVERAGE
		for (int i = 0; i < str.length(); i++) {
82
			switch (str.charAt(i)) {
83
			case 0:
84
				continue;
85
			case '\b':
86
				retval.append("\\b");
87
				continue;
88
			case '\t':
89
				retval.append("\\t");
90
				continue;
91
			case '\n':
92
				retval.append("\\n");
93
				continue;
94
			case '\f':
95
				retval.append("\\f");
96
				continue;
97
			case '\r':
98
				retval.append("\\r");
99
				continue;
100
			case '\"':
101
				retval.append("\\\"");
102
				continue;
103
			case '\'':
104
				retval.append("\\\'");
105
				continue;
106
			case '\\':
107
				retval.append("\\\\");
108
				continue;
109
			default:
110 4 1. addEscapes : changed conditional boundary → NO_COVERAGE
2. addEscapes : changed conditional boundary → NO_COVERAGE
3. addEscapes : negated conditional → NO_COVERAGE
4. addEscapes : negated conditional → NO_COVERAGE
				if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
111
					String s = "0000" + Integer.toString(ch, 16);
112
					retval.append("\\u"
113 1 1. addEscapes : Replaced integer subtraction with addition → NO_COVERAGE
							+ s.substring(s.length() - 4, s.length()));
114
				} else {
115
					retval.append(ch);
116
				}
117
				continue;
118
			}
119
		}
120 1 1. addEscapes : mutated return of Object value for org/graphstream/util/parser/TokenMgrError::addEscapes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return retval.toString();
121
	}
122
123
	/**
124
	 * Returns a detailed message for the Error when it is thrown by the token
125
	 * manager to indicate a lexical error. Parameters : EOFSeen : indicates if
126
	 * EOF caused the lexical error curLexState : lexical state in which this
127
	 * error occurred errorLine : line number when the error occurred
128
	 * errorColumn : column number when the error occurred errorAfter : prefix
129
	 * that was seen before this error occurred curchar : the offending
130
	 * character Note: You can customize the lexical error message by modifying
131
	 * this method.
132
	 */
133
	protected static String LexicalError(boolean EOFSeen, int lexState,
134
			int errorLine, int errorColumn, String errorAfter, char curChar) {
135 1 1. LexicalError : mutated return of Object value for org/graphstream/util/parser/TokenMgrError::LexicalError to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return ("Lexical error at line "
136
				+ errorLine
137
				+ ", column "
138
				+ errorColumn
139
				+ ".  Encountered: "
140 1 1. LexicalError : negated conditional → NO_COVERAGE
				+ (EOFSeen ? "<EOF> " : ("\""
141
						+ addEscapes(String.valueOf(curChar)) + "\"")
142
						+ " (" + (int) curChar + "), ") + "after : \""
143
				+ addEscapes(errorAfter) + "\"");
144
	}
145
146
	/**
147
	 * You can also modify the body of this method to customize your error
148
	 * messages. For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE
149
	 * are not of end-users concern, so you can return something like :
150
	 * 
151
	 * "Internal Error : Please file a bug report .... "
152
	 * 
153
	 * from this method for such cases in the release version of your parser.
154
	 */
155
	public String getMessage() {
156 1 1. getMessage : mutated return of Object value for org/graphstream/util/parser/TokenMgrError::getMessage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
		return super.getMessage();
157
	}
158
159
	/*
160
	 * Constructors of various flavors follow.
161
	 */
162
163
	/** No arg constructor. */
164
	public TokenMgrError() {
165
	}
166
167
	/** Constructor with message and reason. */
168
	public TokenMgrError(String message, int reason) {
169
		super(message);
170
		errorCode = reason;
171
	}
172
173
	/** Full Constructor. */
174
	public TokenMgrError(boolean EOFSeen, int lexState, int errorLine,
175
			int errorColumn, String errorAfter, char curChar, int reason) {
176
		this(LexicalError(EOFSeen, lexState, errorLine, errorColumn,
177
				errorAfter, curChar), reason);
178
	}
179
}
180
/*
181
 * JavaCC - OriginalChecksum=43ce61356e7f4e29ca35693bd6385bae (do not edit this
182
 * line)
183
 */

Mutations

81

1.1
Location : addEscapes
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : addEscapes
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : addEscapes
Killed by : none
negated conditional → NO_COVERAGE

110

1.1
Location : addEscapes
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : addEscapes
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : addEscapes
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : addEscapes
Killed by : none
negated conditional → NO_COVERAGE

113

1.1
Location : addEscapes
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

120

1.1
Location : addEscapes
Killed by : none
mutated return of Object value for org/graphstream/util/parser/TokenMgrError::addEscapes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

135

1.1
Location : LexicalError
Killed by : none
mutated return of Object value for org/graphstream/util/parser/TokenMgrError::LexicalError to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

140

1.1
Location : LexicalError
Killed by : none
negated conditional → NO_COVERAGE

156

1.1
Location : getMessage
Killed by : none
mutated return of Object value for org/graphstream/util/parser/TokenMgrError::getMessage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 0.33