langtools/src/jdk.jshell/share/classes/jdk/jshell/Unit.java
author mcimadamore
Fri, 16 Dec 2016 15:27:34 +0000
changeset 42827 36468b5fa7f4
parent 40304 0318f4e75c6d
child 43134 006808ae5f6e
permissions -rw-r--r--
8181370: Convert anonymous inner classes into lambdas/method references Reviewed-by: jjg, rfield, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
import static jdk.jshell.Snippet.Status.OVERWRITTEN;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
import static jdk.jshell.Snippet.Status.RECOVERABLE_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
import static jdk.jshell.Snippet.Status.RECOVERABLE_NOT_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
import static jdk.jshell.Snippet.Status.REJECTED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
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
    54
import static jdk.jshell.Util.PARSED_LOCALE;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
import static jdk.jshell.Util.expunge;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
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
 * 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
    59
 * @author Robert Field
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
final class Unit {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
    private final JShell state;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
    private final Snippet si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
    private final Snippet siOld;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
    private final boolean isDependency;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
    private final boolean isNew;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
    private final Snippet causalSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
    private final DiagList generatedDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
    private int seq;
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
    72
    private String classNameInitial;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
    private Wrap activeGuts;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
    private Status status;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
    private Status prevStatus;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
    private boolean signatureChanged;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
    private DiagList compilationDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
    private DiagList recompilationDiagnostics = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
    private List<String> unresolved;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
    private SnippetEvent replaceOldEvent;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
    private List<SnippetEvent> secondaryEvents;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
    private boolean isAttemptingCorral;
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
    83
    private List<ClassInfo> toRedefine;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
    private boolean dependenciesNeeded;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
    Unit(JShell state, Snippet si, Snippet causalSnippet,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
            DiagList generatedDiagnostics) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
        this.state = state;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        this.si = si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
        this.isDependency = causalSnippet != null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
        this.siOld = isDependency
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
                ? si
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                : state.maps.getSnippet(si.key());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
        this.isNew = siOld == null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        this.causalSnippet = causalSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
        this.generatedDiagnostics = generatedDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
        this.seq = isNew? 0 : siOld.sequenceNumber();
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
    99
        this.classNameInitial = isNew? "<none>" : siOld.className();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
        this.prevStatus = (isNew || isDependency)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
                ? si.status()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
                : siOld.status();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
        si.setSequenceNumber(seq);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
    }
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
    // Drop entry
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
    Unit(JShell state, Snippet si) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        this.state = state;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        this.si = si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
        this.siOld = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        this.isDependency = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
        this.isNew = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        this.causalSnippet = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
        this.generatedDiagnostics = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
        this.prevStatus = si.status();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
        si.setDropped();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
        this.status = si.status();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
    }
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
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
    public int hashCode() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
        return si.hashCode();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
    }
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
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
    public boolean equals(Object o) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
        return (o instanceof Unit)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
                ? si.equals(((Unit) o).si)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
                : false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
    }
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
    Snippet snippet() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
        return si;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
    }
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
    boolean isDependency() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
        return isDependency;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   140
    void initialize() {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
        isAttemptingCorral = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
        dependenciesNeeded = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
        toRedefine = null; // assure NPE if classToLoad not called
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
        activeGuts = si.guts();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
        markOldDeclarationOverwritten();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   148
    // Set the outer wrap of our Snippet
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   149
    void setWrap(Collection<Unit> exceptUnit, Collection<Unit> plusUnfiltered) {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   150
        if (isImport()) {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   151
            si.setOuterWrap(state.outerMap.wrapImport(activeGuts, si));
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   152
        } else {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   153
            // 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
   154
            List<Unit> units;
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   155
            if (snippet().kind() == Kind.METHOD) {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   156
                String name = ((MethodSnippet) snippet()).name();
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   157
                units = plusUnfiltered.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   158
                        .filter(u -> u.snippet().kind() == Kind.METHOD &&
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   159
                                 ((MethodSnippet) u.snippet()).name().equals(name))
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   160
                        .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   161
            } else {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   162
                units = Collections.singletonList(this);
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   163
            }
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   164
            // Keys to exclude from imports
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   165
            Set<Key> except = exceptUnit.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   166
                    .map(u -> u.snippet().key())
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   167
                    .collect(toSet());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   168
            // Snippets to add to imports
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   169
            Collection<Snippet> plus = plusUnfiltered.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   170
                    .filter(u -> !units.contains(u))
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   171
                    .map(Unit::snippet)
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   172
                    .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   173
            // Snippets to wrap in an outer
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   174
            List<Snippet> snippets = units.stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   175
                    .map(Unit::snippet)
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   176
                    .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   177
            // Snippet wraps to wrap in an outer
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   178
            List<Wrap> wraps = units.stream()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   179
                    .map(u -> u.activeGuts)
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   180
                    .collect(toList());
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   181
            // Set the outer wrap for this snippet
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   182
            si.setOuterWrap(state.outerMap.wrapInClass(except, plus, snippets, wraps));
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   183
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   186
    void setDiagnostics(AnalyzeTask ct) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
        setDiagnostics(ct.getDiagnostics().ofUnit(this));
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
    void setDiagnostics(DiagList diags) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
        compilationDiagnostics = diags;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
        UnresolvedExtractor ue = new UnresolvedExtractor(diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
        unresolved = ue.unresolved();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
        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
   195
                si, si.outerWrap().wrapped(), diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
    private boolean isRecoverable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
        // 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
   200
        // 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
   201
        // redeclare of an existing method
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        return compilationDiagnostics.hasErrors()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
                && si instanceof DeclarationSnippet
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
                && (isDependency()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
                    || (si.subKind() != SubKind.VAR_DECLARATION_WITH_INITIALIZER_SUBKIND
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
                        && compilationDiagnostics.hasResolutionErrorsAndNoOthers()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
     * 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
   211
     * @return true is the corralled wrap was installed
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
    boolean corralIfNeeded(Collection<Unit> working) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
        if (isRecoverable()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
                && si.corralled() != null) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
            activeGuts = si.corralled();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
            setWrap(working, working);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
            return isAttemptingCorral = true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
        return isAttemptingCorral = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
    }
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
    void setCorralledDiagnostics(AnalyzeTask cct) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
        // set corralled diagnostics, but don't reset unresolved
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
        recompilationDiagnostics = cct.getDiagnostics().ofUnit(this);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
        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
   227
                si, si.outerWrap().wrapped(), recompilationDiagnostics);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
    boolean smashingErrorDiagnostics(CompileTask ct) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
        if (isDefined()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
            // set corralled diagnostics, but don't reset unresolved
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
            DiagList dl = ct.getDiagnostics().ofUnit(this);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
            if (dl.hasErrors()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
                setDiagnostics(dl);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
                status = RECOVERABLE_NOT_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
                // overwrite orginal bytes
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
                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
   239
                        si, si.outerWrap().wrapped(), dl);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
                return true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
        return false;
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
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   246
    void setStatus(AnalyzeTask at) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
        if (!compilationDiagnostics.hasErrors()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
            status = VALID;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   249
        } else if (isRecoverable()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
            if (isAttemptingCorral && !recompilationDiagnostics.hasErrors()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
                status = RECOVERABLE_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
            } else {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
                status = RECOVERABLE_NOT_DEFINED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
            }
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 = REJECTED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   257
        }
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   258
        checkForOverwrite(at);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
        state.debug(DBG_GEN, "setStatus() %s - status: %s\n",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   261
                si, status);
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   264
    boolean isDefined() {
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   265
        return status.isDefined();
33362
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   268
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   269
     * 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
   270
     * returned list.
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   271
     *
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
     * @return the list of classes to load
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   273
     */
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   274
    Stream<ClassBytecodes> classesToLoad(List<String> classnames) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
        toRedefine = new ArrayList<>();
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   276
        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
   277
        if (status.isDefined() && !isImport()) {
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents: 37751
diff changeset
   278
            // 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
   279
            // 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
   280
            for (String cn : classnames) {
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   281
                ClassInfo ci = state.classTracker.get(cn);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   282
                if (ci.isLoaded()) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   283
                    if (ci.isCurrent()) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   284
                        // nothing to do
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   285
                    } else {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   286
                        toRedefine.add(ci);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   287
                    }
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
                    // 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
   290
                    toLoad.add(ci.toClassBytecodes());
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   291
                    dependenciesNeeded = true;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   292
                }
38535
4a25025e0b0d 8156101: JShell SPI: Provide a pluggable execution control SPI
rfield
parents: 37751
diff changeset
   293
            }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   294
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
        return toLoad.stream();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   296
    }
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
    /**
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   299
     * 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
   300
     *
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
     * @return true if all redefines succeeded (can be vacuously true)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
    boolean doRedefines() {
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   304
        if (toRedefine.isEmpty()) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   305
            return true;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   306
        }
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   307
        ClassBytecodes[] cbcs = toRedefine.stream()
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   308
                .map(ClassInfo::toClassBytecodes)
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 40304
diff changeset
   309
                .toArray(ClassBytecodes[]::new);
39807
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   310
        try {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   311
            state.executionControl().redefine(cbcs);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   312
            state.classTracker.markLoaded(cbcs);
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   313
            return true;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   314
        } catch (ClassInstallException ex) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   315
            state.classTracker.markLoaded(cbcs, ex.installed());
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   316
            return false;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   317
        } catch (EngineTerminationException ex) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   318
            state.closeDown();
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 (NotImplementedException ex) {
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   321
            return false;
ba0ff343d241 8160127: JShell API: extract abstract JDI and abstract streaming implementations of ExecutionControl
rfield
parents: 38908
diff changeset
   322
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   323
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   324
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   325
    void markForReplacement() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   326
        // increment for replace class wrapper
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   327
        si.setSequenceNumber(++seq);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   328
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   330
    private boolean isImport() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   331
        return si.kind() == Kind.IMPORT;
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   334
    private boolean sigChanged() {
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   335
        return (status.isDefined() != prevStatus.isDefined())
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   336
                || (status.isDefined() && !si.className().equals(classNameInitial))
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   337
                || signatureChanged;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   338
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   339
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   340
    Stream<Unit> effectedDependents() {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   341
        //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
   342
        //       sigChanged(), dependenciesNeeded, status);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   343
        return sigChanged() || dependenciesNeeded || status == RECOVERABLE_NOT_DEFINED
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   344
                ? dependents()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   345
                : Stream.empty();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   346
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   347
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   348
    Stream<Unit> dependents() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   349
        return state.maps.getDependents(si)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   350
                    .stream()
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   351
                    .filter(xsi -> xsi != si && xsi.status().isActive())
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   352
                    .map(xsi -> new Unit(state, xsi, si, new DiagList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   353
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   354
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   355
    void finish() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   356
        recordCompilation();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
        state.maps.installSnippet(si);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   359
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   360
    private void markOldDeclarationOverwritten() {
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 38535
diff changeset
   361
        if (si != siOld && siOld != null && siOld.status().isActive()) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   362
            // Mark the old declaraion as replaced
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   363
            replaceOldEvent = new SnippetEvent(siOld,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   364
                    siOld.status(), OVERWRITTEN,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   365
                    false, si, null, null);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   366
            siOld.setOverwritten();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   367
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   368
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   369
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   370
    private DiagList computeDiagnostics() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   371
        DiagList diagnostics = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   372
        DiagList diags = compilationDiagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   373
        if (status == RECOVERABLE_DEFINED || status == RECOVERABLE_NOT_DEFINED) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   374
            UnresolvedExtractor ue = new UnresolvedExtractor(diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   375
            diagnostics.addAll(ue.otherAll());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   376
        } else {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   377
            unresolved = Collections.emptyList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   378
            diagnostics.addAll(diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   379
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   380
        diagnostics.addAll(generatedDiagnostics);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
        return diagnostics;
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   384
    private void recordCompilation() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
        state.maps.mapDependencies(si);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   386
        DiagList diags = computeDiagnostics();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   387
        si.setCompilationStatus(status, unresolved, diags);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
        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
   389
                si, status, unresolved);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   390
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   392
    private void checkForOverwrite(AnalyzeTask at) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   393
        secondaryEvents = new ArrayList<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
        if (replaceOldEvent != null) secondaryEvents.add(replaceOldEvent);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   395
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   396
        // 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
   397
        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
   398
            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
   399
            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
   400
            String nqpt = computeQualifiedParameterTypes(at, msi);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   401
            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
   402
                msi.setQualifiedParamaterTypes(nqpt);
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   403
                Status overwrittenStatus = overwriteMatchingMethod(msi);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
                if (overwrittenStatus != null) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   405
                    prevStatus = overwrittenStatus;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   406
                    signatureChanged = true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   407
                }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   408
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   409
        }
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
    // 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
   413
    // 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
   414
    // 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
   415
    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
   416
        String qpt = msi.qualifiedParameterTypes();
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   417
        List<MethodSnippet> matching = state.methods()
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   418
                .filter(sn ->
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   419
                           sn != null
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   420
                        && sn != msi
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   421
                        && sn.status().isActive()
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   422
                        && sn.name().equals(msi.name())
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   423
                        && qpt.equals(sn.qualifiedParameterTypes()))
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   424
                .collect(toList());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   425
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   426
        // 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
   427
        // same computed qualified parameter types
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   428
        Status overwrittenStatus = null;
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   429
        for (MethodSnippet sn : matching) {
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   430
            overwrittenStatus = sn.status();
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   431
            SnippetEvent se = new SnippetEvent(
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   432
                    sn, overwrittenStatus, OVERWRITTEN,
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   433
                    false, msi, null, null);
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   434
            sn.setOverwritten();
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   435
            secondaryEvents.add(se);
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   436
            state.debug(DBG_EVNT,
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   437
                    "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
   438
                    secondaryEvents.size(), se.snippet(), se.previousStatus(),
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 39807
diff changeset
   439
                    se.status(), se.isSignatureChange(), se.causeSnippet());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   440
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   441
        return overwrittenStatus;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   442
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   443
34857
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   444
    private String computeQualifiedParameterTypes(AnalyzeTask at, MethodSnippet msi) {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   445
        String rawSig = TreeDissector.createBySnippet(at, msi).typeOfMethod(msi);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   446
        String signature = expunge(rawSig);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   447
        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
   448
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   449
        // 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
   450
        // 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
   451
        return paren >= 0
14d1224cfed3 8145239: JShell: throws AssertionError when replace classes with some methods which depends on these classes
rfield
parents: 33362
diff changeset
   452
                ? 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
   453
                : msi.parameterTypes();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   454
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   455
37751
77e7bb904a13 8139837: JShell API: make a common JShellException
rfield
parents: 37644
diff changeset
   456
    SnippetEvent event(String value, JShellException exception) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   457
        boolean wasSignatureChanged = sigChanged();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   458
        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
   459
                si, si.id(), prevStatus, si.status(), wasSignatureChanged, causalSnippet);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   460
        return new SnippetEvent(si, prevStatus, si.status(),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   461
                wasSignatureChanged, causalSnippet, value, exception);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   462
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   463
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   464
    List<SnippetEvent> secondaryEvents() {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   465
        return secondaryEvents==null
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   466
                ? Collections.emptyList()
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37005
diff changeset
   467
                : secondaryEvents;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   468
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   469
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   470
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   471
    public String toString() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   472
        return "Unit(" + si.name() + ")";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   473
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   474
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   475
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   476
     * Separate out the unresolvedDependencies errors from both the other
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   477
     * corralling errors and the overall errors.
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
    private static class UnresolvedExtractor {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   480
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   481
        private static final String RESOLVE_ERROR_SYMBOL = "symbol:";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   482
        private static final String RESOLVE_ERROR_LOCATION = "location:";
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
        //TODO extract from tree instead -- note: internationalization
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   485
        private final Set<String> unresolved = new LinkedHashSet<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   486
        private final DiagList otherErrors = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   487
        private final DiagList otherAll = new DiagList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   488
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   489
        UnresolvedExtractor(DiagList diags) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   490
            for (Diag diag : diags) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   491
                if (diag.isError()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   492
                    if (diag.isResolutionError()) {
35000
952a7b4652f0 8146368: JShell: couldn't smash the error when it's Japanese locale
rfield
parents: 34857
diff changeset
   493
                        String m = diag.getMessage(PARSED_LOCALE);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   494
                        int symPos = m.indexOf(RESOLVE_ERROR_SYMBOL);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   495
                        if (symPos >= 0) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   496
                            m = m.substring(symPos + RESOLVE_ERROR_SYMBOL.length());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   497
                            int symLoc = m.indexOf(RESOLVE_ERROR_LOCATION);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   498
                            if (symLoc >= 0) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   499
                                m = m.substring(0, symLoc);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   500
                            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   501
                            m = m.trim();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   502
                            unresolved.add(m);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   503
                            continue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   504
                        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
                    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   506
                    otherErrors.add(diag);
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
                otherAll.add(diag);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   509
            }
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   512
        DiagList otherCorralledErrors() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   513
            return otherErrors;
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   516
        DiagList otherAll() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   517
            return otherAll;
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   520
        List<String> unresolved() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   521
            return new ArrayList<>(unresolved);
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
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   524
}