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