src/jdk.jshell/share/classes/jdk/jshell/Unit.java
author prr
Mon, 12 Feb 2018 08:56:44 -0800
changeset 49083 673be6f60323
parent 47216 71c04702a3d5
child 49416 f14852315495
permissions -rw-r--r--
8197546: Fix for 8171000 breaks Solaris + Linux builds Reviewed-by: serb, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
package jdk.jshell;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
import java.util.ArrayList;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
import java.util.Collection;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
import java.util.Collections;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
import java.util.LinkedHashSet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
import java.util.List;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
import java.util.Set;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
import java.util.stream.Stream;
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    35
import jdk.jshell.ClassTracker.ClassInfo;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import jdk.jshell.Snippet.Kind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
import jdk.jshell.Snippet.Status;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import jdk.jshell.Snippet.SubKind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
import jdk.jshell.TaskFactory.AnalyzeTask;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
import jdk.jshell.TaskFactory.CompileTask;
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    41
import jdk.jshell.spi.ExecutionControl.ClassBytecodes;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    42
import jdk.jshell.spi.ExecutionControl.ClassInstallException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    43
import jdk.jshell.spi.ExecutionControl.EngineTerminationException;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    44
import jdk.jshell.spi.ExecutionControl.NotImplementedException;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import static java.util.stream.Collectors.toList;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
import static java.util.stream.Collectors.toSet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_EVNT;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_GEN;
43134
006808ae5f6e 8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents: 42827
diff changeset
    49
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_WRAP;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
import static jdk.jshell.Snippet.Status.OVERWRITTEN;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
import static jdk.jshell.Snippet.Status.REJECTED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
import static jdk.jshell.Snippet.Status.VALID;
35000
952a7b4652f0 8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents: 34857
diff changeset
    55
import static jdk.jshell.Util.PARSED_LOCALE;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
import static jdk.jshell.Util.expunge;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
/**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
 * Tracks the compilation and load of a new or updated snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
 * @author Robert Field
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
final class Unit {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
    private final JShell state;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
    private final Snippet si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
    private final Snippet siOld;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
    private final boolean isDependency;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
    private final boolean isNew;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
    private final Snippet causalSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
    private final DiagList generatedDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
    private int seq;
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
    73
    private String classNameInitial;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
    private Wrap activeGuts;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
    private Status status;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
    private Status prevStatus;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
    private boolean signatureChanged;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
    private DiagList compilationDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
    private DiagList recompilationDiagnostics = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
    private List<String> unresolved;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
    private SnippetEvent replaceOldEvent;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
    private List<SnippetEvent> secondaryEvents;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
    private boolean isAttemptingCorral;
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    84
    private List<ClassInfo> toRedefine;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
    private boolean dependenciesNeeded;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
    Unit(JShell state, Snippet si, Snippet causalSnippet,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
            DiagList generatedDiagnostics) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        this.state = state;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
        this.si = si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
        this.isDependency = causalSnippet != null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
        this.siOld = isDependency
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                ? si
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
                : state.maps.getSnippet(si.key());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        this.isNew = siOld == null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
        this.causalSnippet = causalSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
        this.generatedDiagnostics = generatedDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
        this.seq = isNew? 0 : siOld.sequenceNumber();
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   100
        this.classNameInitial = isNew? "<none>" : siOld.className();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        this.prevStatus = (isNew || isDependency)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
                ? si.status()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
                : siOld.status();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
        si.setSequenceNumber(seq);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
    // Drop entry
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
    Unit(JShell state, Snippet si) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        this.state = state;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
        this.si = si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        this.siOld = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
        this.isDependency = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        this.isNew = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
        this.causalSnippet = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
        this.generatedDiagnostics = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
        this.prevStatus = si.status();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
        si.setDropped();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
        this.status = si.status();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
    public int hashCode() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        return si.hashCode();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
    public boolean equals(Object o) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
        return (o instanceof Unit)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
                ? si.equals(((Unit) o).si)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
                : false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
    Snippet snippet() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
        return si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
    boolean isDependency() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
        return isDependency;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   141
    void initialize() {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
        isAttemptingCorral = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
        dependenciesNeeded = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
        toRedefine = null; // assure NPE if classToLoad not called
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
        activeGuts = si.guts();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
        markOldDeclarationOverwritten();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   149
    // Set the outer wrap of our Snippet
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   150
    void setWrap(Collection<Unit> exceptUnit, Collection<Unit> plusUnfiltered) {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   151
        if (isImport()) {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   152
            si.setOuterWrap(state.outerMap.wrapImport(activeGuts, si));
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   153
        } else {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   154
            // Collect Units for be wrapped together.  Just this except for overloaded methods
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   155
            List<Unit> units;
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   156
            if (snippet().kind() == Kind.METHOD) {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   157
                String name = ((MethodSnippet) snippet()).name();
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   158
                units = plusUnfiltered.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   159
                        .filter(u -> u.snippet().kind() == Kind.METHOD &&
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   160
                                 ((MethodSnippet) u.snippet()).name().equals(name))
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   161
                        .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   162
            } else {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   163
                units = Collections.singletonList(this);
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   164
            }
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   165
            // Keys to exclude from imports
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   166
            Set<Key> except = exceptUnit.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   167
                    .map(u -> u.snippet().key())
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   168
                    .collect(toSet());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   169
            // Snippets to add to imports
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   170
            Collection<Snippet> plus = plusUnfiltered.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   171
                    .filter(u -> !units.contains(u))
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   172
                    .map(Unit::snippet)
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   173
                    .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   174
            // Snippets to wrap in an outer
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   175
            List<Snippet> snippets = units.stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   176
                    .map(Unit::snippet)
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   177
                    .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   178
            // Snippet wraps to wrap in an outer
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   179
            List<Wrap> wraps = units.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   180
                    .map(u -> u.activeGuts)
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   181
                    .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   182
            // Set the outer wrap for this snippet
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   183
            si.setOuterWrap(state.outerMap.wrapInClass(except, plus, snippets, wraps));
43134
006808ae5f6e 8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents: 42827
diff changeset
   184
            state.debug(DBG_WRAP, "++setWrap() %s\n%s\n",
006808ae5f6e 8171981: JShell: Fails compilation: new Object().getClass().getSuperclass()
rfield
parents: 42827
diff changeset
   185
                    si, si.outerWrap().wrapped());
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   186
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
    void setDiagnostics(AnalyzeTask ct) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
        setDiagnostics(ct.getDiagnostics().ofUnit(this));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
    void setDiagnostics(DiagList diags) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
        compilationDiagnostics = diags;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
        UnresolvedExtractor ue = new UnresolvedExtractor(diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
        unresolved = ue.unresolved();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
        state.debug(DBG_GEN, "++setCompilationInfo() %s\n%s\n-- diags: %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
                si, si.outerWrap().wrapped(), diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
    private boolean isRecoverable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        // Unit failed, use corralling if it is defined on this Snippet,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
        // and either all the errors are resolution errors or this is a
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
        // redeclare of an existing method
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
        return compilationDiagnostics.hasErrors()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
                && si instanceof DeclarationSnippet
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
                && (isDependency()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
                    || (si.subKind() != SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
                        && compilationDiagnostics.hasResolutionErrorsAndNoOthers()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
     * If it meets the conditions for corralling, install the corralled wrap
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
     * @return true is the corralled wrap was installed
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
    boolean corralIfNeeded(Collection<Unit> working) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
        if (isRecoverable()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
                && si.corralled() != null) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
            activeGuts = si.corralled();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
            setWrap(working, working);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
            return isAttemptingCorral = true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   223
        return isAttemptingCorral = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
    void setCorralledDiagnostics(AnalyzeTask cct) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
        // set corralled diagnostics, but don't reset unresolved
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
        recompilationDiagnostics = cct.getDiagnostics().ofUnit(this);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
        state.debug(DBG_GEN, "++recomp %s\n%s\n-- diags: %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
                si, si.outerWrap().wrapped(), recompilationDiagnostics);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
    boolean smashingErrorDiagnostics(CompileTask ct) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
        if (isDefined()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
            // set corralled diagnostics, but don't reset unresolved
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
            DiagList dl = ct.getDiagnostics().ofUnit(this);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
            if (dl.hasErrors()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
                setDiagnostics(dl);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
                status = RECOVERABLE_NOT_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
                // overwrite orginal bytes
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
                state.debug(DBG_GEN, "++smashingErrorDiagnostics %s\n%s\n-- diags: %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
                        si, si.outerWrap().wrapped(), dl);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
                return true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   246
        return false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   249
    void setStatus(AnalyzeTask at) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
        if (!compilationDiagnostics.hasErrors()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
            status = VALID;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
        } else if (isRecoverable()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
            if (isAttemptingCorral && !recompilationDiagnostics.hasErrors()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
                status = RECOVERABLE_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   255
            } else {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   256
                status = RECOVERABLE_NOT_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   257
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   258
        } else {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
            status = REJECTED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
        }
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   261
        checkForOverwrite(at);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   263
        state.debug(DBG_GEN, "setStatus() %s - status: %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   264
                si, status);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   265
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   267
    boolean isDefined() {
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   268
        return status.isDefined();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   269
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   272
     * Process the class information from the last compile. Requires loading of
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   273
     * returned list.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   274
     *
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
     * @return the list of classes to load
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   276
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   277
    Stream<ClassBytecodes> classesToLoad(List<String> classnames) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
        toRedefine = new ArrayList<>();
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   279
        List<ClassBytecodes> toLoad = new ArrayList<>();
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   280
        if (status.isDefined() && !isImport()) {
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents: 37751
diff changeset
   281
            // Classes should only be loaded/redefined if the compile left them
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents: 37751
diff changeset
   282
            // in a defined state.  Imports do not have code and are not loaded.
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents: 37751
diff changeset
   283
            for (String cn : classnames) {
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   284
                ClassInfo ci = state.classTracker.get(cn);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   285
                if (ci.isLoaded()) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   286
                    if (ci.isCurrent()) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   287
                        // nothing to do
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   288
                    } else {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   289
                        toRedefine.add(ci);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   290
                    }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   291
                } else {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   292
                    // If not loaded, add to the list of classes to load.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   293
                    toLoad.add(ci.toClassBytecodes());
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   294
                    dependenciesNeeded = true;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
                }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents: 37751
diff changeset
   296
            }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   298
        return toLoad.stream();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   302
     * Redefine classes needing redefine. classesToLoad() must be called first.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   303
     *
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   304
     * @return true if all redefines succeeded (can be vacuously true)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   305
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
    boolean doRedefines() {
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   307
        if (toRedefine.isEmpty()) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   308
            return true;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   309
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   310
        ClassBytecodes[] cbcs = toRedefine.stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   311
                .map(ClassInfo::toClassBytecodes)
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   312
                .toArray(ClassBytecodes[]::new);
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   313
        try {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   314
            state.executionControl().redefine(cbcs);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   315
            state.classTracker.markLoaded(cbcs);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   316
            return true;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   317
        } catch (ClassInstallException ex) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   318
            state.classTracker.markLoaded(cbcs, ex.installed());
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   319
            return false;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   320
        } catch (EngineTerminationException ex) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   321
            state.closeDown();
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   322
            return false;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   323
        } catch (NotImplementedException ex) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   324
            return false;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   325
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   326
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   327
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   328
    void markForReplacement() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
        // increment for replace class wrapper
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   330
        si.setSequenceNumber(++seq);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   331
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   332
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   333
    private boolean isImport() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   334
        return si.kind() == Kind.IMPORT;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   335
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   336
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   337
    private boolean sigChanged() {
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   338
        return (status.isDefined() != prevStatus.isDefined())
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   339
                || (status.isDefined() && !si.className().equals(classNameInitial))
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   340
                || signatureChanged;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   341
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   342
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   343
    Stream<Unit> effectedDependents() {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   344
        //System.err.printf("effectedDependents sigChanged=%b  dependenciesNeeded=%b   status=%s\n",
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   345
        //       sigChanged(), dependenciesNeeded, status);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   346
        return sigChanged() || dependenciesNeeded || status == RECOVERABLE_NOT_DEFINED
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   347
                ? dependents()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   348
                : Stream.empty();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   349
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   350
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   351
    Stream<Unit> dependents() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   352
        return state.maps.getDependents(si)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   353
                    .stream()
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   354
                    .filter(xsi -> xsi != si && xsi.status().isActive())
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   355
                    .map(xsi -> new Unit(state, xsi, si, new DiagList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   356
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
    void finish() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   359
        recordCompilation();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   360
        state.maps.installSnippet(si);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   361
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   363
    private void markOldDeclarationOverwritten() {
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   364
        if (si != siOld && siOld != null && siOld.status().isActive()) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   365
            // Mark the old declaraion as replaced
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   366
            replaceOldEvent = new SnippetEvent(siOld,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   367
                    siOld.status(), OVERWRITTEN,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   368
                    false, si, null, null);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   369
            siOld.setOverwritten();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   370
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   371
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   372
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   373
    private DiagList computeDiagnostics() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   374
        DiagList diagnostics = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   375
        DiagList diags = compilationDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   376
        if (status == RECOVERABLE_DEFINED || status == RECOVERABLE_NOT_DEFINED) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   377
            UnresolvedExtractor ue = new UnresolvedExtractor(diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   378
            diagnostics.addAll(ue.otherAll());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   379
        } else {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   380
            unresolved = Collections.emptyList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
            diagnostics.addAll(diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   382
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   383
        diagnostics.addAll(generatedDiagnostics);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   384
        return diagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   386
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   387
    private void recordCompilation() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
        state.maps.mapDependencies(si);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   389
        DiagList diags = computeDiagnostics();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   390
        si.setCompilationStatus(status, unresolved, diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
        state.debug(DBG_GEN, "recordCompilation: %s -- status %s, unresolved %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   392
                si, status, unresolved);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   393
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   395
    private void checkForOverwrite(AnalyzeTask at) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   396
        secondaryEvents = new ArrayList<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   397
        if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   398
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   399
        // Defined methods can overwrite methods of other (equivalent) snippets
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   400
        if (isNew && si.kind() == Kind.METHOD && status.isDefined()) {
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   401
            MethodSnippet msi = (MethodSnippet)si;
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   402
            String oqpt = msi.qualifiedParameterTypes();
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   403
            String nqpt = computeQualifiedParameterTypes(at, msi);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
            if (!nqpt.equals(oqpt)) {
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   405
                msi.setQualifiedParamaterTypes(nqpt);
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   406
                Status overwrittenStatus = overwriteMatchingMethod(msi);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   407
                if (overwrittenStatus != null) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   408
                    prevStatus = overwrittenStatus;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   409
                    signatureChanged = true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   410
                }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   411
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   412
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   413
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   414
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   415
    // Check if there is a method whose user-declared parameter types are
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   416
    // different (and thus has a different snippet) but whose compiled parameter
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   417
    // types are the same. if so, consider it an overwrite replacement.
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   418
    private Status overwriteMatchingMethod(MethodSnippet msi) {
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   419
        String qpt = msi.qualifiedParameterTypes();
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   420
        List<MethodSnippet> matching = state.methods()
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   421
                .filter(sn ->
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   422
                           sn != null
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   423
                        && sn != msi
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   424
                        && sn.status().isActive()
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   425
                        && sn.name().equals(msi.name())
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   426
                        && qpt.equals(sn.qualifiedParameterTypes()))
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   427
                .collect(toList());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   428
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   429
        // Look through all methods for a method of the same name, with the
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   430
        // same computed qualified parameter types
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   431
        Status overwrittenStatus = null;
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   432
        for (MethodSnippet sn : matching) {
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   433
            overwrittenStatus = sn.status();
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   434
            SnippetEvent se = new SnippetEvent(
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   435
                    sn, overwrittenStatus, OVERWRITTEN,
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   436
                    false, msi, null, null);
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   437
            sn.setOverwritten();
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   438
            secondaryEvents.add(se);
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   439
            state.debug(DBG_EVNT,
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   440
                    "Overwrite event #%d -- key: %s before: %s status: %s sig: %b cause: %s\n",
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   441
                    secondaryEvents.size(), se.snippet(), se.previousStatus(),
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   442
                    se.status(), se.isSignatureChange(), se.causeSnippet());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   443
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   444
        return overwrittenStatus;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   445
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   446
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   447
    private String computeQualifiedParameterTypes(AnalyzeTask at, MethodSnippet msi) {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   448
        String rawSig = TreeDissector.createBySnippet(at, msi).typeOfMethod(msi);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   449
        String signature = expunge(rawSig);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   450
        int paren = signature.lastIndexOf(')');
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   451
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   452
        // Extract the parameter type string from the method signature,
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   453
        // if method did not compile use the user-supplied parameter types
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   454
        return paren >= 0
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   455
                ? signature.substring(0, paren + 1)
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   456
                : msi.parameterTypes();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   457
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   458
37751
77e7bb904a13 8139837: JShell API: make a common JShellException
rfield
parents: 37644
diff changeset
   459
    SnippetEvent event(String value, JShellException exception) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   460
        boolean wasSignatureChanged = sigChanged();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   461
        state.debug(DBG_EVNT, "Snippet: %s id: %s before: %s status: %s sig: %b cause: %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   462
                si, si.id(), prevStatus, si.status(), wasSignatureChanged, causalSnippet);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   463
        return new SnippetEvent(si, prevStatus, si.status(),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   464
                wasSignatureChanged, causalSnippet, value, exception);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   465
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   466
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   467
    List<SnippetEvent> secondaryEvents() {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   468
        return secondaryEvents==null
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   469
                ? Collections.emptyList()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   470
                : secondaryEvents;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   471
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   472
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   473
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   474
    public String toString() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   475
        return "Unit(" + si.name() + ")";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   476
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   477
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   478
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   479
     * Separate out the unresolvedDependencies errors from both the other
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   480
     * corralling errors and the overall errors.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   481
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   482
    private static class UnresolvedExtractor {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   483
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   484
        private static final String RESOLVE_ERROR_SYMBOL = "symbol:";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   485
        private static final String RESOLVE_ERROR_LOCATION = "location:";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   486
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   487
        //TODO extract from tree instead -- note: internationalization
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   488
        private final Set<String> unresolved = new LinkedHashSet<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   489
        private final DiagList otherErrors = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   490
        private final DiagList otherAll = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   491
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   492
        UnresolvedExtractor(DiagList diags) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   493
            for (Diag diag : diags) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   494
                if (diag.isError()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   495
                    if (diag.isResolutionError()) {
35000
952a7b4652f0 8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents: 34857
diff changeset
   496
                        String m = diag.getMessage(PARSED_LOCALE);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   497
                        int symPos = m.indexOf(RESOLVE_ERROR_SYMBOL);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   498
                        if (symPos >= 0) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   499
                            m = m.substring(symPos + RESOLVE_ERROR_SYMBOL.length());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   500
                            int symLoc = m.indexOf(RESOLVE_ERROR_LOCATION);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   501
                            if (symLoc >= 0) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   502
                                m = m.substring(0, symLoc);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   503
                            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   504
                            m = m.trim();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
                            unresolved.add(m);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   506
                            continue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   507
                        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   508
                    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   509
                    otherErrors.add(diag);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   510
                }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   511
                otherAll.add(diag);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   512
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   513
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   514
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   515
        DiagList otherCorralledErrors() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   516
            return otherErrors;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   517
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   518
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   519
        DiagList otherAll() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   520
            return otherAll;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   521
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   522
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   523
        List<String> unresolved() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   524
            return new ArrayList<>(unresolved);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   525
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   526
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   527
}