author | redestad |
Sat, 01 Jun 2019 03:18:23 +0200 | |
changeset 55141 | db105c4c5776 |
parent 51154 | 393f8a42190b |
child 57956 | e0b8b019d2f5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
48944
25aa8b9f1dae
8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.regex; |
|
27 |
||
28 |
/** |
|
29 |
* Unchecked exception thrown to indicate a syntax error in a |
|
30 |
* regular-expression pattern. |
|
31 |
* |
|
32 |
* @author unascribed |
|
33 |
* @since 1.4 |
|
34 |
* @spec JSR-51 |
|
35 |
*/ |
|
36 |
||
37 |
public class PatternSyntaxException |
|
38 |
extends IllegalArgumentException |
|
39 |
{ |
|
1320
2412b1562801
6749308: java.io, java.lang, java.util exception classes don't specify serialVersionUID
chegar
parents:
2
diff
changeset
|
40 |
private static final long serialVersionUID = -3864639126226059218L; |
2 | 41 |
|
42 |
private final String desc; |
|
43 |
private final String pattern; |
|
44 |
private final int index; |
|
45 |
||
46 |
/** |
|
47 |
* Constructs a new instance of this class. |
|
48 |
* |
|
49 |
* @param desc |
|
50 |
* A description of the error |
|
51 |
* |
|
52 |
* @param regex |
|
53 |
* The erroneous pattern |
|
54 |
* |
|
55 |
* @param index |
|
56 |
* The approximate index in the pattern of the error, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
57 |
* or {@code -1} if the index is not known |
2 | 58 |
*/ |
59 |
public PatternSyntaxException(String desc, String regex, int index) { |
|
60 |
this.desc = desc; |
|
61 |
this.pattern = regex; |
|
62 |
this.index = index; |
|
63 |
} |
|
64 |
||
65 |
/** |
|
66 |
* Retrieves the error index. |
|
67 |
* |
|
68 |
* @return The approximate index in the pattern of the error, |
|
32108
aa5490a167ee
8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents:
25859
diff
changeset
|
69 |
* or {@code -1} if the index is not known |
2 | 70 |
*/ |
71 |
public int getIndex() { |
|
72 |
return index; |
|
73 |
} |
|
74 |
||
75 |
/** |
|
76 |
* Retrieves the description of the error. |
|
77 |
* |
|
78 |
* @return The description of the error |
|
79 |
*/ |
|
80 |
public String getDescription() { |
|
81 |
return desc; |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Retrieves the erroneous regular-expression pattern. |
|
86 |
* |
|
87 |
* @return The erroneous pattern |
|
88 |
*/ |
|
89 |
public String getPattern() { |
|
90 |
return pattern; |
|
91 |
} |
|
92 |
||
93 |
/** |
|
94 |
* Returns a multi-line string containing the description of the syntax |
|
95 |
* error and its index, the erroneous regular-expression pattern, and a |
|
96 |
* visual indication of the error index within the pattern. |
|
97 |
* |
|
98 |
* @return The full detail message |
|
99 |
*/ |
|
100 |
public String getMessage() { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
5506
diff
changeset
|
101 |
StringBuilder sb = new StringBuilder(); |
2 | 102 |
sb.append(desc); |
103 |
if (index >= 0) { |
|
104 |
sb.append(" near index "); |
|
105 |
sb.append(index); |
|
106 |
} |
|
48944
25aa8b9f1dae
8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents:
47216
diff
changeset
|
107 |
sb.append(System.lineSeparator()); |
2 | 108 |
sb.append(pattern); |
51154 | 109 |
if (index >= 0 && pattern != null && index < pattern.length()) { |
48944
25aa8b9f1dae
8198645: Use System.lineSeparator() instead of getProperty("line.separator")
rriggs
parents:
47216
diff
changeset
|
110 |
sb.append(System.lineSeparator()); |
2 | 111 |
for (int i = 0; i < index; i++) sb.append(' '); |
112 |
sb.append('^'); |
|
113 |
} |
|
114 |
return sb.toString(); |
|
115 |
} |
|
116 |
||
117 |
} |