author | rfield |
Mon, 17 Sep 2018 08:37:47 -0700 | |
changeset 51766 | 3ca7d5385653 |
parent 47216 | 71c04702a3d5 |
child 55280 | d868727d8f0b |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
34752
9c262a013456
8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents:
33362
diff
changeset
|
25 |
|
33362 | 26 |
package jdk.jshell; |
27 |
||
28 |
import java.util.Set; |
|
29 |
import java.util.stream.Collectors; |
|
30 |
import java.util.stream.Stream; |
|
31 |
||
32 |
/** |
|
33 |
* Within a String, mask code comments and ignored modifiers (within context). |
|
34 |
* |
|
35 |
* @author Robert Field |
|
36 |
*/ |
|
37 |
class MaskCommentsAndModifiers { |
|
38 |
||
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
39 |
private final static Set<String> IGNORED_MODIFIERS = |
33362 | 40 |
Stream.of( "public", "protected", "private", "static", "final" ) |
41 |
.collect( Collectors.toSet() ); |
|
42 |
||
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
43 |
private final static Set<String> OTHER_MODIFIERS = |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
44 |
Stream.of( "abstract", "strictfp", "transient", "volatile", "synchronized", "native", "default" ) |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
45 |
.collect( Collectors.toSet() ); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
46 |
|
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
47 |
// Builder to accumulate non-masked characters |
33362 | 48 |
private final StringBuilder sbCleared = new StringBuilder(); |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
49 |
|
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
50 |
// Builder to accumulate masked characters |
33362 | 51 |
private final StringBuilder sbMask = new StringBuilder(); |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
52 |
|
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
53 |
// The input string |
33362 | 54 |
private final String str; |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
55 |
|
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
56 |
// Entire input string length |
33362 | 57 |
private final int length; |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
58 |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
59 |
// The next character position |
33362 | 60 |
private int next = 0; |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
61 |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
62 |
// The current character |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
63 |
private int c; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
64 |
|
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
65 |
// Do we mask-off ignored modifiers? Set by parameter and turned off after |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
66 |
// initial modifier section |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
67 |
private boolean maskModifiers; |
33362 | 68 |
|
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
69 |
// Does the string end with an unclosed '/*' style comment? |
51766
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
70 |
private boolean openToken = false; |
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
71 |
|
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
72 |
MaskCommentsAndModifiers(String s, boolean maskModifiers) { |
33362 | 73 |
this.str = s; |
74 |
this.length = s.length(); |
|
75 |
this.maskModifiers = maskModifiers; |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
76 |
read(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
77 |
while (c >= 0) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
78 |
next(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
79 |
read(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
80 |
} |
33362 | 81 |
} |
82 |
||
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
83 |
String cleared() { |
33362 | 84 |
return sbCleared.toString(); |
85 |
} |
|
86 |
||
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
87 |
String mask() { |
33362 | 88 |
return sbMask.toString(); |
89 |
} |
|
90 |
||
51766
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
91 |
boolean endsWithOpenToken() { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
92 |
return openToken; |
33362 | 93 |
} |
94 |
||
38835
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
95 |
/****** private implementation methods ******/ |
37280d52d723
8131024: JShell: multi-line comment not detected as incomplete
rfield
parents:
34752
diff
changeset
|
96 |
|
33362 | 97 |
/** |
98 |
* Read the next character |
|
99 |
*/ |
|
100 |
private int read() { |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
101 |
return c = (next >= length) |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
102 |
? -1 |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
103 |
: str.charAt(next++); |
33362 | 104 |
} |
105 |
||
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
106 |
private void unread() { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
107 |
if (c >= 0) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
108 |
--next; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
109 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
110 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
111 |
|
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
112 |
private void writeTo(StringBuilder sb, int ch) { |
33362 | 113 |
sb.append((char)ch); |
114 |
} |
|
115 |
||
116 |
private void write(int ch) { |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
117 |
if (ch != -1) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
118 |
writeTo(sbCleared, ch); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
119 |
writeTo(sbMask, Character.isWhitespace(ch) ? ch : ' '); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
120 |
} |
33362 | 121 |
} |
122 |
||
123 |
private void writeMask(int ch) { |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
124 |
if (ch != -1) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
125 |
writeTo(sbMask, ch); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
126 |
writeTo(sbCleared, Character.isWhitespace(ch) ? ch : ' '); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
127 |
} |
33362 | 128 |
} |
129 |
||
130 |
private void write(CharSequence s) { |
|
131 |
for (int cp : s.chars().toArray()) { |
|
132 |
write(cp); |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
private void writeMask(CharSequence s) { |
|
137 |
for (int cp : s.chars().toArray()) { |
|
138 |
writeMask(cp); |
|
139 |
} |
|
140 |
} |
|
141 |
||
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
142 |
private void next() { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
143 |
switch (c) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
144 |
case '\'': |
51766
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
145 |
case '"': { |
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
146 |
maskModifiers = false; |
33362 | 147 |
write(c); |
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
148 |
int match = c; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
149 |
while (read() >= 0 && c != match && c != '\n' && c != '\r') { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
150 |
write(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
151 |
if (c == '\\') { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
152 |
write(read()); |
33362 | 153 |
} |
154 |
} |
|
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
155 |
write(c); // write match // line-end |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
156 |
break; |
51766
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
157 |
} |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
158 |
case '`': { // RawString |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
159 |
maskModifiers = false; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
160 |
int backtickCount = 0; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
161 |
do { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
162 |
write(c); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
163 |
++backtickCount; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
164 |
read(); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
165 |
} while (c == '`'); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
166 |
while (true) { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
167 |
if (c == '`') { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
168 |
int cnt = 0; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
169 |
do { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
170 |
write(c); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
171 |
++cnt; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
172 |
read(); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
173 |
} while (c == '`'); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
174 |
if (cnt == backtickCount) { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
175 |
unread(); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
176 |
break; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
177 |
} |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
178 |
} else { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
179 |
write(c); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
180 |
if (c < 0) { |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
181 |
openToken = true; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
182 |
break; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
183 |
} |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
184 |
read(); |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
185 |
} |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
186 |
} |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
187 |
break; |
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
188 |
} |
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
189 |
case '/': |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
190 |
read(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
191 |
switch (c) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
192 |
case '*': |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
193 |
writeMask('/'); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
194 |
writeMask(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
195 |
int prevc = 0; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
196 |
while (read() >= 0 && (c != '/' || prevc != '*')) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
197 |
writeMask(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
198 |
prevc = c; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
199 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
200 |
writeMask(c); |
51766
3ca7d5385653
8210596: jshell does not support raw string literals
rfield
parents:
47216
diff
changeset
|
201 |
openToken = c < 0; |
41940
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
202 |
break; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
203 |
case '/': |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
204 |
writeMask('/'); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
205 |
writeMask(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
206 |
while (read() >= 0 && c != '\n' && c != '\r') { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
207 |
writeMask(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
208 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
209 |
writeMask(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
210 |
break; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
211 |
default: |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
212 |
maskModifiers = false; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
213 |
write('/'); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
214 |
unread(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
215 |
break; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
216 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
217 |
break; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
218 |
case '@': |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
219 |
do { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
220 |
write(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
221 |
read(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
222 |
} while (Character.isJavaIdentifierPart(c)); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
223 |
while (Character.isWhitespace(c)) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
224 |
write(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
225 |
read(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
226 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
227 |
// if this is an annotation with arguments, process those recursively |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
228 |
if (c == '(') { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
229 |
write(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
230 |
boolean prevMaskModifiers = maskModifiers; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
231 |
int parenCnt = 1; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
232 |
while (read() >= 0) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
233 |
if (c == ')') { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
234 |
if (--parenCnt == 0) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
235 |
break; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
236 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
237 |
} else if (c == '(') { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
238 |
++parenCnt; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
239 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
240 |
next(); // recurse to handle quotes and comments |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
241 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
242 |
write(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
243 |
// stuff in annotation arguments doesn't effect inside determination |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
244 |
maskModifiers = prevMaskModifiers; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
245 |
} else { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
246 |
unread(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
247 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
248 |
break; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
249 |
default: |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
250 |
if (Character.isJavaIdentifierStart(c)) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
251 |
StringBuilder sb = new StringBuilder(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
252 |
do { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
253 |
writeTo(sb, c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
254 |
read(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
255 |
} while (Character.isJavaIdentifierPart(c)); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
256 |
unread(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
257 |
String id = sb.toString(); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
258 |
if (maskModifiers && IGNORED_MODIFIERS.contains(id)) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
259 |
writeMask(sb); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
260 |
} else { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
261 |
write(sb); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
262 |
if (maskModifiers && !OTHER_MODIFIERS.contains(id)) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
263 |
maskModifiers = false; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
264 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
265 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
266 |
} else { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
267 |
if (!Character.isWhitespace(c)) { |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
268 |
maskModifiers = false; |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
269 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
270 |
write(c); |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
271 |
} |
048d559e9da7
8129559: JShell: compilation fails if class, method or field is annotated and has modifiers
rfield
parents:
38835
diff
changeset
|
272 |
break; |
33362 | 273 |
} |
274 |
} |
|
275 |
} |