Skip to content

Package: TokenMgrError

TokenMgrError

nameinstructionbranchcomplexitylinemethod
LexicalError(boolean, int, int, int, String, char)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
TokenMgrError()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
TokenMgrError(String, int)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
TokenMgrError(boolean, int, int, int, String, char, int)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
addEscapes(String)
M: 92 C: 0
0%
M: 16 C: 0
0%
M: 13 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%
getMessage()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
3: * Copyright (c) 2021 Payara Services Ltd.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package com.sun.el.parser;
19:
20: public class TokenMgrError extends Error {
21: /*
22: * Ordinals for various reasons why an Error of this type can be thrown.
23: */
24:
25: /**
26: * Lexical error occured.
27: */
28: static final int LEXICAL_ERROR = 0;
29:
30: /**
31: * An attempt wass made to create a second instance of a static token manager.
32: */
33: static final int STATIC_LEXER_ERROR = 1;
34:
35: /**
36: * Tried to change to an invalid lexical state.
37: */
38: static final int INVALID_LEXICAL_STATE = 2;
39:
40: /**
41: * Detected (and bailed out of) an infinite loop in the token manager.
42: */
43: static final int LOOP_DETECTED = 3;
44:
45: /**
46: * Indicates the reason why the exception is thrown. It will have one of the above 4 values.
47: */
48: int errorCode;
49:
50: /**
51: * Replaces unprintable characters by their espaced (or unicode escaped) equivalents in the given string
52: */
53: protected static final String addEscapes(String str) {
54: StringBuilder retval = new StringBuilder();
55: char ch;
56:• for (int i = 0; i < str.length(); i++) {
57:• switch (str.charAt(i)) {
58: case 0:
59: continue;
60: case '\b':
61: retval.append("\\b");
62: continue;
63: case '\t':
64: retval.append("\\t");
65: continue;
66: case '\n':
67: retval.append("\\n");
68: continue;
69: case '\f':
70: retval.append("\\f");
71: continue;
72: case '\r':
73: retval.append("\\r");
74: continue;
75: case '\"':
76: retval.append("\\\"");
77: continue;
78: case '\'':
79: retval.append("\\\'");
80: continue;
81: case '\\':
82: retval.append("\\\\");
83: continue;
84: default:
85:• if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
86: String s = "0000" + Integer.toString(ch, 16);
87: retval.append("\\u" + s.substring(s.length() - 4, s.length()));
88: } else {
89: retval.append(ch);
90: }
91: continue;
92: }
93: }
94: return retval.toString();
95: }
96:
97: /**
98: * Returns a detailed message for the Error when it is thrown by the token manager to indicate a lexical error.
99: * Parameters : EOFSeen : indicates if EOF caused the lexicl error curLexState : lexical state in which this error
100: * occured errorLine : line number when the error occured errorColumn : column number when the error occured errorAfter
101: * : prefix that was seen before this error occured curchar : the offending character Note: You can customize the
102: * lexical error message by modifying this method.
103: */
104: protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
105: return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: "
106:• + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ") + "after : \""
107: + addEscapes(errorAfter) + "\"");
108: }
109:
110: /**
111: * You can also modify the body of this method to customize your error messages. For example, cases like LOOP_DETECTED
112: * and INVALID_LEXICAL_STATE are not of end-users concern, so you can return something like :
113: *
114: * "Internal Error : Please file a bug report .... "
115: *
116: * from this method for such cases in the release version of your parser.
117: */
118: @Override
119: public String getMessage() {
120: return super.getMessage();
121: }
122:
123: /*
124: * Constructors of various flavors follow.
125: */
126:
127: public TokenMgrError() {
128: }
129:
130: public TokenMgrError(String message, int reason) {
131: super(message);
132: errorCode = reason;
133: }
134:
135: public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
136: this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
137: }
138: }