author | rfield |
Mon, 23 May 2016 10:12:05 -0700 | |
changeset 38539 | 71874886920f |
parent 38531 | c449daa25b45 |
child 40600 | 3874367e6e6f |
permissions | -rw-r--r-- |
36494 | 1 |
/* |
2 |
* Copyright (c) 2016, 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 |
*/ |
|
25 |
||
26 |
package jdk.internal.jshell.tool; |
|
27 |
||
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Arrays; |
|
30 |
import java.util.Collection; |
|
31 |
import java.util.EnumSet; |
|
32 |
import java.util.HashMap; |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
33 |
import java.util.Iterator; |
36494 | 34 |
import java.util.List; |
35 |
import java.util.Locale; |
|
36 |
import java.util.Map; |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
37 |
import java.util.Map.Entry; |
36494 | 38 |
import java.util.regex.Matcher; |
39 |
import java.util.regex.Pattern; |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
40 |
import static java.util.stream.Collectors.joining; |
36494 | 41 |
|
42 |
/** |
|
43 |
* Feedback customization support |
|
44 |
* |
|
45 |
* @author Robert Field |
|
46 |
*/ |
|
47 |
class Feedback { |
|
48 |
||
49 |
// Patern for substituted fields within a customized format string |
|
50 |
private static final Pattern FIELD_PATTERN = Pattern.compile("\\{(.*?)\\}"); |
|
51 |
||
38513 | 52 |
// Internal field name for truncation length |
53 |
private static final String TRUNCATION_FIELD = "<truncation>"; |
|
54 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
55 |
// For encoding to Properties String |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
56 |
private static final String RECORD_SEPARATOR = "\u241E"; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
57 |
|
38539 | 58 |
// Current mode -- initial value is placeholder during start-up |
59 |
private Mode mode = new Mode(""); |
|
60 |
||
61 |
// Retained current mode -- for checks |
|
62 |
private Mode retainedCurrentMode = null; |
|
36494 | 63 |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
64 |
// Mapping of mode name to mode |
36494 | 65 |
private final Map<String, Mode> modeMap = new HashMap<>(); |
66 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
67 |
// Mapping of mode names to encoded retained mode |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
68 |
private final Map<String, String> retainedMap = new HashMap<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
69 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
70 |
// Mapping selector enum names to enums |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
71 |
private final Map<String, Selector<?>> selectorMap = new HashMap<>(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
72 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
73 |
private static final long ALWAYS = bits(FormatCase.all, FormatAction.all, FormatWhen.all, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
74 |
FormatResolve.all, FormatUnresolved.all, FormatErrors.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
75 |
private static final long ANY = 0L; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
76 |
|
36494 | 77 |
public boolean shouldDisplayCommandFluff() { |
78 |
return mode.commandFluff; |
|
79 |
} |
|
80 |
||
81 |
public String getPre() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
82 |
return mode.format("pre", ANY); |
36494 | 83 |
} |
84 |
||
85 |
public String getPost() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
86 |
return mode.format("post", ANY); |
36494 | 87 |
} |
88 |
||
89 |
public String getErrorPre() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
90 |
return mode.format("errorpre", ANY); |
36494 | 91 |
} |
92 |
||
93 |
public String getErrorPost() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
94 |
return mode.format("errorpost", ANY); |
36494 | 95 |
} |
96 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
97 |
public String format(FormatCase fc, FormatAction fa, FormatWhen fw, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
98 |
FormatResolve fr, FormatUnresolved fu, FormatErrors fe, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
99 |
String name, String type, String value, String unresolved, List<String> errorLines) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
100 |
return mode.format(fc, fa, fw, fr, fu, fe, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
101 |
name, type, value, unresolved, errorLines); |
36494 | 102 |
} |
103 |
||
104 |
public String getPrompt(String nextId) { |
|
105 |
return mode.getPrompt(nextId); |
|
106 |
} |
|
107 |
||
108 |
public String getContinuationPrompt(String nextId) { |
|
109 |
return mode.getContinuationPrompt(nextId); |
|
110 |
} |
|
111 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
112 |
public boolean setFeedback(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
113 |
return new Setter(messageHandler, at).setFeedback(); |
36494 | 114 |
} |
115 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
116 |
public boolean setFormat(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
117 |
return new Setter(messageHandler, at).setFormat(); |
36494 | 118 |
} |
119 |
||
38513 | 120 |
public boolean setTruncation(MessageHandler messageHandler, ArgTokenizer at) { |
121 |
return new Setter(messageHandler, at).setTruncation(); |
|
122 |
} |
|
123 |
||
38539 | 124 |
public boolean setMode(MessageHandler messageHandler, ArgTokenizer at) { |
125 |
return new Setter(messageHandler, at).setMode(); |
|
36494 | 126 |
} |
127 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
128 |
public boolean setPrompt(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
129 |
return new Setter(messageHandler, at).setPrompt(); |
36494 | 130 |
} |
131 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
132 |
public String retainFeedback(MessageHandler messageHandler, ArgTokenizer at) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
133 |
return new Setter(messageHandler, at).retainFeedback(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
134 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
135 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
136 |
public String retainMode(MessageHandler messageHandler, ArgTokenizer at) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
137 |
return new Setter(messageHandler, at).retainMode(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
138 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
139 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
140 |
public boolean restoreEncodedModes(MessageHandler messageHandler, String encoded) { |
38539 | 141 |
return new Setter(messageHandler, new ArgTokenizer("<init>", "")).restoreEncodedModes(encoded); |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
142 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
143 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
144 |
public void markModesReadOnly() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
145 |
modeMap.values().stream() |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
146 |
.forEach(m -> m.readOnly = true); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
147 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
148 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
149 |
{ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
150 |
for (FormatCase e : EnumSet.allOf(FormatCase.class)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
151 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
152 |
for (FormatAction e : EnumSet.allOf(FormatAction.class)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
153 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
154 |
for (FormatResolve e : EnumSet.allOf(FormatResolve.class)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
155 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
156 |
for (FormatUnresolved e : EnumSet.allOf(FormatUnresolved.class)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
157 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
158 |
for (FormatErrors e : EnumSet.allOf(FormatErrors.class)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
159 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
160 |
for (FormatWhen e : EnumSet.allOf(FormatWhen.class)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
161 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
36494 | 162 |
} |
163 |
||
164 |
/** |
|
165 |
* Holds all the context of a mode mode |
|
166 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
167 |
private static class Mode { |
36494 | 168 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
169 |
// Name of mode |
36494 | 170 |
final String name; |
171 |
||
172 |
// Display command verification/information |
|
38539 | 173 |
boolean commandFluff; |
36494 | 174 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
175 |
// Event cases: class, method, expression, ... |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
176 |
final Map<String, List<Setting>> cases; |
36494 | 177 |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
178 |
boolean readOnly = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
179 |
|
36494 | 180 |
String prompt = "\n-> "; |
181 |
String continuationPrompt = ">> "; |
|
182 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
183 |
static class Setting { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
184 |
final long enumBits; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
185 |
final String format; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
186 |
Setting(long enumBits, String format) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
187 |
this.enumBits = enumBits; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
188 |
this.format = format; |
36494 | 189 |
} |
190 |
} |
|
191 |
||
192 |
/** |
|
193 |
* Set up an empty mode. |
|
194 |
* |
|
195 |
* @param name |
|
196 |
* @param commandFluff True if should display command fluff messages |
|
197 |
*/ |
|
38539 | 198 |
Mode(String name) { |
36494 | 199 |
this.name = name; |
38539 | 200 |
this.cases = new HashMap<>(); |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
201 |
add("name", new Setting(ALWAYS, "%1$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
202 |
add("type", new Setting(ALWAYS, "%2$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
203 |
add("value", new Setting(ALWAYS, "%3$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
204 |
add("unresolved", new Setting(ALWAYS, "%4$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
205 |
add("errors", new Setting(ALWAYS, "%5$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
206 |
add("err", new Setting(ALWAYS, "%6$s")); |
36494 | 207 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
208 |
add("errorline", new Setting(ALWAYS, " {err}%n")); |
36494 | 209 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
210 |
add("pre", new Setting(ALWAYS, "| ")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
211 |
add("post", new Setting(ALWAYS, "%n")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
212 |
add("errorpre", new Setting(ALWAYS, "| ")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
213 |
add("errorpost", new Setting(ALWAYS, "%n")); |
36494 | 214 |
} |
215 |
||
216 |
/** |
|
217 |
* Set up a copied mode. |
|
218 |
* |
|
219 |
* @param name |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
220 |
* @param m Mode to copy, or null for no fresh |
36494 | 221 |
*/ |
38539 | 222 |
Mode(String name, Mode m) { |
36494 | 223 |
this.name = name; |
38539 | 224 |
this.commandFluff = m.commandFluff; |
225 |
this.prompt = m.prompt; |
|
226 |
this.continuationPrompt = m.continuationPrompt; |
|
227 |
this.cases = new HashMap<>(); |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
228 |
m.cases.entrySet().stream() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
229 |
.forEach(fes -> fes.getValue() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
230 |
.forEach(ing -> add(fes.getKey(), ing))); |
36494 | 231 |
|
232 |
} |
|
233 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
234 |
/** |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
235 |
* Set up a mode reconstituted from a preferences string. |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
236 |
* |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
237 |
* @param it the encoded Mode broken into String chunks, may contain |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
238 |
* subsequent encoded modes |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
239 |
*/ |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
240 |
Mode(Iterator<String> it) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
241 |
this.name = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
242 |
this.commandFluff = Boolean.parseBoolean(it.next()); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
243 |
this.prompt = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
244 |
this.continuationPrompt = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
245 |
cases = new HashMap<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
246 |
String field; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
247 |
while (!(field = it.next()).equals("***")) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
248 |
String open = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
249 |
assert open.equals("("); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
250 |
List<Setting> settings = new ArrayList<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
251 |
String bits; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
252 |
while (!(bits = it.next()).equals(")")) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
253 |
String format = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
254 |
Setting ing = new Setting(Long.parseLong(bits), format); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
255 |
settings.add(ing); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
256 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
257 |
cases.put(field, settings); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
258 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
259 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
260 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
261 |
/** |
38539 | 262 |
* Set if this mode displays informative/confirmational messages on |
263 |
* commands. |
|
264 |
* |
|
265 |
* @param fluff the value to set |
|
266 |
*/ |
|
267 |
void setCommandFluff(boolean fluff) { |
|
268 |
commandFluff = fluff; |
|
269 |
} |
|
270 |
||
271 |
/** |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
272 |
* Encodes the mode into a String so it can be saved in Preferences. |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
273 |
* |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
274 |
* @return the string representation |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
275 |
*/ |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
276 |
String encode() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
277 |
List<String> el = new ArrayList<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
278 |
el.add(name); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
279 |
el.add(String.valueOf(commandFluff)); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
280 |
el.add(prompt); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
281 |
el.add(continuationPrompt); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
282 |
for (Entry<String, List<Setting>> es : cases.entrySet()) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
283 |
el.add(es.getKey()); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
284 |
el.add("("); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
285 |
for (Setting ing : es.getValue()) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
286 |
el.add(String.valueOf(ing.enumBits)); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
287 |
el.add(ing.format); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
288 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
289 |
el.add(")"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
290 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
291 |
el.add("***"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
292 |
return String.join(RECORD_SEPARATOR, el); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
293 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
294 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
295 |
private boolean add(String field, Setting ing) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
296 |
List<Setting> settings = cases.computeIfAbsent(field, k -> new ArrayList<>()); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
297 |
if (settings == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
298 |
return false; |
36494 | 299 |
} |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
300 |
settings.add(ing); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
301 |
return true; |
36494 | 302 |
} |
303 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
304 |
void set(String field, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
305 |
Collection<FormatCase> cc, Collection<FormatAction> ca, Collection<FormatWhen> cw, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
306 |
Collection<FormatResolve> cr, Collection<FormatUnresolved> cu, Collection<FormatErrors> ce, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
307 |
String format) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
308 |
long bits = bits(cc, ca, cw, cr, cu, ce); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
309 |
set(field, bits, format); |
36494 | 310 |
} |
311 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
312 |
void set(String field, long bits, String format) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
313 |
add(field, new Setting(bits, format)); |
36494 | 314 |
} |
315 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
316 |
/** |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
317 |
* Lookup format Replace fields with context specific formats. |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
318 |
* |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
319 |
* @return format string |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
320 |
*/ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
321 |
String format(String field, long bits) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
322 |
List<Setting> settings = cases.get(field); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
323 |
if (settings == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
324 |
return ""; //TODO error? |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
325 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
326 |
String format = null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
327 |
for (int i = settings.size() - 1; i >= 0; --i) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
328 |
Setting ing = settings.get(i); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
329 |
long mask = ing.enumBits; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
330 |
if ((bits & mask) == bits) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
331 |
format = ing.format; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
332 |
break; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
333 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
334 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
335 |
if (format == null || format.isEmpty()) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
336 |
return ""; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
337 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
338 |
Matcher m = FIELD_PATTERN.matcher(format); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
339 |
StringBuffer sb = new StringBuffer(format.length()); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
340 |
while (m.find()) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
341 |
String fieldName = m.group(1); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
342 |
String sub = format(fieldName, bits); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
343 |
m.appendReplacement(sb, Matcher.quoteReplacement(sub)); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
344 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
345 |
m.appendTail(sb); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
346 |
return sb.toString(); |
36494 | 347 |
} |
348 |
||
38513 | 349 |
// Compute the display output given full context and values |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
350 |
String format(FormatCase fc, FormatAction fa, FormatWhen fw, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
351 |
FormatResolve fr, FormatUnresolved fu, FormatErrors fe, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
352 |
String name, String type, String value, String unresolved, List<String> errorLines) { |
38513 | 353 |
// Convert the context into a bit representation used as selectors for store field formats |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
354 |
long bits = bits(fc, fa, fw, fr, fu, fe); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
355 |
String fname = name==null? "" : name; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
356 |
String ftype = type==null? "" : type; |
38513 | 357 |
// Compute the representation of value |
358 |
String fvalue; |
|
359 |
if (value==null) { |
|
360 |
fvalue = ""; |
|
361 |
} else { |
|
362 |
// Retrieve the truncation length |
|
363 |
String truncField = format(TRUNCATION_FIELD, bits); |
|
364 |
if (truncField.isEmpty()) { |
|
365 |
// No truncation set, use whole value |
|
366 |
fvalue = value; |
|
367 |
} else { |
|
368 |
// Convert truncation length to int |
|
369 |
// this is safe since it has been tested before it is set |
|
370 |
int trunc = Integer.parseUnsignedInt(truncField); |
|
371 |
if (value.length() > trunc) { |
|
372 |
if (trunc <= 5) { |
|
373 |
// Very short truncations have no room for "..." |
|
374 |
fvalue = value.substring(0, trunc); |
|
375 |
} else { |
|
376 |
// Normal truncation, make total length equal truncation length |
|
377 |
fvalue = value.substring(0, trunc - 4) + " ..."; |
|
378 |
} |
|
379 |
} else { |
|
380 |
// Within truncation length, use whole value |
|
381 |
fvalue = value; |
|
382 |
} |
|
383 |
} |
|
384 |
} |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
385 |
String funresolved = unresolved==null? "" : unresolved; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
386 |
String errors = errorLines.stream() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
387 |
.map(el -> String.format( |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
388 |
format("errorline", bits), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
389 |
fname, ftype, fvalue, funresolved, "*cannot-use-errors-here*", el)) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
390 |
.collect(joining()); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
391 |
return String.format( |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
392 |
format("display", bits), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
393 |
fname, ftype, fvalue, funresolved, errors, "*cannot-use-err-here*"); |
36494 | 394 |
} |
395 |
||
396 |
void setPrompts(String prompt, String continuationPrompt) { |
|
397 |
this.prompt = prompt; |
|
398 |
this.continuationPrompt = continuationPrompt; |
|
399 |
} |
|
400 |
||
401 |
String getPrompt(String nextId) { |
|
402 |
return String.format(prompt, nextId); |
|
403 |
} |
|
404 |
||
405 |
String getContinuationPrompt(String nextId) { |
|
406 |
return String.format(continuationPrompt, nextId); |
|
407 |
} |
|
408 |
} |
|
409 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
410 |
// Representation of one instance of all the enum values as bits in a long |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
411 |
private static long bits(FormatCase fc, FormatAction fa, FormatWhen fw, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
412 |
FormatResolve fr, FormatUnresolved fu, FormatErrors fe) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
413 |
long res = 0L; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
414 |
res |= 1 << fc.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
415 |
res <<= FormatAction.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
416 |
res |= 1 << fa.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
417 |
res <<= FormatWhen.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
418 |
res |= 1 << fw.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
419 |
res <<= FormatResolve.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
420 |
res |= 1 << fr.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
421 |
res <<= FormatUnresolved.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
422 |
res |= 1 << fu.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
423 |
res <<= FormatErrors.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
424 |
res |= 1 << fe.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
425 |
return res; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
426 |
} |
36494 | 427 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
428 |
// Representation of a space of enum values as or'edbits in a long |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
429 |
private static long bits(Collection<FormatCase> cc, Collection<FormatAction> ca, Collection<FormatWhen> cw, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
430 |
Collection<FormatResolve> cr, Collection<FormatUnresolved> cu, Collection<FormatErrors> ce) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
431 |
long res = 0L; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
432 |
for (FormatCase fc : cc) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
433 |
res |= 1 << fc.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
434 |
res <<= FormatAction.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
435 |
for (FormatAction fa : ca) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
436 |
res |= 1 << fa.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
437 |
res <<= FormatWhen.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
438 |
for (FormatWhen fw : cw) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
439 |
res |= 1 << fw.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
440 |
res <<= FormatResolve.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
441 |
for (FormatResolve fr : cr) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
442 |
res |= 1 << fr.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
443 |
res <<= FormatUnresolved.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
444 |
for (FormatUnresolved fu : cu) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
445 |
res |= 1 << fu.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
446 |
res <<= FormatErrors.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
447 |
for (FormatErrors fe : ce) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
448 |
res |= 1 << fe.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
449 |
return res; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
450 |
} |
36494 | 451 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
452 |
interface Selector<E extends Enum<E> & Selector<E>> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
453 |
SelectorCollector<E> collector(Setter.SelectorList sl); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
454 |
String doc(); |
36494 | 455 |
} |
456 |
||
457 |
/** |
|
458 |
* The event cases |
|
459 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
460 |
public enum FormatCase implements Selector<FormatCase> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
461 |
IMPORT("import declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
462 |
CLASS("class declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
463 |
INTERFACE("interface declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
464 |
ENUM("enum declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
465 |
ANNOTATION("annotation interface declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
466 |
METHOD("method declaration -- note: {type}==parameter-types"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
467 |
VARDECL("variable declaration without init"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
468 |
VARINIT("variable declaration with init"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
469 |
EXPRESSION("expression -- note: {name}==scratch-variable-name"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
470 |
VARVALUE("variable value expression"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
471 |
ASSIGNMENT("assign variable"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
472 |
STATEMENT("statement"); |
36494 | 473 |
String doc; |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
474 |
static final EnumSet<FormatCase> all = EnumSet.allOf(FormatCase.class); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
475 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
476 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
477 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
478 |
public SelectorCollector<FormatCase> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
479 |
return sl.cases; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
480 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
481 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
482 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
483 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
484 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
485 |
} |
36494 | 486 |
|
487 |
private FormatCase(String doc) { |
|
488 |
this.doc = doc; |
|
489 |
} |
|
490 |
} |
|
491 |
||
492 |
/** |
|
493 |
* The event actions |
|
494 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
495 |
public enum FormatAction implements Selector<FormatAction> { |
36494 | 496 |
ADDED("snippet has been added"), |
497 |
MODIFIED("an existing snippet has been modified"), |
|
498 |
REPLACED("an existing snippet has been replaced with a new snippet"), |
|
499 |
OVERWROTE("an existing snippet has been overwritten"), |
|
500 |
DROPPED("snippet has been dropped"), |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
501 |
USED("snippet was used when it cannot be"); |
36494 | 502 |
String doc; |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
503 |
static final EnumSet<FormatAction> all = EnumSet.allOf(FormatAction.class); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
504 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
505 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
506 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
507 |
public SelectorCollector<FormatAction> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
508 |
return sl.actions; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
509 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
510 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
511 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
512 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
513 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
514 |
} |
36494 | 515 |
|
516 |
private FormatAction(String doc) { |
|
517 |
this.doc = doc; |
|
518 |
} |
|
519 |
} |
|
520 |
||
521 |
/** |
|
522 |
* When the event occurs: primary or update |
|
523 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
524 |
public enum FormatWhen implements Selector<FormatWhen> { |
36494 | 525 |
PRIMARY("the entered snippet"), |
526 |
UPDATE("an update to a dependent snippet"); |
|
527 |
String doc; |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
528 |
static final EnumSet<FormatWhen> all = EnumSet.allOf(FormatWhen.class); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
529 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
530 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
531 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
532 |
public SelectorCollector<FormatWhen> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
533 |
return sl.whens; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
534 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
535 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
536 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
537 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
538 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
539 |
} |
36494 | 540 |
|
541 |
private FormatWhen(String doc) { |
|
542 |
this.doc = doc; |
|
543 |
} |
|
544 |
} |
|
545 |
||
546 |
/** |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
547 |
* Resolution problems |
36494 | 548 |
*/ |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
549 |
public enum FormatResolve implements Selector<FormatResolve> { |
36494 | 550 |
OK("resolved correctly"), |
551 |
DEFINED("defined despite recoverably unresolved references"), |
|
552 |
NOTDEFINED("not defined because of recoverably unresolved references"); |
|
553 |
String doc; |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
554 |
static final EnumSet<FormatResolve> all = EnumSet.allOf(FormatResolve.class); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
555 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
556 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
557 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
558 |
public SelectorCollector<FormatResolve> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
559 |
return sl.resolves; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
560 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
561 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
562 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
563 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
564 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
565 |
} |
36494 | 566 |
|
567 |
private FormatResolve(String doc) { |
|
568 |
this.doc = doc; |
|
569 |
} |
|
570 |
} |
|
571 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
572 |
/** |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
573 |
* Count of unresolved references |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
574 |
*/ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
575 |
public enum FormatUnresolved implements Selector<FormatUnresolved> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
576 |
UNRESOLVED0("no names are unresolved"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
577 |
UNRESOLVED1("one name is unresolved"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
578 |
UNRESOLVED2("two or more names are unresolved"); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
579 |
String doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
580 |
static final EnumSet<FormatUnresolved> all = EnumSet.allOf(FormatUnresolved.class); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
581 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
582 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
583 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
584 |
public SelectorCollector<FormatUnresolved> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
585 |
return sl.unresolvedCounts; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
586 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
587 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
588 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
589 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
590 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
591 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
592 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
593 |
private FormatUnresolved(String doc) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
594 |
this.doc = doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
595 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
596 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
597 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
598 |
/** |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
599 |
* Count of unresolved references |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
600 |
*/ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
601 |
public enum FormatErrors implements Selector<FormatErrors> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
602 |
ERROR0("no errors"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
603 |
ERROR1("one error"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
604 |
ERROR2("two or more errors"); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
605 |
String doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
606 |
static final EnumSet<FormatErrors> all = EnumSet.allOf(FormatErrors.class); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
607 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
608 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
609 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
610 |
public SelectorCollector<FormatErrors> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
611 |
return sl.errorCounts; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
612 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
613 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
614 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
615 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
616 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
617 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
618 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
619 |
private FormatErrors(String doc) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
620 |
this.doc = doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
621 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
622 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
623 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
624 |
class SelectorCollector<E extends Enum<E> & Selector<E>> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
625 |
final EnumSet<E> all; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
626 |
EnumSet<E> set = null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
627 |
SelectorCollector(EnumSet<E> all) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
628 |
this.all = all; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
629 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
630 |
void add(Object o) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
631 |
@SuppressWarnings("unchecked") |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
632 |
E e = (E) o; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
633 |
if (set == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
634 |
set = EnumSet.of(e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
635 |
} else { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
636 |
set.add(e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
637 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
638 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
639 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
640 |
boolean isEmpty() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
641 |
return set == null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
642 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
643 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
644 |
EnumSet<E> getSet() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
645 |
return set == null |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
646 |
? all |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
647 |
: set; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
648 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
649 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
650 |
|
36494 | 651 |
// Class used to set custom eval output formats |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
652 |
// For both /set format -- Parse arguments, setting custom format, or printing error |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
653 |
private class Setter { |
36494 | 654 |
|
655 |
private final ArgTokenizer at; |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
656 |
private final MessageHandler messageHandler; |
36494 | 657 |
boolean valid = true; |
658 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
659 |
Setter(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
660 |
this.messageHandler = messageHandler; |
36494 | 661 |
this.at = at; |
662 |
} |
|
663 |
||
664 |
void fluff(String format, Object... args) { |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
665 |
messageHandler.fluff(format, args); |
36494 | 666 |
} |
667 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
668 |
void fluffmsg(String messageKey, Object... args) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
669 |
messageHandler.fluffmsg(messageKey, args); |
36494 | 670 |
} |
671 |
||
36990 | 672 |
void errorat(String messageKey, Object... args) { |
673 |
Object[] a2 = Arrays.copyOf(args, args.length + 2); |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
674 |
a2[args.length] = at.whole(); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
675 |
messageHandler.errormsg(messageKey, a2); |
36494 | 676 |
} |
677 |
||
678 |
// For /set prompt <mode> "<prompt>" "<continuation-prompt>" |
|
679 |
boolean setPrompt() { |
|
680 |
Mode m = nextMode(); |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
681 |
if (valid && m.readOnly) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
682 |
errorat("jshell.err.not.valid.with.predefined.mode", m.name); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
683 |
valid = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
684 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
685 |
String prompt = valid ? nextFormat() : null; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
686 |
String continuationPrompt = valid ? nextFormat() : null; |
36494 | 687 |
if (valid) { |
688 |
m.setPrompts(prompt, continuationPrompt); |
|
689 |
} else { |
|
36990 | 690 |
fluffmsg("jshell.msg.see", "/help /set prompt"); |
36494 | 691 |
} |
692 |
return valid; |
|
693 |
} |
|
694 |
||
38539 | 695 |
/** |
696 |
* Set mode. Create, changed, or delete a feedback mode. For @{code /set |
|
697 |
* mode <mode> [<old-mode>] [-command|-quiet|-delete]}. |
|
698 |
* |
|
699 |
* @return true if successful |
|
700 |
*/ |
|
701 |
boolean setMode() { |
|
702 |
at.allowedOptions("-command", "-quiet", "-delete"); |
|
703 |
String umode = nextModeIdentifier(); |
|
704 |
Mode om = null; |
|
705 |
String omode = at.next(); |
|
706 |
if (valid && omode != null) { |
|
707 |
om = toMode(omode); |
|
36494 | 708 |
} |
38539 | 709 |
checkOptionsAndRemainingInput(); |
710 |
boolean commandOption = at.hasOption("-command"); |
|
711 |
boolean quietOption = at.hasOption("-quiet"); |
|
712 |
boolean deleteOption = at.hasOption("-delete"); |
|
713 |
// Only one (or zero) of the options can be used |
|
714 |
if (valid && at.optionCount() > 1) { |
|
715 |
errorat("jshell.err.conflicting.options"); |
|
36494 | 716 |
valid = false; |
717 |
} |
|
38539 | 718 |
if (valid) { |
719 |
Mode m = modeMap.get(umode); |
|
720 |
if (m != null && m.readOnly) { |
|
721 |
// Cannot make changes to a the built-in modes |
|
722 |
errorat("jshell.err.not.valid.with.predefined.mode", m.name); |
|
723 |
valid = false; |
|
724 |
} else if (deleteOption) { |
|
725 |
if (m == null) { |
|
726 |
// Cannot delete a mode that does not exist |
|
727 |
errorat("jshell.err.mode.unknown", umode); |
|
728 |
valid = false; |
|
729 |
} else if (mode.name.equals(m.name)) { |
|
730 |
// Cannot delete the current mode out from under us |
|
731 |
errorat("jshell.err.cannot.delete.current.mode", umode); |
|
732 |
valid = false; |
|
733 |
} else { |
|
734 |
// Remove the mode |
|
735 |
modeMap.remove(umode); |
|
736 |
} |
|
737 |
} else { |
|
738 |
if (om != null || m == null) { |
|
739 |
// We are copying and existing mode and/or creating a |
|
740 |
// brand-new mode -- in either case create from scratch |
|
741 |
m = (om != null) |
|
742 |
? new Mode(umode, om) |
|
743 |
: new Mode(umode); |
|
744 |
modeMap.put(umode, m); |
|
745 |
fluffmsg("jshell.msg.feedback.new.mode", m.name); |
|
746 |
// Set the current mode by name, in case we just smashed |
|
747 |
// the current mode |
|
748 |
if (umode.equals(mode.name)) { |
|
749 |
mode = modeMap.get(mode.name); |
|
750 |
} |
|
751 |
} |
|
752 |
if (commandOption || quietOption || om == null) { |
|
753 |
// set command fluff, if explicit, or wholly new |
|
754 |
m.setCommandFluff(!quietOption); |
|
755 |
} |
|
756 |
} |
|
36494 | 757 |
} |
38539 | 758 |
if (!valid) { |
759 |
fluffmsg("jshell.msg.see", "/help /set mode"); |
|
36494 | 760 |
} |
761 |
return valid; |
|
762 |
} |
|
763 |
||
764 |
// For /set feedback <mode> |
|
765 |
boolean setFeedback() { |
|
766 |
Mode m = nextMode(); |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
767 |
if (valid) { |
36494 | 768 |
mode = m; |
36990 | 769 |
fluffmsg("jshell.msg.feedback.mode", mode.name); |
36494 | 770 |
} else { |
36990 | 771 |
fluffmsg("jshell.msg.see", "/help /set feedback"); |
37640
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
772 |
printFeedbackModes(); |
36494 | 773 |
} |
774 |
return valid; |
|
775 |
} |
|
776 |
||
777 |
// For /set format <mode> "<format>" <selector>... |
|
778 |
boolean setFormat() { |
|
779 |
Mode m = nextMode(); |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
780 |
if (valid && m.readOnly) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
781 |
errorat("jshell.err.not.valid.with.predefined.mode", m.name); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
782 |
valid = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
783 |
} |
38539 | 784 |
String field = valid |
785 |
? toIdentifier(at.next(), "jshell.err.missing.field", "jshell.err.field.name") |
|
786 |
: null; |
|
38513 | 787 |
String format = valid ? nextFormat() : null; |
788 |
return installFormat(m, field, format, "/help /set format"); |
|
789 |
} |
|
790 |
||
791 |
// For /set truncation <mode> <length> <selector>... |
|
792 |
boolean setTruncation() { |
|
793 |
Mode m = nextMode(); |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
794 |
if (valid && m.readOnly) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
795 |
errorat("jshell.err.not.valid.with.predefined.mode", m.name); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
796 |
valid = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
797 |
} |
38513 | 798 |
String length = at.next(); |
799 |
if (length == null) { |
|
800 |
errorat("jshell.err.truncation.expected.length"); |
|
801 |
valid = false; |
|
802 |
} else { |
|
803 |
try { |
|
804 |
// Assure that integer format is correct |
|
805 |
Integer.parseUnsignedInt(length); |
|
806 |
} catch (NumberFormatException ex) { |
|
807 |
errorat("jshell.err.truncation.length.not.integer", length); |
|
808 |
valid = false; |
|
809 |
} |
|
810 |
} |
|
811 |
// install length into an internal format field |
|
812 |
return installFormat(m, TRUNCATION_FIELD, length, "/help /set truncation"); |
|
813 |
} |
|
814 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
815 |
String retainFeedback() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
816 |
String umode = at.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
817 |
if (umode != null) { |
38539 | 818 |
toModeIdentifier(umode); |
819 |
Mode m = valid ? toMode(umode) : null; |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
820 |
if (valid && !m.readOnly && !retainedMap.containsKey(m.name)) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
821 |
errorat("jshell.err.retained.feedback.mode.must.be.retained.or.predefined"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
822 |
valid = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
823 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
824 |
if (valid) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
825 |
mode = m; |
38539 | 826 |
retainedCurrentMode = m; |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
827 |
fluffmsg("jshell.msg.feedback.mode", mode.name); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
828 |
} else { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
829 |
fluffmsg("jshell.msg.see", "/help /retain feedback"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
830 |
return null; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
831 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
832 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
833 |
return mode.name; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
834 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
835 |
|
38539 | 836 |
/** |
837 |
* Retain (or delete from retention) a previously set mode. |
|
838 |
* |
|
839 |
* @return all retained modes encoded into a String |
|
840 |
*/ |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
841 |
String retainMode() { |
38539 | 842 |
at.allowedOptions("-delete"); |
843 |
String umode = nextModeIdentifier(); |
|
844 |
// -delete is the only valid option, fail for anything else |
|
845 |
checkOptionsAndRemainingInput(); |
|
846 |
boolean deleteOption = at.hasOption("-delete"); |
|
847 |
// Lookup the mode |
|
848 |
Mode m; |
|
849 |
if (!valid) { |
|
850 |
m = null; |
|
851 |
// Skip this stuff, we have failed already |
|
852 |
} else if (deleteOption) { |
|
853 |
// If delete, allow for deleting, from retention, a mode that |
|
854 |
// has been locally deleted but is retained. |
|
855 |
// Also require the full name. |
|
856 |
m = modeMap.get(umode); |
|
857 |
if (m == null && !retainedMap.containsKey(umode)) { |
|
858 |
errorat("jshell.err.mode.unknown", umode); |
|
859 |
valid = false; |
|
860 |
} |
|
861 |
} else { |
|
862 |
// For retain do normal lookup and checking |
|
863 |
m = toMode(umode); |
|
864 |
} |
|
865 |
||
866 |
// Built-in modes cannot be retained or deleted |
|
867 |
if (valid && m != null && m.readOnly) { |
|
868 |
errorat("jshell.err.not.valid.with.predefined.mode", umode); |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
869 |
valid = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
870 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
871 |
if (valid) { |
38539 | 872 |
if (deleteOption) { |
873 |
if (mode.name.equals(umode)) { |
|
874 |
// Cannot delete the current mode out from under us |
|
875 |
errorat("jshell.err.cannot.delete.current.mode", umode); |
|
876 |
valid = false; |
|
877 |
} else if (retainedCurrentMode != null && retainedCurrentMode.name.equals(umode)) { |
|
878 |
// Cannot delete the retained mode or re-start has error |
|
879 |
errorat("jshell.err.cannot.delete.retained.mode", umode); |
|
880 |
valid = false; |
|
881 |
} else { |
|
882 |
// Delete the mode |
|
883 |
modeMap.remove(umode); |
|
884 |
retainedMap.remove(umode); |
|
885 |
} |
|
886 |
} else { |
|
887 |
// Retain the current encoding |
|
888 |
retainedMap.put(m.name, m.encode()); |
|
889 |
} |
|
890 |
} |
|
891 |
if (valid) { |
|
892 |
// Join all the retained encodings |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
893 |
return String.join(RECORD_SEPARATOR, retainedMap.values()); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
894 |
} else { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
895 |
fluffmsg("jshell.msg.see", "/help /retain mode"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
896 |
return null; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
897 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
898 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
899 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
900 |
boolean restoreEncodedModes(String allEncoded) { |
38539 | 901 |
try { |
902 |
// Iterate over each record in each encoded mode |
|
903 |
String[] ms = allEncoded.split(RECORD_SEPARATOR); |
|
904 |
Iterator<String> itr = Arrays.asList(ms).iterator(); |
|
905 |
while (itr.hasNext()) { |
|
906 |
// Reconstruct the encoded mode |
|
907 |
Mode m = new Mode(itr); |
|
908 |
modeMap.put(m.name, m); |
|
909 |
// Continue to retain it a new retains occur |
|
910 |
retainedMap.put(m.name, m.encode()); |
|
911 |
} |
|
912 |
return true; |
|
913 |
} catch (Throwable exc) { |
|
914 |
// Catastrophic corruption -- clear map |
|
915 |
errorat("jshell.err.retained.mode.failure", exc); |
|
916 |
retainedMap.clear(); |
|
917 |
return false; |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
918 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
919 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
920 |
|
38513 | 921 |
// install the format of a field under parsed selectors |
922 |
boolean installFormat(Mode m, String field, String format, String help) { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
923 |
String slRaw; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
924 |
List<SelectorList> slList = new ArrayList<>(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
925 |
while (valid && (slRaw = at.next()) != null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
926 |
SelectorList sl = new SelectorList(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
927 |
sl.parseSelectorList(slRaw); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
928 |
slList.add(sl); |
36494 | 929 |
} |
930 |
if (valid) { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
931 |
if (slList.isEmpty()) { |
38513 | 932 |
// No selectors specified, then always the format |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
933 |
m.set(field, ALWAYS, format); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
934 |
} else { |
38513 | 935 |
// Set the format of the field for specified selector |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
936 |
slList.stream() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
937 |
.forEach(sl -> m.set(field, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
938 |
sl.cases.getSet(), sl.actions.getSet(), sl.whens.getSet(), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
939 |
sl.resolves.getSet(), sl.unresolvedCounts.getSet(), sl.errorCounts.getSet(), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
940 |
format)); |
36494 | 941 |
} |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
942 |
} else { |
38513 | 943 |
fluffmsg("jshell.msg.see", help); |
36494 | 944 |
} |
945 |
return valid; |
|
946 |
} |
|
947 |
||
38539 | 948 |
void checkOptionsAndRemainingInput() { |
949 |
if (!valid) { |
|
950 |
return; |
|
951 |
} |
|
952 |
String junk = at.remainder(); |
|
953 |
if (!junk.isEmpty()) { |
|
954 |
errorat("jshell.err.unexpected.at.end", junk); |
|
955 |
valid = false; |
|
956 |
} else { |
|
957 |
String bad = at.badOptions(); |
|
958 |
if (!bad.isEmpty()) { |
|
959 |
errorat("jshell.err.unknown.option", bad); |
|
960 |
valid = false; |
|
961 |
} |
|
962 |
} |
|
963 |
} |
|
964 |
||
965 |
/** |
|
966 |
* Check that the specified string is an identifier (Java identifier). |
|
967 |
* If null display the missing error. If it is not an identifier, |
|
968 |
* display the error. |
|
969 |
* |
|
970 |
* @param id the string to check, MUST be the most recently retrieved |
|
971 |
* token from 'at'. |
|
972 |
* @param missing the resource error to display if null |
|
973 |
* @param err the resource error to display if not an identifier |
|
974 |
* @return the identifier string, or null if null or not an identifier |
|
975 |
*/ |
|
976 |
String toIdentifier(String id, String missing, String err) { |
|
977 |
if (id == null) { |
|
978 |
errorat(missing); |
|
979 |
valid = false; |
|
980 |
return null; |
|
981 |
} |
|
982 |
if (at.isQuoted() || |
|
983 |
!id.codePoints().allMatch(cp -> Character.isJavaIdentifierPart(cp))) { |
|
984 |
errorat(err, id); |
|
985 |
valid = false; |
|
986 |
return null; |
|
987 |
} |
|
988 |
return id; |
|
989 |
} |
|
990 |
||
991 |
String toModeIdentifier(String id) { |
|
992 |
return toIdentifier(id, "jshell.err.missing.mode", "jshell.err.mode.name"); |
|
993 |
} |
|
994 |
||
995 |
String nextModeIdentifier() { |
|
996 |
return toModeIdentifier(at.next()); |
|
997 |
} |
|
998 |
||
36494 | 999 |
Mode nextMode() { |
38539 | 1000 |
String umode = nextModeIdentifier(); |
36494 | 1001 |
return toMode(umode); |
1002 |
} |
|
1003 |
||
1004 |
Mode toMode(String umode) { |
|
38539 | 1005 |
if (!valid) { |
1006 |
return null; |
|
1007 |
} |
|
1008 |
if (umode == null) { |
|
1009 |
errorat("jshell.err.missing.mode"); |
|
36494 | 1010 |
valid = false; |
1011 |
return null; |
|
1012 |
} |
|
1013 |
Mode m = modeMap.get(umode); |
|
1014 |
if (m != null) { |
|
1015 |
return m; |
|
1016 |
} |
|
1017 |
// Failing an exact match, go searching |
|
1018 |
Mode[] matches = modeMap.entrySet().stream() |
|
1019 |
.filter(e -> e.getKey().startsWith(umode)) |
|
1020 |
.map(e -> e.getValue()) |
|
1021 |
.toArray(size -> new Mode[size]); |
|
1022 |
if (matches.length == 1) { |
|
1023 |
return matches[0]; |
|
1024 |
} else { |
|
1025 |
valid = false; |
|
1026 |
if (matches.length == 0) { |
|
36990 | 1027 |
errorat("jshell.err.feedback.does.not.match.mode", umode); |
36494 | 1028 |
} else { |
36990 | 1029 |
errorat("jshell.err.feedback.ambiguous.mode", umode); |
36494 | 1030 |
} |
37640
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1031 |
printFeedbackModes(); |
36494 | 1032 |
return null; |
1033 |
} |
|
1034 |
} |
|
1035 |
||
37640
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1036 |
void printFeedbackModes() { |
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1037 |
fluffmsg("jshell.msg.feedback.mode.following"); |
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1038 |
modeMap.keySet().stream() |
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1039 |
.forEach(mk -> fluff(" %s", mk)); |
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1040 |
} |
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1041 |
|
36494 | 1042 |
// Test if the format string is correctly |
1043 |
final String nextFormat() { |
|
1044 |
String format = at.next(); |
|
1045 |
if (format == null) { |
|
36990 | 1046 |
errorat("jshell.err.feedback.expected.format"); |
36494 | 1047 |
valid = false; |
1048 |
return null; |
|
1049 |
} |
|
1050 |
if (!at.isQuoted()) { |
|
36990 | 1051 |
errorat("jshell.err.feedback.must.be.quoted", format); |
36494 | 1052 |
valid = false; |
1053 |
return null; |
|
1054 |
} |
|
1055 |
return format; |
|
1056 |
} |
|
1057 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1058 |
class SelectorList { |
36494 | 1059 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1060 |
SelectorCollector<FormatCase> cases = new SelectorCollector<>(FormatCase.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1061 |
SelectorCollector<FormatAction> actions = new SelectorCollector<>(FormatAction.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1062 |
SelectorCollector<FormatWhen> whens = new SelectorCollector<>(FormatWhen.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1063 |
SelectorCollector<FormatResolve> resolves = new SelectorCollector<>(FormatResolve.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1064 |
SelectorCollector<FormatUnresolved> unresolvedCounts = new SelectorCollector<>(FormatUnresolved.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1065 |
SelectorCollector<FormatErrors> errorCounts = new SelectorCollector<>(FormatErrors.all); |
36494 | 1066 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1067 |
final void parseSelectorList(String sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1068 |
for (String s : sl.split("-")) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1069 |
SelectorCollector<?> lastCollector = null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1070 |
for (String as : s.split(",")) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1071 |
if (!as.isEmpty()) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1072 |
Selector<?> sel = selectorMap.get(as); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1073 |
if (sel == null) { |
36990 | 1074 |
errorat("jshell.err.feedback.not.a.valid.selector", as, s); |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1075 |
valid = false; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1076 |
return; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1077 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1078 |
SelectorCollector<?> collector = sel.collector(this); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1079 |
if (lastCollector == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1080 |
if (!collector.isEmpty()) { |
36990 | 1081 |
errorat("jshell.err.feedback.multiple.sections", as, s); |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1082 |
valid = false; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1083 |
return; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1084 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1085 |
} else if (collector != lastCollector) { |
36990 | 1086 |
errorat("jshell.err.feedback.different.selector.kinds", as, s); |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1087 |
valid = false; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1088 |
return; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1089 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1090 |
collector.add(sel); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1091 |
lastCollector = collector; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1092 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1093 |
} |
36494 | 1094 |
} |
1095 |
} |
|
1096 |
} |
|
1097 |
} |
|
1098 |
} |