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