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