author | rfield |
Thu, 20 Oct 2016 12:53:11 -0700 | |
changeset 41635 | cb3d04878117 |
parent 40765 | 6f9556cf4404 |
child 41937 | 1313399705e9 |
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; |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
31 |
import java.util.Collections; |
36494 | 32 |
import java.util.EnumSet; |
33 |
import java.util.HashMap; |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
34 |
import java.util.HashSet; |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
35 |
import java.util.Iterator; |
36494 | 36 |
import java.util.List; |
37 |
import java.util.Locale; |
|
38 |
import java.util.Map; |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
39 |
import java.util.Map.Entry; |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
40 |
import java.util.Objects; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
41 |
import java.util.Set; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
42 |
import java.util.StringJoiner; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
43 |
import java.util.function.BiConsumer; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
44 |
import java.util.function.BinaryOperator; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
45 |
import java.util.function.Consumer; |
40765
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
46 |
import java.util.function.Function; |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
47 |
import java.util.function.Supplier; |
36494 | 48 |
import java.util.regex.Matcher; |
49 |
import java.util.regex.Pattern; |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
50 |
import java.util.stream.Collector; |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
51 |
import static java.util.stream.Collectors.joining; |
40765
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
52 |
import static java.util.stream.Collectors.toMap; |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
53 |
import static jdk.internal.jshell.tool.ContinuousCompletionProvider.PERFECT_MATCHER; |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
54 |
import jdk.internal.jshell.tool.JShellTool.CompletionProvider; |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
55 |
import static jdk.internal.jshell.tool.JShellTool.EMPTY_COMPLETION_PROVIDER; |
36494 | 56 |
|
57 |
/** |
|
58 |
* Feedback customization support |
|
59 |
* |
|
60 |
* @author Robert Field |
|
61 |
*/ |
|
62 |
class Feedback { |
|
63 |
||
64 |
// Patern for substituted fields within a customized format string |
|
65 |
private static final Pattern FIELD_PATTERN = Pattern.compile("\\{(.*?)\\}"); |
|
66 |
||
38513 | 67 |
// Internal field name for truncation length |
68 |
private static final String TRUNCATION_FIELD = "<truncation>"; |
|
69 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
70 |
// For encoding to Properties String |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
71 |
private static final String RECORD_SEPARATOR = "\u241E"; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
72 |
|
38539 | 73 |
// Current mode -- initial value is placeholder during start-up |
74 |
private Mode mode = new Mode(""); |
|
75 |
||
76 |
// Retained current mode -- for checks |
|
77 |
private Mode retainedCurrentMode = null; |
|
36494 | 78 |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
79 |
// Mapping of mode name to mode |
36494 | 80 |
private final Map<String, Mode> modeMap = new HashMap<>(); |
81 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
82 |
// Mapping of mode names to encoded retained mode |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
83 |
private final Map<String, String> retainedMap = new HashMap<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
84 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
85 |
// Mapping selector enum names to enums |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
86 |
private final Map<String, Selector<?>> selectorMap = new HashMap<>(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
87 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
88 |
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
|
89 |
FormatResolve.all, FormatUnresolved.all, FormatErrors.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
90 |
private static final long ANY = 0L; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
91 |
|
36494 | 92 |
public boolean shouldDisplayCommandFluff() { |
93 |
return mode.commandFluff; |
|
94 |
} |
|
95 |
||
96 |
public String getPre() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
97 |
return mode.format("pre", ANY); |
36494 | 98 |
} |
99 |
||
100 |
public String getPost() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
101 |
return mode.format("post", ANY); |
36494 | 102 |
} |
103 |
||
104 |
public String getErrorPre() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
105 |
return mode.format("errorpre", ANY); |
36494 | 106 |
} |
107 |
||
108 |
public String getErrorPost() { |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
109 |
return mode.format("errorpost", ANY); |
36494 | 110 |
} |
111 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
112 |
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
|
113 |
FormatResolve fr, FormatUnresolved fu, FormatErrors fe, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
name, type, value, unresolved, errorLines); |
36494 | 117 |
} |
118 |
||
119 |
public String getPrompt(String nextId) { |
|
120 |
return mode.getPrompt(nextId); |
|
121 |
} |
|
122 |
||
123 |
public String getContinuationPrompt(String nextId) { |
|
124 |
return mode.getContinuationPrompt(nextId); |
|
125 |
} |
|
126 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
127 |
public boolean setFeedback(MessageHandler messageHandler, ArgTokenizer at, Consumer<String> retainer) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
128 |
return new Setter(messageHandler, at).setFeedback(retainer); |
36494 | 129 |
} |
130 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
131 |
public boolean setFormat(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
132 |
return new Setter(messageHandler, at).setFormat(); |
36494 | 133 |
} |
134 |
||
38513 | 135 |
public boolean setTruncation(MessageHandler messageHandler, ArgTokenizer at) { |
136 |
return new Setter(messageHandler, at).setTruncation(); |
|
137 |
} |
|
138 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
139 |
public boolean setMode(MessageHandler messageHandler, ArgTokenizer at, Consumer<String> retainer) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
140 |
return new Setter(messageHandler, at).setMode(retainer); |
36494 | 141 |
} |
142 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
143 |
public boolean setPrompt(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
144 |
return new Setter(messageHandler, at).setPrompt(); |
36494 | 145 |
} |
146 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
147 |
public boolean restoreEncodedModes(MessageHandler messageHandler, String encoded) { |
38539 | 148 |
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
|
149 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
150 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
151 |
public void markModesReadOnly() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
152 |
modeMap.values().stream() |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
153 |
.forEach(m -> m.readOnly = true); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
154 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
155 |
|
40765
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
156 |
JShellTool.CompletionProvider modeCompletions() { |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
157 |
return modeCompletions(EMPTY_COMPLETION_PROVIDER); |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
158 |
} |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
159 |
|
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
160 |
JShellTool.CompletionProvider modeCompletions(CompletionProvider successor) { |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
161 |
return new ContinuousCompletionProvider( |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
162 |
() -> modeMap.keySet().stream() |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
163 |
.collect(toMap(Function.identity(), m -> successor)), |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
164 |
PERFECT_MATCHER); |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
165 |
} |
6f9556cf4404
8164825: jshell tool: Completion for subcommand
shinyafox
parents:
40600
diff
changeset
|
166 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
167 |
{ |
40600
3874367e6e6f
8156984: JShell tool: for (FormatCase e : EnumSet.allOf(FormatCase.class))
ntv
parents:
38539
diff
changeset
|
168 |
for (FormatCase e : FormatCase.all) |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
169 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
40600
3874367e6e6f
8156984: JShell tool: for (FormatCase e : EnumSet.allOf(FormatCase.class))
ntv
parents:
38539
diff
changeset
|
170 |
for (FormatAction e : FormatAction.all) |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
171 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
40600
3874367e6e6f
8156984: JShell tool: for (FormatCase e : EnumSet.allOf(FormatCase.class))
ntv
parents:
38539
diff
changeset
|
172 |
for (FormatResolve e : FormatResolve.all) |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
173 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
40600
3874367e6e6f
8156984: JShell tool: for (FormatCase e : EnumSet.allOf(FormatCase.class))
ntv
parents:
38539
diff
changeset
|
174 |
for (FormatUnresolved e : FormatUnresolved.all) |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
175 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
40600
3874367e6e6f
8156984: JShell tool: for (FormatCase e : EnumSet.allOf(FormatCase.class))
ntv
parents:
38539
diff
changeset
|
176 |
for (FormatErrors e : FormatErrors.all) |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
177 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
40600
3874367e6e6f
8156984: JShell tool: for (FormatCase e : EnumSet.allOf(FormatCase.class))
ntv
parents:
38539
diff
changeset
|
178 |
for (FormatWhen e : FormatWhen.all) |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
179 |
selectorMap.put(e.name().toLowerCase(Locale.US), e); |
36494 | 180 |
} |
181 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
182 |
private static class SelectorSets { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
183 |
Set<FormatCase> cc; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
184 |
Set<FormatAction> ca; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
185 |
Set<FormatWhen> cw; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
186 |
Set<FormatResolve> cr; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
187 |
Set<FormatUnresolved> cu; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
188 |
Set<FormatErrors> ce; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
189 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
190 |
|
36494 | 191 |
/** |
192 |
* Holds all the context of a mode mode |
|
193 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
194 |
private static class Mode { |
36494 | 195 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
196 |
// Name of mode |
36494 | 197 |
final String name; |
198 |
||
199 |
// Display command verification/information |
|
38539 | 200 |
boolean commandFluff; |
36494 | 201 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
202 |
// Event cases: class, method, expression, ... |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
203 |
final Map<String, List<Setting>> cases; |
36494 | 204 |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
205 |
boolean readOnly = false; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
206 |
|
36494 | 207 |
String prompt = "\n-> "; |
208 |
String continuationPrompt = ">> "; |
|
209 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
210 |
static class Setting { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
211 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
212 |
final long enumBits; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
213 |
final String format; |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
214 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
215 |
Setting(long enumBits, String format) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
216 |
this.enumBits = enumBits; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
217 |
this.format = format; |
36494 | 218 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
219 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
220 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
221 |
public boolean equals(Object o) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
222 |
if (o instanceof Setting) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
223 |
Setting ing = (Setting) o; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
224 |
return enumBits == ing.enumBits && format.equals(ing.format); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
225 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
226 |
return false; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
227 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
228 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
229 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
230 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
231 |
public int hashCode() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
232 |
int hash = 7; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
233 |
hash = 67 * hash + (int) (this.enumBits ^ (this.enumBits >>> 32)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
234 |
hash = 67 * hash + Objects.hashCode(this.format); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
235 |
return hash; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
236 |
} |
36494 | 237 |
} |
238 |
||
239 |
/** |
|
240 |
* Set up an empty mode. |
|
241 |
* |
|
242 |
* @param name |
|
243 |
* @param commandFluff True if should display command fluff messages |
|
244 |
*/ |
|
38539 | 245 |
Mode(String name) { |
36494 | 246 |
this.name = name; |
38539 | 247 |
this.cases = new HashMap<>(); |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
248 |
add("name", new Setting(ALWAYS, "%1$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
249 |
add("type", new Setting(ALWAYS, "%2$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
250 |
add("value", new Setting(ALWAYS, "%3$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
251 |
add("unresolved", new Setting(ALWAYS, "%4$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
252 |
add("errors", new Setting(ALWAYS, "%5$s")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
253 |
add("err", new Setting(ALWAYS, "%6$s")); |
36494 | 254 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
255 |
add("errorline", new Setting(ALWAYS, " {err}%n")); |
36494 | 256 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
257 |
add("pre", new Setting(ALWAYS, "| ")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
258 |
add("post", new Setting(ALWAYS, "%n")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
259 |
add("errorpre", new Setting(ALWAYS, "| ")); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
260 |
add("errorpost", new Setting(ALWAYS, "%n")); |
36494 | 261 |
} |
262 |
||
263 |
/** |
|
264 |
* Set up a copied mode. |
|
265 |
* |
|
266 |
* @param name |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
267 |
* @param m Mode to copy, or null for no fresh |
36494 | 268 |
*/ |
38539 | 269 |
Mode(String name, Mode m) { |
36494 | 270 |
this.name = name; |
38539 | 271 |
this.commandFluff = m.commandFluff; |
272 |
this.prompt = m.prompt; |
|
273 |
this.continuationPrompt = m.continuationPrompt; |
|
274 |
this.cases = new HashMap<>(); |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
275 |
m.cases.entrySet().stream() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
276 |
.forEach(fes -> fes.getValue() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
277 |
.forEach(ing -> add(fes.getKey(), ing))); |
36494 | 278 |
|
279 |
} |
|
280 |
||
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
281 |
/** |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
282 |
* Set up a mode reconstituted from a preferences string. |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
283 |
* |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
284 |
* @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
|
285 |
* subsequent encoded modes |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
286 |
*/ |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
287 |
Mode(Iterator<String> it) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
288 |
this.name = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
289 |
this.commandFluff = Boolean.parseBoolean(it.next()); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
290 |
this.prompt = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
291 |
this.continuationPrompt = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
292 |
cases = new HashMap<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
293 |
String field; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
294 |
while (!(field = it.next()).equals("***")) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
295 |
String open = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
296 |
assert open.equals("("); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
297 |
List<Setting> settings = new ArrayList<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
298 |
String bits; |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
299 |
while (!(bits = it.next()).equals(")")) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
300 |
String format = it.next(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
301 |
Setting ing = new Setting(Long.parseLong(bits), format); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
302 |
settings.add(ing); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
303 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
304 |
cases.put(field, settings); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
305 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
306 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
307 |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
308 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
309 |
public boolean equals(Object o) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
310 |
if (o instanceof Mode) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
311 |
Mode m = (Mode) o; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
312 |
return name.equals((m.name)) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
313 |
&& commandFluff == m.commandFluff |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
314 |
&& prompt.equals((m.prompt)) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
315 |
&& continuationPrompt.equals((m.continuationPrompt)) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
316 |
&& cases.equals((m.cases)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
317 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
318 |
return false; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
319 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
320 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
321 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
322 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
323 |
public int hashCode() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
324 |
return Objects.hashCode(name); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
325 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
326 |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
327 |
/** |
38539 | 328 |
* Set if this mode displays informative/confirmational messages on |
329 |
* commands. |
|
330 |
* |
|
331 |
* @param fluff the value to set |
|
332 |
*/ |
|
333 |
void setCommandFluff(boolean fluff) { |
|
334 |
commandFluff = fluff; |
|
335 |
} |
|
336 |
||
337 |
/** |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
338 |
* 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
|
339 |
* |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
340 |
* @return the string representation |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
341 |
*/ |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
342 |
String encode() { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
343 |
List<String> el = new ArrayList<>(); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
344 |
el.add(name); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
345 |
el.add(String.valueOf(commandFluff)); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
346 |
el.add(prompt); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
347 |
el.add(continuationPrompt); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
348 |
for (Entry<String, List<Setting>> es : cases.entrySet()) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
349 |
el.add(es.getKey()); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
350 |
el.add("("); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
351 |
for (Setting ing : es.getValue()) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
352 |
el.add(String.valueOf(ing.enumBits)); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
353 |
el.add(ing.format); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
354 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
355 |
el.add(")"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
356 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
357 |
el.add("***"); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
358 |
return String.join(RECORD_SEPARATOR, el); |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
359 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
360 |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
361 |
private void add(String field, Setting ing) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
362 |
List<Setting> settings = cases.get(field); |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
363 |
if (settings == null) { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
364 |
settings = new ArrayList<>(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
365 |
cases.put(field, settings); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
366 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
367 |
// remove obscured settings |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
368 |
long mask = ~ing.enumBits; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
369 |
settings.removeIf(t -> (t.enumBits & mask) == 0); |
36494 | 370 |
} |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
371 |
settings.add(ing); |
36494 | 372 |
} |
373 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
374 |
void set(String field, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
375 |
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
|
376 |
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
|
377 |
String format) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
378 |
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
|
379 |
set(field, bits, format); |
36494 | 380 |
} |
381 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
382 |
void set(String field, long bits, String format) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
383 |
add(field, new Setting(bits, format)); |
36494 | 384 |
} |
385 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
386 |
/** |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
387 |
* Lookup format Replace fields with context specific formats. |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
388 |
* |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
389 |
* @return format string |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
390 |
*/ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
391 |
String format(String field, long bits) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
392 |
List<Setting> settings = cases.get(field); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
393 |
if (settings == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
394 |
return ""; //TODO error? |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
395 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
396 |
String format = null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
397 |
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
|
398 |
Setting ing = settings.get(i); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
399 |
long mask = ing.enumBits; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
400 |
if ((bits & mask) == bits) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
401 |
format = ing.format; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
402 |
break; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
403 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
404 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
405 |
if (format == null || format.isEmpty()) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
406 |
return ""; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
407 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
408 |
Matcher m = FIELD_PATTERN.matcher(format); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
409 |
StringBuffer sb = new StringBuffer(format.length()); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
410 |
while (m.find()) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
411 |
String fieldName = m.group(1); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
412 |
String sub = format(fieldName, bits); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
413 |
m.appendReplacement(sb, Matcher.quoteReplacement(sub)); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
414 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
415 |
m.appendTail(sb); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
416 |
return sb.toString(); |
36494 | 417 |
} |
418 |
||
38513 | 419 |
// 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
|
420 |
String format(FormatCase fc, FormatAction fa, FormatWhen fw, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
421 |
FormatResolve fr, FormatUnresolved fu, FormatErrors fe, |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
422 |
String name, String type, String value, String unresolved, List<String> errorLines) { |
38513 | 423 |
// 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
|
424 |
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
|
425 |
String fname = name==null? "" : name; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
426 |
String ftype = type==null? "" : type; |
38513 | 427 |
// Compute the representation of value |
428 |
String fvalue; |
|
429 |
if (value==null) { |
|
430 |
fvalue = ""; |
|
431 |
} else { |
|
432 |
// Retrieve the truncation length |
|
433 |
String truncField = format(TRUNCATION_FIELD, bits); |
|
434 |
if (truncField.isEmpty()) { |
|
435 |
// No truncation set, use whole value |
|
436 |
fvalue = value; |
|
437 |
} else { |
|
438 |
// Convert truncation length to int |
|
439 |
// this is safe since it has been tested before it is set |
|
440 |
int trunc = Integer.parseUnsignedInt(truncField); |
|
441 |
if (value.length() > trunc) { |
|
442 |
if (trunc <= 5) { |
|
443 |
// Very short truncations have no room for "..." |
|
444 |
fvalue = value.substring(0, trunc); |
|
445 |
} else { |
|
446 |
// Normal truncation, make total length equal truncation length |
|
447 |
fvalue = value.substring(0, trunc - 4) + " ..."; |
|
448 |
} |
|
449 |
} else { |
|
450 |
// Within truncation length, use whole value |
|
451 |
fvalue = value; |
|
452 |
} |
|
453 |
} |
|
454 |
} |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
455 |
String funresolved = unresolved==null? "" : unresolved; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
456 |
String errors = errorLines.stream() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
457 |
.map(el -> String.format( |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
458 |
format("errorline", bits), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
459 |
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
|
460 |
.collect(joining()); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
461 |
return String.format( |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
462 |
format("display", bits), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
463 |
fname, ftype, fvalue, funresolved, errors, "*cannot-use-err-here*"); |
36494 | 464 |
} |
465 |
||
466 |
void setPrompts(String prompt, String continuationPrompt) { |
|
467 |
this.prompt = prompt; |
|
468 |
this.continuationPrompt = continuationPrompt; |
|
469 |
} |
|
470 |
||
471 |
String getPrompt(String nextId) { |
|
472 |
return String.format(prompt, nextId); |
|
473 |
} |
|
474 |
||
475 |
String getContinuationPrompt(String nextId) { |
|
476 |
return String.format(continuationPrompt, nextId); |
|
477 |
} |
|
478 |
} |
|
479 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
480 |
// 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
|
481 |
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
|
482 |
FormatResolve fr, FormatUnresolved fu, FormatErrors fe) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
483 |
long res = 0L; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
484 |
res |= 1 << fc.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
485 |
res <<= FormatAction.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
486 |
res |= 1 << fa.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
487 |
res <<= FormatWhen.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
488 |
res |= 1 << fw.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
489 |
res <<= FormatResolve.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
490 |
res |= 1 << fr.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
491 |
res <<= FormatUnresolved.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
492 |
res |= 1 << fu.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
493 |
res <<= FormatErrors.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
494 |
res |= 1 << fe.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
495 |
return res; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
496 |
} |
36494 | 497 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
498 |
// 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
|
499 |
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
|
500 |
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
|
501 |
long res = 0L; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
502 |
for (FormatCase fc : cc) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
503 |
res |= 1 << fc.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
504 |
res <<= FormatAction.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
505 |
for (FormatAction fa : ca) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
506 |
res |= 1 << fa.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
507 |
res <<= FormatWhen.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
508 |
for (FormatWhen fw : cw) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
509 |
res |= 1 << fw.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
510 |
res <<= FormatResolve.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
511 |
for (FormatResolve fr : cr) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
512 |
res |= 1 << fr.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
513 |
res <<= FormatUnresolved.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
514 |
for (FormatUnresolved fu : cu) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
515 |
res |= 1 << fu.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
516 |
res <<= FormatErrors.count; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
517 |
for (FormatErrors fe : ce) |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
518 |
res |= 1 << fe.ordinal(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
519 |
return res; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
520 |
} |
36494 | 521 |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
522 |
private static SelectorSets unpackEnumbits(long enumBits) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
523 |
class Unpacker { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
524 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
525 |
SelectorSets u = new SelectorSets(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
526 |
long b = enumBits; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
527 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
528 |
<E extends Enum<E>> Set<E> unpackEnumbits(E[] values) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
529 |
Set<E> c = new HashSet<>(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
530 |
for (int i = 0; i < values.length; ++i) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
531 |
if ((b & (1 << i)) != 0) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
532 |
c.add(values[i]); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
533 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
534 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
535 |
b >>>= values.length; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
536 |
return c; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
537 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
538 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
539 |
SelectorSets unpack() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
540 |
// inverseof the order they were packed |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
541 |
u.ce = unpackEnumbits(FormatErrors.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
542 |
u.cu = unpackEnumbits(FormatUnresolved.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
543 |
u.cr = unpackEnumbits(FormatResolve.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
544 |
u.cw = unpackEnumbits(FormatWhen.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
545 |
u.ca = unpackEnumbits(FormatAction.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
546 |
u.cc = unpackEnumbits(FormatCase.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
547 |
return u; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
548 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
549 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
550 |
return new Unpacker().unpack(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
551 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
552 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
553 |
interface Selector<E extends Enum<E> & Selector<E>> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
554 |
SelectorCollector<E> collector(Setter.SelectorList sl); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
555 |
String doc(); |
36494 | 556 |
} |
557 |
||
558 |
/** |
|
559 |
* The event cases |
|
560 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
561 |
public enum FormatCase implements Selector<FormatCase> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
562 |
IMPORT("import declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
563 |
CLASS("class declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
564 |
INTERFACE("interface declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
565 |
ENUM("enum declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
566 |
ANNOTATION("annotation interface declaration"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
567 |
METHOD("method declaration -- note: {type}==parameter-types"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
568 |
VARDECL("variable declaration without init"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
569 |
VARINIT("variable declaration with init"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
570 |
EXPRESSION("expression -- note: {name}==scratch-variable-name"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
571 |
VARVALUE("variable value expression"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
572 |
ASSIGNMENT("assign variable"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
573 |
STATEMENT("statement"); |
36494 | 574 |
String doc; |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
575 |
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
|
576 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
577 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
578 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
579 |
public SelectorCollector<FormatCase> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
580 |
return sl.cases; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
581 |
} |
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 String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
585 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
586 |
} |
36494 | 587 |
|
588 |
private FormatCase(String doc) { |
|
589 |
this.doc = doc; |
|
590 |
} |
|
591 |
} |
|
592 |
||
593 |
/** |
|
594 |
* The event actions |
|
595 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
596 |
public enum FormatAction implements Selector<FormatAction> { |
36494 | 597 |
ADDED("snippet has been added"), |
598 |
MODIFIED("an existing snippet has been modified"), |
|
599 |
REPLACED("an existing snippet has been replaced with a new snippet"), |
|
600 |
OVERWROTE("an existing snippet has been overwritten"), |
|
601 |
DROPPED("snippet has been dropped"), |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
602 |
USED("snippet was used when it cannot be"); |
36494 | 603 |
String doc; |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
604 |
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
|
605 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
606 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
607 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
608 |
public SelectorCollector<FormatAction> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
609 |
return sl.actions; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
610 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
611 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
612 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
613 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
614 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
615 |
} |
36494 | 616 |
|
617 |
private FormatAction(String doc) { |
|
618 |
this.doc = doc; |
|
619 |
} |
|
620 |
} |
|
621 |
||
622 |
/** |
|
623 |
* When the event occurs: primary or update |
|
624 |
*/ |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
625 |
public enum FormatWhen implements Selector<FormatWhen> { |
36494 | 626 |
PRIMARY("the entered snippet"), |
627 |
UPDATE("an update to a dependent snippet"); |
|
628 |
String doc; |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
629 |
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
|
630 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
631 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
632 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
633 |
public SelectorCollector<FormatWhen> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
634 |
return sl.whens; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
635 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
636 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
637 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
638 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
639 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
640 |
} |
36494 | 641 |
|
642 |
private FormatWhen(String doc) { |
|
643 |
this.doc = doc; |
|
644 |
} |
|
645 |
} |
|
646 |
||
647 |
/** |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
648 |
* Resolution problems |
36494 | 649 |
*/ |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
650 |
public enum FormatResolve implements Selector<FormatResolve> { |
36494 | 651 |
OK("resolved correctly"), |
652 |
DEFINED("defined despite recoverably unresolved references"), |
|
653 |
NOTDEFINED("not defined because of recoverably unresolved references"); |
|
654 |
String doc; |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
655 |
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
|
656 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
657 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
658 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
659 |
public SelectorCollector<FormatResolve> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
660 |
return sl.resolves; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
661 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
662 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
663 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
664 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
665 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
666 |
} |
36494 | 667 |
|
668 |
private FormatResolve(String doc) { |
|
669 |
this.doc = doc; |
|
670 |
} |
|
671 |
} |
|
672 |
||
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
673 |
/** |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
674 |
* Count of unresolved references |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
675 |
*/ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
676 |
public enum FormatUnresolved implements Selector<FormatUnresolved> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
677 |
UNRESOLVED0("no names are unresolved"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
678 |
UNRESOLVED1("one name is unresolved"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
679 |
UNRESOLVED2("two or more names are unresolved"); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
680 |
String doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
681 |
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
|
682 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
683 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
684 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
685 |
public SelectorCollector<FormatUnresolved> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
686 |
return sl.unresolvedCounts; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
687 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
688 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
689 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
690 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
691 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
692 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
693 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
694 |
private FormatUnresolved(String doc) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
695 |
this.doc = doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
696 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
697 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
698 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
699 |
/** |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
700 |
* Count of unresolved references |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
701 |
*/ |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
702 |
public enum FormatErrors implements Selector<FormatErrors> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
703 |
ERROR0("no errors"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
704 |
ERROR1("one error"), |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
705 |
ERROR2("two or more errors"); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
706 |
String doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
707 |
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
|
708 |
static final int count = all.size(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
709 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
710 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
711 |
public SelectorCollector<FormatErrors> collector(Setter.SelectorList sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
712 |
return sl.errorCounts; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
713 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
714 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
715 |
@Override |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
716 |
public String doc() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
717 |
return doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
718 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
719 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
720 |
private FormatErrors(String doc) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
721 |
this.doc = doc; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
722 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
723 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
724 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
725 |
class SelectorCollector<E extends Enum<E> & Selector<E>> { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
726 |
final EnumSet<E> all; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
727 |
EnumSet<E> set = null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
728 |
SelectorCollector(EnumSet<E> all) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
729 |
this.all = all; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
730 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
731 |
void add(Object o) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
732 |
@SuppressWarnings("unchecked") |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
733 |
E e = (E) o; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
734 |
if (set == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
735 |
set = EnumSet.of(e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
736 |
} else { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
737 |
set.add(e); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
738 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
739 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
740 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
741 |
boolean isEmpty() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
742 |
return set == null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
743 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
744 |
|
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
745 |
EnumSet<E> getSet() { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
746 |
return set == null |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
747 |
? all |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
748 |
: set; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
749 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
750 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
751 |
|
36494 | 752 |
// 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
|
753 |
// 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
|
754 |
private class Setter { |
36494 | 755 |
|
756 |
private final ArgTokenizer at; |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
757 |
private final MessageHandler messageHandler; |
36494 | 758 |
boolean valid = true; |
759 |
||
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
760 |
Setter(MessageHandler messageHandler, ArgTokenizer at) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
761 |
this.messageHandler = messageHandler; |
36494 | 762 |
this.at = at; |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
763 |
at.allowedOptions("-retain"); |
36494 | 764 |
} |
765 |
||
766 |
void fluff(String format, Object... args) { |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
767 |
messageHandler.fluff(format, args); |
36494 | 768 |
} |
769 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
770 |
void hard(String format, Object... args) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
771 |
messageHandler.hard(format, args); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
772 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
773 |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
774 |
void fluffmsg(String messageKey, Object... args) { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
775 |
messageHandler.fluffmsg(messageKey, args); |
36494 | 776 |
} |
777 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
778 |
void hardmsg(String messageKey, Object... args) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
779 |
messageHandler.hardmsg(messageKey, args); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
780 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
781 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
782 |
boolean showFluff() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
783 |
return messageHandler.showFluff(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
784 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
785 |
|
36990 | 786 |
void errorat(String messageKey, Object... args) { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
787 |
if (!valid) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
788 |
// no spew of errors |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
789 |
return; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
790 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
791 |
valid = false; |
36990 | 792 |
Object[] a2 = Arrays.copyOf(args, args.length + 2); |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
793 |
a2[args.length] = at.whole(); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
37640
diff
changeset
|
794 |
messageHandler.errormsg(messageKey, a2); |
36494 | 795 |
} |
796 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
797 |
String selectorsToString(SelectorSets u) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
798 |
StringBuilder sb = new StringBuilder(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
799 |
selectorToString(sb, u.cc, FormatCase.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
800 |
selectorToString(sb, u.ca, FormatAction.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
801 |
selectorToString(sb, u.cw, FormatWhen.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
802 |
selectorToString(sb, u.cr, FormatResolve.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
803 |
selectorToString(sb, u.cu, FormatUnresolved.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
804 |
selectorToString(sb, u.ce, FormatErrors.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
805 |
return sb.toString(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
806 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
807 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
808 |
private <E extends Enum<E>> void selectorToString(StringBuilder sb, Set<E> c, E[] values) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
809 |
if (!c.containsAll(Arrays.asList(values))) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
810 |
sb.append(c.stream() |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
811 |
.sorted((x, y) -> x.ordinal() - y.ordinal()) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
812 |
.map(v -> v.name().toLowerCase(Locale.US)) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
813 |
.collect(new Collector<CharSequence, StringJoiner, String>() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
814 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
815 |
public BiConsumer<StringJoiner, CharSequence> accumulator() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
816 |
return StringJoiner::add; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
817 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
818 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
819 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
820 |
public Supplier<StringJoiner> supplier() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
821 |
return () -> new StringJoiner(",", (sb.length() == 0)? "" : "-", "") |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
822 |
.setEmptyValue(""); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
823 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
824 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
825 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
826 |
public BinaryOperator<StringJoiner> combiner() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
827 |
return StringJoiner::merge; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
828 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
829 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
830 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
831 |
public Function<StringJoiner, String> finisher() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
832 |
return StringJoiner::toString; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
833 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
834 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
835 |
@Override |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
836 |
public Set<Characteristics> characteristics() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
837 |
return Collections.emptySet(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
838 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
839 |
})); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
840 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
841 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
842 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
843 |
// Show format settings -- in a predictable order, for testing... |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
844 |
void showFormatSettings(Mode sm, String f) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
845 |
if (sm == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
846 |
modeMap.entrySet().stream() |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
847 |
.sorted((es1, es2) -> es1.getKey().compareTo(es2.getKey())) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
848 |
.forEach(m -> showFormatSettings(m.getValue(), f)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
849 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
850 |
sm.cases.entrySet().stream() |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
851 |
.filter(ec -> (f == null) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
852 |
? !ec.getKey().equals(TRUNCATION_FIELD) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
853 |
: ec.getKey().equals(f)) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
854 |
.sorted((ec1, ec2) -> ec1.getKey().compareTo(ec2.getKey())) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
855 |
.forEach(ec -> { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
856 |
ec.getValue().forEach(s -> { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
857 |
hard("/set format %s %s %s %s", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
858 |
sm.name, ec.getKey(), toStringLiteral(s.format), |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
859 |
selectorsToString(unpackEnumbits(s.enumBits))); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
860 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
861 |
}); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
862 |
}); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
863 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
864 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
865 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
866 |
void showTruncationSettings(Mode sm) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
867 |
if (sm == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
868 |
modeMap.values().forEach(m -> showTruncationSettings(m)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
869 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
870 |
List<Mode.Setting> trunc = sm.cases.get(TRUNCATION_FIELD); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
871 |
if (trunc != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
872 |
trunc.forEach(s -> { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
873 |
hard("/set truncation %s %s %s", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
874 |
sm.name, s.format, |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
875 |
selectorsToString(unpackEnumbits(s.enumBits))); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
876 |
}); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
877 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
878 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
879 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
880 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
881 |
void showPromptSettings(Mode sm) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
882 |
if (sm == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
883 |
modeMap.values().forEach(m -> showPromptSettings(m)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
884 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
885 |
hard("/set prompt %s %s %s", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
886 |
sm.name, |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
887 |
toStringLiteral(sm.prompt), |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
888 |
toStringLiteral(sm.continuationPrompt)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
889 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
890 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
891 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
892 |
void showModeSettings(String umode, String msg) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
893 |
if (umode == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
894 |
modeMap.values().forEach(n -> showModeSettings(n)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
895 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
896 |
Mode m; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
897 |
String retained = retainedMap.get(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
898 |
if (retained == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
899 |
m = searchForMode(umode, msg); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
900 |
if (m == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
901 |
return; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
902 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
903 |
umode = m.name; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
904 |
retained = retainedMap.get(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
905 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
906 |
m = modeMap.get(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
907 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
908 |
if (retained != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
909 |
Mode rm = new Mode(encodedModeIterator(retained)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
910 |
showModeSettings(rm); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
911 |
hard("/set mode -retain %s", umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
912 |
if (m != null && !m.equals(rm)) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
913 |
hard(""); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
914 |
showModeSettings(m); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
915 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
916 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
917 |
showModeSettings(m); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
918 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
919 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
920 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
921 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
922 |
void showModeSettings(Mode sm) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
923 |
hard("/set mode %s %s", |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
924 |
sm.name, sm.commandFluff ? "-command" : "-quiet"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
925 |
showPromptSettings(sm); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
926 |
showFormatSettings(sm, null); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
927 |
showTruncationSettings(sm); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
928 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
929 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
930 |
void showFeedbackSetting() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
931 |
if (retainedCurrentMode != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
932 |
hard("/set feedback -retain %s", retainedCurrentMode.name); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
933 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
934 |
if (mode != retainedCurrentMode) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
935 |
hard("/set feedback %s", mode.name); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
936 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
937 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
938 |
|
36494 | 939 |
// For /set prompt <mode> "<prompt>" "<continuation-prompt>" |
940 |
boolean setPrompt() { |
|
941 |
Mode m = nextMode(); |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
942 |
String prompt = nextFormat(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
943 |
String continuationPrompt = nextFormat(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
944 |
checkOptionsAndRemainingInput(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
945 |
if (valid && prompt == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
946 |
showPromptSettings(m); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
947 |
return valid; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
948 |
} |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
949 |
if (valid && m.readOnly) { |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
950 |
errorat("jshell.err.not.valid.with.predefined.mode", m.name); |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
951 |
} else if (continuationPrompt == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
952 |
errorat("jshell.err.continuation.prompt.required"); |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
953 |
} |
36494 | 954 |
if (valid) { |
955 |
m.setPrompts(prompt, continuationPrompt); |
|
956 |
} else { |
|
36990 | 957 |
fluffmsg("jshell.msg.see", "/help /set prompt"); |
36494 | 958 |
} |
959 |
return valid; |
|
960 |
} |
|
961 |
||
38539 | 962 |
/** |
963 |
* Set mode. Create, changed, or delete a feedback mode. For @{code /set |
|
964 |
* mode <mode> [<old-mode>] [-command|-quiet|-delete]}. |
|
965 |
* |
|
966 |
* @return true if successful |
|
967 |
*/ |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
968 |
boolean setMode(Consumer<String> retainer) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
969 |
class SetMode { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
970 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
971 |
final String umode; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
972 |
final String omode; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
973 |
final boolean commandOption; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
974 |
final boolean quietOption; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
975 |
final boolean deleteOption; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
976 |
final boolean retainOption; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
977 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
978 |
SetMode() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
979 |
at.allowedOptions("-command", "-quiet", "-delete", "-retain"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
980 |
umode = nextModeIdentifier(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
981 |
omode = nextModeIdentifier(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
982 |
checkOptionsAndRemainingInput(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
983 |
commandOption = at.hasOption("-command"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
984 |
quietOption = at.hasOption("-quiet"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
985 |
deleteOption = at.hasOption("-delete"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
986 |
retainOption = at.hasOption("-retain"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
987 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
988 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
989 |
void delete() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
990 |
// Note: delete, for safety reasons, does NOT do name matching |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
991 |
if (commandOption || quietOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
992 |
errorat("jshell.err.conflicting.options"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
993 |
} else if (!(retainOption ? retainedMap : modeMap).containsKey(umode)) { |
38539 | 994 |
// Cannot delete a mode that does not exist |
995 |
errorat("jshell.err.mode.unknown", umode); |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
996 |
} else if (omode != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
997 |
// old mode is for creation |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
998 |
errorat("jshell.err.unexpected.at.end", omode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
999 |
} else if (mode.name.equals(umode)) { |
38539 | 1000 |
// Cannot delete the current mode out from under us |
1001 |
errorat("jshell.err.cannot.delete.current.mode", umode); |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1002 |
} else if (retainOption && retainedCurrentMode != null && |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1003 |
retainedCurrentMode.name.equals(umode)) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1004 |
// Cannot delete the retained mode or re-start will have an error |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1005 |
errorat("jshell.err.cannot.delete.retained.mode", umode); |
38539 | 1006 |
} else { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1007 |
Mode m = modeMap.get(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1008 |
if (m != null && m.readOnly) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1009 |
errorat("jshell.err.not.valid.with.predefined.mode", umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1010 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1011 |
// Remove the mode |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1012 |
modeMap.remove(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1013 |
if (retainOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1014 |
// Remove the retained mode |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1015 |
retainedMap.remove(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1016 |
updateRetainedModes(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1017 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1018 |
} |
38539 | 1019 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1020 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1021 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1022 |
void retain() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1023 |
if (commandOption || quietOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1024 |
errorat("jshell.err.conflicting.options"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1025 |
} else if (omode != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1026 |
// old mode is for creation |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1027 |
errorat("jshell.err.unexpected.at.end", omode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1028 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1029 |
Mode m = modeMap.get(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1030 |
if (m == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1031 |
// can only retain existing modes |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1032 |
errorat("jshell.err.mode.unknown", umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1033 |
} else if (m.readOnly) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1034 |
errorat("jshell.err.not.valid.with.predefined.mode", umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1035 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1036 |
// Add to local cache of retained current encodings |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1037 |
retainedMap.put(m.name, m.encode()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1038 |
updateRetainedModes(); |
38539 | 1039 |
} |
1040 |
} |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1041 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1042 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1043 |
void updateRetainedModes() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1044 |
// Join all the retained encodings |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1045 |
String encoded = String.join(RECORD_SEPARATOR, retainedMap.values()); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1046 |
// Retain it |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1047 |
retainer.accept(encoded); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1048 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1049 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1050 |
void create() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1051 |
if (commandOption && quietOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1052 |
errorat("jshell.err.conflicting.options"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1053 |
} else if (!commandOption && !quietOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1054 |
errorat("jshell.err.mode.creation"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1055 |
} else if (modeMap.containsKey(umode)) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1056 |
// Mode already exists |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1057 |
errorat("jshell.err.mode.exists", umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1058 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1059 |
Mode om = searchForMode(omode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1060 |
if (valid) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1061 |
// We are copying an existing mode and/or creating a |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1062 |
// brand-new mode -- in either case create from scratch |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1063 |
Mode m = (om != null) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1064 |
? new Mode(umode, om) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1065 |
: new Mode(umode); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1066 |
modeMap.put(umode, m); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1067 |
fluffmsg("jshell.msg.feedback.new.mode", m.name); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1068 |
m.setCommandFluff(commandOption); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1069 |
} |
38539 | 1070 |
} |
1071 |
} |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1072 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1073 |
boolean set() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1074 |
if (valid && !commandOption && !quietOption && !deleteOption && |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1075 |
omode == null && !retainOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1076 |
// Not a creation, deletion, or retain -- show mode(s) |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1077 |
showModeSettings(umode, "jshell.err.mode.creation"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1078 |
} else if (valid && umode == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1079 |
errorat("jshell.err.missing.mode"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1080 |
} else if (valid && deleteOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1081 |
delete(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1082 |
} else if (valid && retainOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1083 |
retain(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1084 |
} else if (valid) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1085 |
create(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1086 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1087 |
if (!valid) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1088 |
fluffmsg("jshell.msg.see", "/help /set mode"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1089 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1090 |
return valid; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1091 |
} |
36494 | 1092 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1093 |
return new SetMode().set(); |
36494 | 1094 |
} |
1095 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1096 |
// For /set format <mode> <field> "<format>" <selector>... |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1097 |
boolean setFormat() { |
36494 | 1098 |
Mode m = nextMode(); |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1099 |
String field = toIdentifier(next(), "jshell.err.field.name"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1100 |
String format = nextFormat(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1101 |
if (valid && format == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1102 |
if (field != null && m != null && !m.cases.containsKey(field)) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1103 |
errorat("jshell.err.field.name", field); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1104 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1105 |
showFormatSettings(m, field); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1106 |
} |
36494 | 1107 |
} else { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1108 |
installFormat(m, field, format, "/help /set format"); |
36494 | 1109 |
} |
1110 |
return valid; |
|
1111 |
} |
|
1112 |
||
38513 | 1113 |
// For /set truncation <mode> <length> <selector>... |
1114 |
boolean setTruncation() { |
|
1115 |
Mode m = nextMode(); |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1116 |
String length = next(); |
38513 | 1117 |
if (length == null) { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1118 |
showTruncationSettings(m); |
38513 | 1119 |
} else { |
1120 |
try { |
|
1121 |
// Assure that integer format is correct |
|
1122 |
Integer.parseUnsignedInt(length); |
|
1123 |
} catch (NumberFormatException ex) { |
|
1124 |
errorat("jshell.err.truncation.length.not.integer", length); |
|
1125 |
} |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1126 |
// install length into an internal format field |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1127 |
installFormat(m, TRUNCATION_FIELD, length, "/help /set truncation"); |
38513 | 1128 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1129 |
return valid; |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1130 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1131 |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1132 |
// For /set feedback <mode> |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1133 |
boolean setFeedback(Consumer<String> retainer) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1134 |
String umode = next(); |
38539 | 1135 |
checkOptionsAndRemainingInput(); |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1136 |
boolean retainOption = at.hasOption("-retain"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1137 |
if (valid && umode == null && !retainOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1138 |
showFeedbackSetting(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1139 |
hard(""); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1140 |
showFeedbackModes(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1141 |
return true; |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1142 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1143 |
if (valid) { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1144 |
Mode m = umode == null |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1145 |
? mode |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1146 |
: searchForMode(toModeIdentifier(umode)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1147 |
if (valid && retainOption && !m.readOnly && !retainedMap.containsKey(m.name)) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1148 |
errorat("jshell.err.retained.feedback.mode.must.be.retained.or.predefined"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1149 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1150 |
if (valid) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1151 |
if (umode != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1152 |
mode = m; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1153 |
fluffmsg("jshell.msg.feedback.mode", mode.name); |
38539 | 1154 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1155 |
if (retainOption) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1156 |
retainedCurrentMode = m; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1157 |
retainer.accept(m.name); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1158 |
} |
38539 | 1159 |
} |
1160 |
} |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1161 |
if (!valid) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1162 |
fluffmsg("jshell.msg.see", "/help /set feedback"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1163 |
return false; |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1164 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1165 |
return true; |
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1166 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1167 |
|
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1168 |
boolean restoreEncodedModes(String allEncoded) { |
38539 | 1169 |
try { |
1170 |
// Iterate over each record in each encoded mode |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1171 |
Iterator<String> itr = encodedModeIterator(allEncoded); |
38539 | 1172 |
while (itr.hasNext()) { |
1173 |
// Reconstruct the encoded mode |
|
1174 |
Mode m = new Mode(itr); |
|
1175 |
modeMap.put(m.name, m); |
|
1176 |
// Continue to retain it a new retains occur |
|
1177 |
retainedMap.put(m.name, m.encode()); |
|
1178 |
} |
|
1179 |
return true; |
|
1180 |
} catch (Throwable exc) { |
|
1181 |
// Catastrophic corruption -- clear map |
|
1182 |
errorat("jshell.err.retained.mode.failure", exc); |
|
1183 |
retainedMap.clear(); |
|
1184 |
return false; |
|
38531
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1185 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1186 |
} |
c449daa25b45
8157200: jshell tool: Add /retain command to persist settings
rfield
parents:
38520
diff
changeset
|
1187 |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1188 |
Iterator<String> encodedModeIterator(String encoded) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1189 |
String[] ms = encoded.split(RECORD_SEPARATOR); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1190 |
return Arrays.asList(ms).iterator(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1191 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1192 |
|
38513 | 1193 |
// install the format of a field under parsed selectors |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1194 |
void 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
|
1195 |
String slRaw; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1196 |
List<SelectorList> slList = new ArrayList<>(); |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1197 |
while (valid && (slRaw = next()) != null) { |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1198 |
SelectorList sl = new SelectorList(); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1199 |
sl.parseSelectorList(slRaw); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1200 |
slList.add(sl); |
36494 | 1201 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1202 |
checkOptionsAndRemainingInput(); |
36494 | 1203 |
if (valid) { |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1204 |
if (m.readOnly) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1205 |
errorat("jshell.err.not.valid.with.predefined.mode", m.name); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1206 |
} else if (slList.isEmpty()) { |
38513 | 1207 |
// No selectors specified, then always the format |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1208 |
m.set(field, ALWAYS, format); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1209 |
} else { |
38513 | 1210 |
// 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
|
1211 |
slList.stream() |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1212 |
.forEach(sl -> m.set(field, |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1213 |
sl.cases.getSet(), sl.actions.getSet(), sl.whens.getSet(), |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1214 |
sl.resolves.getSet(), sl.unresolvedCounts.getSet(), sl.errorCounts.getSet(), |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1215 |
format)); |
36494 | 1216 |
} |
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1217 |
} else { |
38513 | 1218 |
fluffmsg("jshell.msg.see", help); |
36494 | 1219 |
} |
1220 |
} |
|
1221 |
||
38539 | 1222 |
void checkOptionsAndRemainingInput() { |
1223 |
String junk = at.remainder(); |
|
1224 |
if (!junk.isEmpty()) { |
|
1225 |
errorat("jshell.err.unexpected.at.end", junk); |
|
1226 |
} else { |
|
1227 |
String bad = at.badOptions(); |
|
1228 |
if (!bad.isEmpty()) { |
|
1229 |
errorat("jshell.err.unknown.option", bad); |
|
1230 |
} |
|
1231 |
} |
|
1232 |
} |
|
1233 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1234 |
String next() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1235 |
String s = at.next(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1236 |
if (s == null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1237 |
checkOptionsAndRemainingInput(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1238 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1239 |
return s; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1240 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1241 |
|
38539 | 1242 |
/** |
1243 |
* Check that the specified string is an identifier (Java identifier). |
|
1244 |
* If null display the missing error. If it is not an identifier, |
|
1245 |
* display the error. |
|
1246 |
* |
|
1247 |
* @param id the string to check, MUST be the most recently retrieved |
|
1248 |
* token from 'at'. |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1249 |
* @param missing null for no null error, otherwise the resource error to display if id is null |
38539 | 1250 |
* @param err the resource error to display if not an identifier |
1251 |
* @return the identifier string, or null if null or not an identifier |
|
1252 |
*/ |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1253 |
private String toIdentifier(String id, String err) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1254 |
if (!valid || id == null) { |
38539 | 1255 |
return null; |
1256 |
} |
|
1257 |
if (at.isQuoted() || |
|
1258 |
!id.codePoints().allMatch(cp -> Character.isJavaIdentifierPart(cp))) { |
|
1259 |
errorat(err, id); |
|
1260 |
return null; |
|
1261 |
} |
|
1262 |
return id; |
|
1263 |
} |
|
1264 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1265 |
private String toModeIdentifier(String id) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1266 |
return toIdentifier(id, "jshell.err.mode.name"); |
38539 | 1267 |
} |
1268 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1269 |
private String nextModeIdentifier() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1270 |
return toModeIdentifier(next()); |
38539 | 1271 |
} |
1272 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1273 |
private Mode nextMode() { |
38539 | 1274 |
String umode = nextModeIdentifier(); |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1275 |
return searchForMode(umode); |
36494 | 1276 |
} |
1277 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1278 |
private Mode searchForMode(String umode) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1279 |
return searchForMode(umode, null); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1280 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1281 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1282 |
private Mode searchForMode(String umode, String msg) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1283 |
if (!valid || umode == null) { |
36494 | 1284 |
return null; |
1285 |
} |
|
1286 |
Mode m = modeMap.get(umode); |
|
1287 |
if (m != null) { |
|
1288 |
return m; |
|
1289 |
} |
|
1290 |
// Failing an exact match, go searching |
|
1291 |
Mode[] matches = modeMap.entrySet().stream() |
|
1292 |
.filter(e -> e.getKey().startsWith(umode)) |
|
1293 |
.map(e -> e.getValue()) |
|
1294 |
.toArray(size -> new Mode[size]); |
|
1295 |
if (matches.length == 1) { |
|
1296 |
return matches[0]; |
|
1297 |
} else { |
|
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1298 |
if (msg != null) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1299 |
hardmsg(msg, ""); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1300 |
} |
36494 | 1301 |
if (matches.length == 0) { |
36990 | 1302 |
errorat("jshell.err.feedback.does.not.match.mode", umode); |
36494 | 1303 |
} else { |
36990 | 1304 |
errorat("jshell.err.feedback.ambiguous.mode", umode); |
36494 | 1305 |
} |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1306 |
if (showFluff()) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1307 |
showFeedbackModes(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1308 |
} |
36494 | 1309 |
return null; |
1310 |
} |
|
1311 |
} |
|
1312 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1313 |
void showFeedbackModes() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1314 |
if (!retainedMap.isEmpty()) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1315 |
hardmsg("jshell.msg.feedback.retained.mode.following"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1316 |
retainedMap.keySet().stream() |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1317 |
.sorted() |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1318 |
.forEach(mk -> hard(" %s", mk)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1319 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1320 |
hardmsg("jshell.msg.feedback.mode.following"); |
37640
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1321 |
modeMap.keySet().stream() |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1322 |
.sorted() |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1323 |
.forEach(mk -> hard(" %s", mk)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1324 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1325 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1326 |
// Read and test if the format string is correctly |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1327 |
private String nextFormat() { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1328 |
return toFormat(next()); |
37640
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1329 |
} |
42e5136a367c
8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents:
36990
diff
changeset
|
1330 |
|
36494 | 1331 |
// Test if the format string is correctly |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1332 |
private String toFormat(String format) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1333 |
if (!valid || format == null) { |
36494 | 1334 |
return null; |
1335 |
} |
|
1336 |
if (!at.isQuoted()) { |
|
36990 | 1337 |
errorat("jshell.err.feedback.must.be.quoted", format); |
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1338 |
return null; |
36494 | 1339 |
} |
1340 |
return format; |
|
1341 |
} |
|
1342 |
||
41635
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1343 |
// Convert to a quoted string |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1344 |
private String toStringLiteral(String s) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1345 |
StringBuilder sb = new StringBuilder(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1346 |
sb.append('"'); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1347 |
final int length = s.length(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1348 |
for (int offset = 0; offset < length;) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1349 |
final int codepoint = s.codePointAt(offset); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1350 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1351 |
switch (codepoint) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1352 |
case '\b': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1353 |
sb.append("\\b"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1354 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1355 |
case '\t': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1356 |
sb.append("\\t"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1357 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1358 |
case '\n': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1359 |
sb.append("\\n"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1360 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1361 |
case '\f': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1362 |
sb.append("\\f"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1363 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1364 |
case '\r': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1365 |
sb.append("\\r"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1366 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1367 |
case '\"': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1368 |
sb.append("\\\""); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1369 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1370 |
case '\'': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1371 |
sb.append("\\'"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1372 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1373 |
case '\\': |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1374 |
sb.append("\\\\"); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1375 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1376 |
default: |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1377 |
if (codepoint < 040) { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1378 |
sb.append(String.format("\\%o", codepoint)); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1379 |
} else { |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1380 |
sb.appendCodePoint(codepoint); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1381 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1382 |
break; |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1383 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1384 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1385 |
// do something with the codepoint |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1386 |
offset += Character.charCount(codepoint); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1387 |
|
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1388 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1389 |
sb.append('"'); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1390 |
return sb.toString(); |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1391 |
} |
cb3d04878117
8163840: jshell tool: provide way to display configuration settings
rfield
parents:
40765
diff
changeset
|
1392 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1393 |
class SelectorList { |
36494 | 1394 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1395 |
SelectorCollector<FormatCase> cases = new SelectorCollector<>(FormatCase.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1396 |
SelectorCollector<FormatAction> actions = new SelectorCollector<>(FormatAction.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1397 |
SelectorCollector<FormatWhen> whens = new SelectorCollector<>(FormatWhen.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1398 |
SelectorCollector<FormatResolve> resolves = new SelectorCollector<>(FormatResolve.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1399 |
SelectorCollector<FormatUnresolved> unresolvedCounts = new SelectorCollector<>(FormatUnresolved.all); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1400 |
SelectorCollector<FormatErrors> errorCounts = new SelectorCollector<>(FormatErrors.all); |
36494 | 1401 |
|
36718
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1402 |
final void parseSelectorList(String sl) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1403 |
for (String s : sl.split("-")) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1404 |
SelectorCollector<?> lastCollector = null; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1405 |
for (String as : s.split(",")) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1406 |
if (!as.isEmpty()) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1407 |
Selector<?> sel = selectorMap.get(as); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1408 |
if (sel == null) { |
36990 | 1409 |
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
|
1410 |
return; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1411 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1412 |
SelectorCollector<?> collector = sel.collector(this); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1413 |
if (lastCollector == null) { |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1414 |
if (!collector.isEmpty()) { |
36990 | 1415 |
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
|
1416 |
return; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1417 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1418 |
} else if (collector != lastCollector) { |
36990 | 1419 |
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
|
1420 |
return; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1421 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1422 |
collector.add(sel); |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1423 |
lastCollector = collector; |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1424 |
} |
bf40906bf49d
8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents:
36494
diff
changeset
|
1425 |
} |
36494 | 1426 |
} |
1427 |
} |
|
1428 |
} |
|
1429 |
} |
|
1430 |
} |