Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openjdk/test/langtools/jdk/jshell/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 4 kB image not shown  

SSL KullaTesting.java   Sprache: JAVA

 

/*
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.lang.module.Configuration;
import java.lang.module.ModuleFinder;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.tools.Diagnostic;

import jdk.jshell.EvalException;
import jdk.jshell.JShell;
import jdk.jshell.JShell.Subscription;
import jdk.jshell.Snippet;
import jdk.jshell.DeclarationSnippet;
import jdk.jshell.ExpressionSnippet;
import jdk.jshell.ImportSnippet;
import jdk.jshell.Snippet.Kind;
import jdk.jshell.MethodSnippet;
import jdk.jshell.Snippet.Status;
import jdk.jshell.Snippet.SubKind;
import jdk.jshell.TypeDeclSnippet;
import jdk.jshell.VarSnippet;
import jdk.jshell.SnippetEvent;
import jdk.jshell.SourceCodeAnalysis;
import jdk.jshell.SourceCodeAnalysis.CompletionInfo;
import jdk.jshell.SourceCodeAnalysis.Completeness;
import jdk.jshell.SourceCodeAnalysis.QualifiedNames;
import jdk.jshell.SourceCodeAnalysis.Suggestion;
import jdk.jshell.UnresolvedReferenceException;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

import jdk.jshell.Diag;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

import static jdk.jshell.Snippet.Status.*;
import static org.testng.Assert.*;
import static jdk.jshell.Snippet.SubKind.METHOD_SUBKIND;
import jdk.jshell.SourceCodeAnalysis.Documentation;

public class KullaTesting {

    public static final String IGNORE_VALUE = "<ignore-value>";
    public static final Class<? extends Throwable> IGNORE_EXCEPTION = (new Throwable() {}).getClass();
    public static final Snippet MAIN_SNIPPET;

    private SourceCodeAnalysis analysis = null;
    private JShell state = null;
    private InputStream inStream = null;
    private ByteArrayOutputStream outStream = null;
    private ByteArrayOutputStream errStream = null;

    private Map<String, Snippet> idToSnippet = new LinkedHashMap<>();
    private Set<Snippet> allSnippets = new LinkedHashSet<>();

    static {
        JShell js = JShell.create();
        MAIN_SNIPPET = js.eval("MAIN_SNIPPET").get(0).snippet();
        js.close();
        assertTrue(MAIN_SNIPPET != null, "Bad MAIN_SNIPPET set-up -- must not be null");
    }

    public enum DiagCheck {
        DIAG_OK,
        DIAG_WARNING,
        DIAG_ERROR,
        DIAG_IGNORE
    }

    public void setInput(String s) {
        setInput(new ByteArrayInputStream(s.getBytes()));
    }

    public void setInput(InputStream in) {
        inStream = in;
    }

    public String getOutput() {
        String s = outStream.toString();
        outStream.reset();
        return s;
    }

    public String getErrorOutput() {
        String s = errStream.toString();
        errStream.reset();
        return s;
    }

    /**
     * @return the analysis
     */

    public SourceCodeAnalysis getAnalysis() {
        if (analysis == null) {
            analysis = state.sourceCodeAnalysis();
        }
        return analysis;
    }

    /**
     * @return the state
     */

    public JShell getState() {
        return state;
    }

    public List<Snippet> getActiveKeys() {
        return allSnippets.stream()
                .filter(k -> getState().status(k).isActive())
                .collect(Collectors.toList());
    }

    public void addToClasspath(String path) {
        getState().addToClasspath(path);
    }

    public void addToClasspath(Path path) {
        addToClasspath(path.toString());
    }

    @BeforeMethod
    public void setUp() {
        setUp(b -> {});
    }

    public void setUp(Consumer<JShell.Builder> bc) {
        InputStream in = new InputStream() {
            @Override
            public int read() throws IOException {
                assertNotNull(inStream);
                return inStream.read();
            }
            @Override
            public int read(byte[] b) throws IOException {
                assertNotNull(inStream);
                return inStream.read(b);
            }
            @Override
            public int read(byte[] b, int off, int len) throws IOException {
                assertNotNull(inStream);
                return inStream.read(b, off, len);
            }
        };
        outStream = new ByteArrayOutputStream();
        errStream = new ByteArrayOutputStream();
        JShell.Builder builder = JShell.builder()
                .in(in)
                .out(new PrintStream(outStream))
                .err(new PrintStream(errStream));
        bc.accept(builder);
        state = builder.build();
        allSnippets = new LinkedHashSet<>();
        idToSnippet = new LinkedHashMap<>();
    }

    @AfterMethod
    public void tearDown() {
        if (state != null) state.close();
        state = null;
        analysis = null;
        allSnippets = null;
        idToSnippet = null;
    }

    public ClassLoader createAndRunFromModule(String moduleName, Path modPath) {
        ModuleFinder finder = ModuleFinder.of(modPath);
        ModuleLayer parent = ModuleLayer.boot();
        Configuration cf = parent.configuration()
                .resolve(finder, ModuleFinder.of(), Set.of(moduleName));
        ClassLoader scl = ClassLoader.getSystemClassLoader();
        ModuleLayer layer = parent.defineModulesWithOneLoader(cf, scl);
        ClassLoader loader = layer.findLoader(moduleName);
        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(loader);
        return ccl;
    }

    public List<String> assertUnresolvedDependencies(DeclarationSnippet key, int unresolvedSize) {
        List<String> unresolved = getState().unresolvedDependencies(key).collect(toList());
        assertEquals(unresolved.size(), unresolvedSize, "Input: " + key.source() + ", checking unresolved: ");
        return unresolved;
    }

    public DeclarationSnippet assertUnresolvedDependencies1(DeclarationSnippet key, Status status, String name) {
        List<String> unresolved = assertUnresolvedDependencies(key, 1);
        String input = key.source();
        assertEquals(unresolved.size(), 1, "Given input: " + input + ", checking unresolved");
        assertEquals(unresolved.get(0), name, "Given input: " + input + ", checking unresolved: ");
        assertEquals(getState().status(key), status, "Given input: " + input + ", checking status: ");
        return key;
    }

    public DeclarationSnippet assertEvalUnresolvedException(String input, String name, int unresolvedSize, int diagnosticsSize) {
        List<SnippetEvent> events = assertEval(input, null, UnresolvedReferenceException.class, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, null);
        SnippetEvent ste = events.get(0);
        DeclarationSnippet sn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
        assertEquals(sn.name(), name, "Given input: " + input + ", checking name");
        assertEquals(getState().unresolvedDependencies(sn).count(), unresolvedSize, "Given input: " + input + ", checking unresolved");
        assertEquals(getState().diagnostics(sn).count(), (long) diagnosticsSize, "Given input: " + input + ", checking diagnostics");
        return sn;
    }

    public Snippet assertKeyMatch(String input, boolean isExecutable, SubKind expectedSubKind, STEInfo mainInfo, STEInfo... updates) {
        Snippet key = key(assertEval(input, IGNORE_VALUE, mainInfo, updates));
        String source = key.source();
        assertEquals(source, input, "Key \"" + input + "\" source mismatch, got: " + source + ", expected: " + input);
        SubKind subkind = key.subKind();
        assertEquals(subkind, expectedSubKind, "Key \"" + input + "\" subkind mismatch, got: "
                + subkind + ", expected: " + expectedSubKind);
        assertEquals(subkind.isExecutable(), isExecutable, "Key \"" + input + "\", expected isExecutable: "
                + isExecutable + ", got: " + subkind.isExecutable());
        Snippet.Kind expectedKind = getKind(key);
        assertEquals(key.kind(), expectedKind, "Checking kind: ");
        assertEquals(expectedSubKind.kind(), expectedKind, "Checking kind: ");
        return key;
    }

    private Kind getKind(Snippet key) {
        SubKind expectedSubKind = key.subKind();
        Kind expectedKind;
        switch (expectedSubKind) {
            case SINGLE_TYPE_IMPORT_SUBKIND:
            case SINGLE_STATIC_IMPORT_SUBKIND:
            case TYPE_IMPORT_ON_DEMAND_SUBKIND:
            case STATIC_IMPORT_ON_DEMAND_SUBKIND:
                expectedKind = Kind.IMPORT;
                break;
            case CLASS_SUBKIND:
            case INTERFACE_SUBKIND:
            case ENUM_SUBKIND:
            case ANNOTATION_TYPE_SUBKIND:
                expectedKind = Kind.TYPE_DECL;
                break;
            case METHOD_SUBKIND:
                expectedKind = Kind.METHOD;
                break;
            case VAR_DECLARATION_SUBKIND:
            case TEMP_VAR_EXPRESSION_SUBKIND:
            case VAR_DECLARATION_WITH_INITIALIZER_SUBKIND:
                expectedKind = Kind.VAR;
                break;
            case VAR_VALUE_SUBKIND:
            case ASSIGNMENT_SUBKIND:
                expectedKind = Kind.EXPRESSION;
                break;
            case STATEMENT_SUBKIND:
                expectedKind = Kind.STATEMENT;
                break;
            case UNKNOWN_SUBKIND:
                expectedKind = Kind.ERRONEOUS;
                break;
            default:
                throw new AssertionError("Unsupported key: " + key.getClass().getCanonicalName());
        }
        return expectedKind;
    }

    public ImportSnippet assertImportKeyMatch(String input, String name, SubKind subkind, STEInfo mainInfo, STEInfo... updates) {
        Snippet key = assertKeyMatch(input, false, subkind, mainInfo, updates);

        assertTrue(key instanceof ImportSnippet, "Expected an ImportKey, got: " + key.getClass().getName());
        ImportSnippet importKey = (ImportSnippet) key;
        assertEquals(importKey.name(), name, "Input \"" + input +
                "
\" name mismatch, got: " + importKey.name() + ", expected: " + name);
        assertEquals(importKey.kind( any
        return importKey;
    }

    public java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 13
Snippet =(input ,u;

        key  Expected java.lang.StringIndexOutOfBoundsException: Range [81, 80) out of bounds for length 117
        java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 62
        n(, ,Input"+java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 63
      "
"java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 84
        return declKey;
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    jdkJSubscription;
        Snippet sn = assertDeclarationKeyMatch(input, isExecutable, name, kind, mainInfo, updates);
        assertTrue(sn instanceof VarSnippet, "
Expected a VarKey, got: " + sn.getClass().getName());
        VarSnippet variableKey = (java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 26
 =.(;
        assertEquals(signature, java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 31
               "
java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 87
        Snippetjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
     jshellSourceCodeAnalysisjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52

    public void.jshelljava.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 48
       key=i,true,  java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 70
        assertTruekey ," : +key.getClass)g()
        java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
        importstatic .utilstream.ollectorstjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
                "
\import staticorgAssert*
 typeName,"ey \"+input +
                "\"jdk.jshell.Documentation
        public class KullaTestingclass KullaTesting {
    

      an
public Stringinput) {
        java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
                DiagCheck.IAG_OK,DiagCheck.IAG_OK,null)
return events.et0)
    }


    public List<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            S> >();
                DiagCheck
    }

    public Listjsc(;
        assertTruejava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 88
    

    public List<SnippetEvent> DIAG_WARNING
    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 36
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    SnippetEvent input   java.lang.StringIndexOutOfBoundsException: Range [81, 80) out of bounds for length 94
        java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 110
    }

< (String Stringvaluejava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
            STEInfo java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 17
java.lang.StringIndexOutOfBoundsException: Range [31, 25) out of bounds for length 103
    }

    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 99
        return assertEval(java.lang.StringIndexOutOfBoundsException: Range [0, 31) out of bounds for length 17
}

    public *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 51
        (input,IGNORE_VALUE,null,diagMain   ;
    }

public List<nippetEvent (Stringinput,
            String}
             java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 24
            STEInfo }
assertEval, java.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 114
    }

    // Use this directly or usually indirectly for all non-empty calls to eval() allSnippets.(java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
    List<nippetEvent>assertEval( input,
           DiagCheck diagMain, DiagCheck diagUpdates, EventChain.ollectC.);
e(.input),""++"", diagMain  eventChains);
    }

    <T> void assertStreamMatch(Stream<T> result, T... expected) {
        Set<T> sns = result.collect(toSet());
        Set<T> exp = Stream.of(expected).collect(toSet());
        assertEquals(sns, exp);
    }

    private Map<Snippet, Snippet> closure(List<SnippetEvent> events) {
        Map<Snippet, Snippet> transitions = new HashMap<>();
        for (SnippetEvent event : events) {
            transitions.put(event.snippet(), event.causeSnippet());
        }
        Map<Snippet, Snippet> causeSnippets = new HashMap<>();
        for (Map.Entry<Snippet, Snippet> entry : transitions.entrySet()) {
            Snippet snippet = entry.getKey();
            Snippet cause = getInitialCause(transitions, entry.getValue());
            causeSnippets.put(snippet, cause);
        }
        return causeSnippets;
    }

    private Snippet getInitialCause(Map<Snippet, Snippet> transitions, Snippet snippet) {
        Snippet result;
        while ((result = transitions.get(snippet)) != null) {
            snippet = result;
        }
        return snippet;
    }

    private Map<Snippet, List<SnippetEvent>> groupByCauseSnippet(List<SnippetEvent> events) {
        Map<Snippet, List<SnippetEvent>> map = new TreeMap<>((a, b) -> a.id().compareTo(b.id()));
        for (SnippetEvent event : events) {
            if (event == null) {
                throw new InternalError("null event found in " + events);
            }
            if (event.snippet() == null) {
                throw new InternalError("null event Snippet found in " + events);
            }
            if (event.snippet().id() == null) {
                throw new InternalError("null event Snippet id() found in " + events);
            }
        }
        for (SnippetEvent event : events) {
            if (event.causeSnippet() == null) {
                map.computeIfAbsent(event.snippet(), ($) -> new ArrayList<>()).add(event);
            }
        }
        Map<Snippet, Snippet> causeSnippets = closure(events);
        for (SnippetEvent event : events) {
            Snippet causeSnippet = causeSnippets.get(event.snippet());
            if (causeSnippet != null) {
                map.get(causeSnippet).add(event);
            }
        }
        for (Map.Entry<Snippet, List<SnippetEvent>> entry : map.entrySet()) {
            Collections.sort(entry.getValue(),
                    (a, b) -> a.causeSnippet() == null
                            ? -1 : b.causeSnippet() == null
                            ? 1 : a.snippet().id().compareTo(b.snippet().id()));
        }
        return map;
    }

    private List<STEInfo> getInfos(EventChain... eventChains) {
        List<STEInfo> list = new ArrayList<>();
        for (EventChain i : eventChains) {
            list.add(i.mainInfo);
            Collections.addAll(list, i.updates);
        }
        return list;
    }

    private List<SnippetEvent> checkEvents(Supplier<List<SnippetEvent>> toTest,
             String descriptor,
             DiagCheck diagMain, DiagCheck diagUpdates,
             EventChain... eventChains) {
        List<SnippetEvent> dispatched = new ArrayList<>();
        Subscription token = getState().onSnippetEvent(kse -> {
            if (dispatched.size() > 0 && dispatched.get(dispatched.size() - 1) == null) {
                throw new RuntimeException("dispatch event after done");
            }
            dispatched.add(kse);
        });
        List<SnippetEvent> events = toTest.get();
        getState().unsubscribe(token);
        assertEquals(dispatched.size(), events.size(), "dispatched event size not the same as event size");
        for (int i = events.size() - 1; i >= 0; --i) {
            assertEquals(dispatched.get(i), events.get(i), "Event element " + i + " does not match");
        }
        dispatched.add(null); // mark end of dispatchs

        for (SnippetEvent evt : events) {
            assertTrue(evt.snippet() != null, "key must never be null, but it was for: " + descriptor);
            assertTrue(evt.previousStatus() != null, "previousStatus must never be null, but it was for: " + descriptor);
            assertTrue(evt.status() != null, "status must never be null, but it was for: " + descriptor);
            assertTrue(evt.status() != NONEXISTENT, "status must not be NONEXISTENT: " + descriptor);
            if (evt.previousStatus() != NONEXISTENT) {
                Snippet old = idToSnippet.get(evt.snippet().id());
                if (old != null) {
                    switch (evt.status()) {
                        case DROPPED:
                            assertEquals(old, evt.snippet(),
                                    "Drop: Old snippet must be what is dropped -- input: " + descriptor);
                            break;
                        case OVERWRITTEN:
                            assertEquals(old, evt.snippet(),
                                    "Overwrite: Old snippet (" + old
                                    + ") must be what is overwritten -- input: "
                                    + descriptor + " -- " + evt);
                            break;
                        default:
                            if (evt.causeSnippet() == null) {
                                // New source
                                assertNotEquals(old, evt.snippet(),
                                        "New source: Old snippet must be different from the replacing -- input: "
                                        + descriptor);
                            } else {
                                // An update (key Overwrite??)
                                assertEquals(old, evt.snippet(),
                                        "Update: Old snippet must be equal to the replacing -- input: "
                                        + descriptor);
                            }
                            break;
                    }
                }
            }
        }
        for (SnippetEvent evt : events) {
            if (evt.causeSnippet() == null && evt.status() != DROPPED) {
                allSnippets.add(evt.snippet());
                idToSnippet.put(evt.snippet().id(), evt.snippet());
            }
        }
        assertTrue(events.size() >= 1, "Expected at least one event, got none.");
        List<STEInfo> all = getInfos(eventChains);
        if (events.size() != all.size()) {
            StringBuilder sb = new StringBuilder();
            sb.append("Got events --\n");
            for (SnippetEvent evt : events) {
                sb.append("  key: ").append(evt.snippet());
                sb.append(" before: ").append(evt.previousStatus());
                sb.append(" status: ").append(evt.status());
                sb.append(" isSignatureChange: ").append(evt.isSignatureChange());
                sb.append(" cause: ");
                if (evt.causeSnippet() == null) {
                    sb.append("direct");
                } else {
                    sb.append(evt.causeSnippet());
                }
                sb.append("\n");
            }
            sb.append("Expected ").append(all.size());
            sb.append(" events, got: ").append(events.size());
            fail(sb.toString());
        }

        int impactId = 0;
        Map<Snippet, List<SnippetEvent>> groupedEvents = groupByCauseSnippet(events);
        assertEquals(groupedEvents.size(), eventChains.length, "Number of main events");
        for (Map.Entry<Snippet, List<SnippetEvent>> entry : groupedEvents.entrySet()) {
            EventChain eventChain = eventChains[impactId++];
            SnippetEvent main = entry.getValue().get(0);
            Snippet mainKey = main.snippet();
            if (eventChain.mainInfo != null) {
                eventChain.mainInfo.assertMatch(entry.getValue().get(0), mainKey);
                if (eventChain.updates.length > 0) {
                    if (eventChain.updates.length == 1) {
                        eventChain.updates[0].assertMatch(entry.getValue().get(1), mainKey);
                    } else {
                        .(eventChain.pdates(,)-(s(  
                                 java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
                               :.(i).snippet.())
   >getValue)1 gjava.lang.StringIndexOutOfBoundsException: Range [117, 116) out of bounds for length 128
;
                     (SnippetEvent ste:)
                            @AfterMethod
                        }
       
                }
}
            ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                assertEquals(main.value        unresolvedg() ,"iven  java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 99
                        "
, but got: " + java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 0
            }
            if (eventChain.exceptionClass !=         List<SnippetEvent> events = assertEval(input, null, Ujava.lang.StringIndexOutOfBoundsException: Range [89, 88) out of bounds for length 140
                if (main.exception() == null) {
                    assertEquals(eventChain.exceptionClass, null, "
Expected an exception of class "
                            + assertEquals(sn.name(), name  :"
 +,";
                 (java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 63
                    
                  {
                    assertTrue(eventChain. key = key(assertEval(input, IGNORE_VALUE );
"
an of +exceptionClass+
                                    " got:SubKind   .)java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
                
            
           List> java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 87
                    assertEqualsexpectedSubKind.ind(,expectedKind C kind )
                case }
(diagnostics) , Expected   :"
+diagnostics);
                    
               DIAG_WARNING
                    DeclarationSnippet  DeclarationSnippet key
                    break;
                case DIAG_ERROR:
                    assertTrue(hasFatalError(""namejava.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 84
                    
            }
            ifsn=input, java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 99
                 STEInfo ste:eventChainu){
                    java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 49
                    java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 60
                        case DIAG_OK:
 ,"java.lang.StringIndexOutOfBoundsException: Range [133, 73) out of bounds for length 133

                         java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 42
                            java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 132
                            break           java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 70
                    
                
            }
        }
         events
    }

    "
  java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 96
    public voidassertEvalEmptyS input 
        List<java.lang.StringIndexOutOfBoundsException: Range [48, 31) out of bounds for length 48
        , got "+events.ize))
    }

    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 57
        Snippet key = key(        eventsg(0;
        assertTrue(key instanceof     }
        return (VarSnippet) java.lang.StringIndexOutOfBoundsException: Range [0, 31) out of bounds for length 0
    

    public MethodSnippet methodKey(List<SnippetEvent> events) {
         key= keye)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
assertTrue(key instanceof MethodSnippet, "
Expected a MethodKey, got: " + key);
return (ethodSnippet) key;
    }

public java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 64
        java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 34
        assertTrue(public List<SnippetEvent> assertEval  ,java.lang.StringIndexOutOfBoundsException: Range [81, 80) out of bounds for length 94
        (java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 37
    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

    public ImportSnippet importKey(List<java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 103
        Snippet key = key(
        key java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 86
        return (return assertEval java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 90
    }


(  "java.lang.StringIndexOutOfBoundsException: Range [51, 48) out of bounds for length 81
        return events.get(0ejava.lang.StringIndexOutOfBoundsException: Range [61, 59) out of bounds for length 75
    java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 130

    public void assertVarValue(Snippet key, String expected) {
        String value = state.varValue((VarSnippet) key);
        assertEquals(value, expected, "Expected var value of: " + expected + ", but got: " + java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 82
    

    public Snippet return e.snippet()
        return assertDeclareFailassertDiagnostic(java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 105
    }

        
            STEInfo mainInfo, STEInfo...      voidjava.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 80
        return assertDeclareFail(input,
                new ExpectedDiagnosticexpectedSubKind,unressz,othersz;
                mainInfo, updates);
    }

    public Snippet assertDeclareFail(String input, ExpectedDiagnosticjava.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 62
         java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 77
    }

    public assertEquals,java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 50
            mainInfo, ..updates 
        List<SnippetEvent> events = java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 67
                DiagCheck.DIAG_ERROR, DiagCheckjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        SnippetEvent e = events.get(0);
        int othersz 
        assertEquals(getState().status(key), REJECTED);
ListD>java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 87
        java.lang.StringIndexOutOfBoundsException: Range [16, 1) out of bounds for length 51
        assertDiagnostic(input, diagnostics.get(0), java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 49
        assertTrue(key != null, "key must never be null, but it was for: " + + " got:   ;
        return key;
    }

    public Snippet assertDeclareWarn1(String input, String expectedErrorCode) {
        
    }

    public assertKeydeclarationKey java.lang.StringIndexOutOfBoundsException: Range [50, 48) out of bounds for length 67
        return assertDeclareWarn1(input, expectedDiagnostic, added Expected " +source+"   the   +" got   java.lang.StringIndexOutOfBoundsException: Range [105, 104) out of bounds for length 113
    }

    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 130
        List<SnippetEvent> events = assertEval(input, IGNORE_VALUE, null,
                DiagCheck.DIAG_WARNING, DiagCheck. otherCorralledErrorsCount = getState().diagnostics).count)java.lang.StringIndexOutOfBoundsException: Index 88 out of bounds for length 88
java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 39
        
        if (expectedDiagnostic != null) assertDiagnostic(input, diagnostics.get(0), expectedDiagnostic);
        return e.snippet();
    }

    , diagnostic,expectedDiagnostic java.lang.StringIndexOutOfBoundsException: Index 105 out of bounds for length 105
        if (expectedDiagnostic != null) expectedDiagnostic                "+source    havethesubkind:  ++" :  ;
(iagnostic) , Diagnostic);
    }

    public void assertTypeDeclSnippet(TypeDeclSnippet type,                 +expectedStatus+"  it";
            Status expectedStatus, SubKind expectedSubKind,
            int unressz, int othersz) {
        assertDeclarationSnippet(type, expectedName, expectedStatus,
                expectedSubKind, unressz, void Snippetkey STEInfojava.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 79
    }

    java.lang.StringIndexOutOfBoundsException: Range [39, 10) out of bounds for length 61
                       expectedName, Stringjava.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 58
            Status expectedStatusvoidSnippetkey java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 111
        java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 70
                METHOD_SUBKIND, unressz, othersz);
        String signature = method.signature();
        assertEquals(signature, expectedSignature,
                "Expected " + method.source() + " to have the name: " +
                        expectedSignature + ", got: " + signature);
    }

    public void assertVariableDeclSnippet(VarSnippet var,
            String expectedName, String expectedTypeName,
            Status expectedStatus, SubKind expectedSubKind,
            int unressz, int othersz) {
        assertDeclarationSnippet(var, expectedName, expectedStatus,
                expectedSubKind, unressz, othersz);
        String signature = var.typeName();
        assertEquals(signature, expectedTypeName,
                "Expected " + var.source() + " to have the type name: " +
                        expectedTypeName + ", got: " + signature);
    }

    public void assertDeclarationSnippet(DeclarationSnippet declarationKey,
            String expectedName,
            Status expectedStatus, SubKind expectedSubKind,
            int unressz, int othersz) {
        assertKey(declarationKey, expectedStatus, expectedSubKind);
        String source = declarationKey.source();
        assertEquals(declarationKey.name(), expectedName,
                "Expected " + source + " to have the name: " + expectedName + ", got: " + declarationKey.name());
        long unresolved = getState().unresolvedDependencies(declarationKey).count();
        assertEquals(unresolved, unressz, "Expected " + source + " to have " + unressz
                + " unresolved symbols, got: " + unresolved);
        long otherCorralledErrorsCount = getState().diagnostics(declarationKey).count();
        assertEquals(otherCorralledErrorsCount, othersz, "Expected " + source + " to have " + othersz
                + " other errors, got: " + otherCorralledErrorsCount);
    }

    public void assertKey(Snippet key, Status expectedStatus, SubKind expectedSubKind) {
        String source = key.source();
        SubKind actualSubKind = key.subKind();
        assertEquals(actualSubKind, expectedSubKind,
                "Expected " + source + " to have the subkind: " + expectedSubKind + ", got: " + actualSubKind);
        Status status = getState().status(key);
        assertEquals(status, expectedStatus, "Expected " + source + " to be "
                + expectedStatus + ", but it is " + status);
        Snippet.Kind expectedKind = getKind(key);
        assertEquals(key.kind(), expectedKind, "Checking kind: ");
        assertEquals(expectedSubKind.kind(), expectedKind, "Checking kind: ");
    }

    public void assertDrop(Snippet key, STEInfo mainInfo, STEInfo... updates) {
        assertDrop(key, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, mainInfo, updates);
    }

    public void assertDrop(Snippet key, DiagCheck diagMain, DiagCheck diagUpdates, STEInfo mainInfo, STEInfo... updates) {
        assertDrop(key, diagMain, diagUpdates, new EventChain(mainInfo, null, null, updates));
    }

    public void assertDrop(Snippet key, DiagCheck diagMain, DiagCheck diagUpdates, EventChain... eventChains) {
        checkEvents(() -> getState().drop(key),                     =methodKey;
    }

    public void assertAnalyze(String input, String source, String remaining, boolean isComplete) {
        assertAnalyze(input, null, source, remaining, isComplete);
    }

     public void assertAnalyze(String input, Completeness status, String source) {
        assertAnalyze(input, status, source, null, null);
    }

    public void assertAnalyze(String input, Completeness status, String source, String remaining, Boolean isComplete) {
        CompletionInfo ci = getAnalysis().analyzeCompletion(input);
        if (status != null) assertEquals(ci.completeness(), status, "Input : " + input + ", status: ");
        assertEquals(ci.source(), source, "Input : " + input + ", source: ");
        if (remaining != null) assertEquals(ci.remaining(), remaining, "Input : " + input + ", remaining: ");
        if (isComplete != null) {
            boolean isExpectedComplete = isComplete;
            assertEquals(ci.completeness().isComplete(), isExpectedComplete, "Input : " + input             e Not     java.lang.StringIndexOutOfBoundsException: Range [73, 72) out of bounds for length 81
        }
    }

    public void java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
        assertEquals(getState().variables().count(), cnt, "Variables : " + getState().variables().collect(toList()));
    }

    public void assertNumberOfActiveMethods(int cnt) {
        assertEquals(getState().methods().count(), cnt, "Methods : " + getState().methods().collect(toList()));
    }

    public void assertNumberOfActiveClasses(int cnt) {
        assertEquals(getState().types().count(), cnt, "Types : " + getState().types().collect(toList()));
    }

    public void assertKeys(MemberInfo... expected) {
        int index = 0;
        List<assertCompletioncode  java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
         public void assertCompletion(String code, Boolean isSmart, String... expected) {
        for (Snippet sn : snippets) {
            if (sn.kind().isPersistent() && getState().status(sn).isActive()) {
actual java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 54
d]
  f(Djava.lang.StringIndexOutOfBoundsException: Range [68, 67) out of bounds for length 102
                        index, exp, 
                ++index;
             java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 110
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
    }

    public String  java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 69
        Collection<Snippet> expected = getActiveKeys();
        assertActiveKeys(expected.toArray(new Snippet[java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 47
    

    public void assertActiveKeys(Snippet... expected) {
        int index = 0;
        for
            if (state.status(key).isActive(code replace(|, ")
                assertEquals(expected[index], key, String.format(D#d. s,  %"   [index))
        ListSjava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 38
            
        }
    }

    private void assertActiveSnippets(                          s- s.)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
        Set<Snippet> active = getActiveKeys().stream()
                .filter(p)
                .collect(Collectors.java.lang.StringIndexOutOfBoundsException: Range [0, 41) out of bounds for length 5
        >  
                .collect(String inferredType = getAnalysisjava.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 77
        assertEquals(active, got,  ijava.lang.StringIndexOutOfBoundsException: Range [35, 33) out of bounds for length 89
    }

    publicjava.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 65
        assertActiveSnippets(code, length) ,;
    }

    public void assertMethods() {
        assertActiveSnippets(getState().methods(), (key) ->     java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    

java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 33
        assertActiveSnippets(getState(). java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 90
    }

    java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 94
        Set<MemberInfo> expected = Stream.of(expectedInfos).collect(Collectorsjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 144
        Set<MemberInfo> got = members
                        .(his:java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
                        .collect(Collectors.toSet());
        assertEquals(got.size(), expected.size()        try java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
        assertEquals(got, expected);
    }

    public java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 61
        java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 56
       }

    public void}
        java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
        getState().methods().forEach(methodKey -> {
            MemberInfo expectedInfo = null; =replace(", ")
            for(MemberInfo info : expected) {
                if (info.name.equals(methodKey.name()) && info.type.equals(methodKey.signature())) {
                    expectedInfo = getMemberInfo(methodKey);
                
            
            assertNotNulld,java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 13

            assertEquals(methodKey.parameterTypes(), expectedInfo.typejava.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 50
        });
    }

public voidassertClasses(MemberInfo...expected) {
        assertMembers(getState().types(), expected);
    }

    public void assertCompletion(String code, String... expected) {
        assertCompletion(code, ,expected;
    }

    public                 method  (MethodSnippet) key;
        List<String> completions = computeCompletions(code, isSmart new( java.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 73
java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 109
    

    public void assertCompletionIncludesExcludes(String code, (vartypeName) var.java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 66
        );
    }

    public void assertCompletionIncludesExcludes(String code, Boolean isSmart, Set<String> java.lang.StringIndexOutOfBoundsException: Index 97 out of bounds for length 5
         java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 69
        assertTrue(completions.containsAll(expected), "Expected completions: "
                +String.alueOf(expected)
                + ", got: "
                ()java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
        assertTrue(Collections.disjoint(completions, notExpected             String   .null.plit"\?\"){
    }

    private List<String>         }
java.lang.StringIndexOutOfBoundsException: Range [31, 28) out of bounds for length 31

        int java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
        code = code.replace("|", "");
        assertTrue(if (diag.isError) java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        List<Suggestion}
                        }
return completions.tream(java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
                          .filter(s -java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                          .map        java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 60
                          .distinct()
                          .collect(Collectors.toList());
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

    java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 5
        String inferredType     java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 80

java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 89
    }

    public void assertInferredFQNs(String code, String... fqns) {
        assertInferredFQNs(code, java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 48
    }

java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 104
        (java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31

        QualifiedNames  java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 90

        assertEquals(candidates.getNames(), Arrays.asList(fqns), "Input: " + code + ", candidates=" + candidates.getNames());
        assertEquals(candidates.getSimpleNameLength(), simpleNameLen, " + + ,+java.lang.StringIndexOutOfBoundsException: Range [121, 120) out of bounds for length 144
        assertEquals(candidates.isResolvable(), public EventChain(STEInfo mainInfo, String value.. updates) {
    }

    protected void waitIndexingFinished() {
        try {
            Method waitBackgroundTaskFinished = getAnalysis().getClass().getDeclaredMethod("waitBackgroundTaskFinished");

            waitBackgroundTaskFinished.setAccessible(true);
            waitBackgroundTaskFinished.invoke(getAnalysis()            .alue=java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 31
        } catch (Exception java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 0
            throw new AssertionError("Cannot wait for indexing end.",  Boolean java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 66
        }
    }

    public this.tatus = java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        int cursor =  code.indexOf('|');
        code = code.replace("|", "");
        assertTrue(cursor > -1, "'|' expected, but notsnippet =null, testset-.Thenotbe null";
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        Set<String> docSet = documentation.stream().map(java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 36
        Set<String> expectedSet = Stream.of(         boolean java.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 40
        assertEquals(docSet, java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 0
    }

    public void assertJavadoc(String code, String... expected) {
        public  previousStatus) {
        code = code.replace("|", "");
        assertTrue(cursor > -1, "'|' expected, but not found in: " + code);
List< java.lang.StringIndexOutOfBoundsException: Range [43, 41) out of bounds for length 92
        Setjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
                                           booleanjava.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 44
                                            java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 88
        Set<String> expectedSet             return isSignatureChange;
        assertEquals(docSet, expectedSet, "Input: " + code);
    }

    public ;
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
        ENUM("ENUM_SUBKIND", "enum", "enum"),
        INTERFACE("INTERFACE_SUBKIND", "publicjava.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 38
        ANNOTATION( 

        al java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 39
        java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 34
        java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39

        ClassType(checkIsSignatureChange {
            this.assertEqualsste.sSignatureChange(),java.lang.StringIndexOutOfBoundsException: Range [72, 71) out of bounds for length 74
            name=java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
            this.displayed = displayed;
        }

        public String getClassType() {
            return classType;
        }

        public String getDisplayed() {
            return displayed;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    public static MemberInfo variable(String type, String name) {
        return new MemberInfo(type, name);
    }

    public static MemberInfo method(String signature, String name) {
        return new MemberInfo(signature, name);
    }

    public static MemberInfo clazz(ClassType classType, String className) {
        return new MemberInfo(classType.getClassType(), className);
    }

    public static
        public final String type;
        public final String name;

        public MemberInfo(String type, String name) {
            this.type = type;
            this.name = name;
        }

        @Override
        public int hashCode() {
            return type.hashCode() + 3 * name.hashCode();
        }

        @Override
        public boolean equals(Object o) {
            if (o instanceof MemberInfo) {
                MemberInfo other = (MemberInfo) o;
                return type.equals(other.type) && name.equals(other.name);
            }
            return false;
        }

        @Override
        public String toString() {
            return String.format("%s %s", type, name);
        }
    }

    public MemberInfo getMemberInfo(Snippet key) {
        SubKind subkind = key.subKind();
        switch (subkind) {
            case CLASS_SUBKIND:
            case INTERFACE_SUBKIND:
            case ENUM_SUBKIND:
            case ANNOTATION_TYPE_SUBKIND:
                return new MemberInfo(subkind.name(), ((DeclarationSnippet) key).name());
            case METHOD_SUBKIND:
                MethodSnippet method = (MethodSnippet) key;
                return new MemberInfo(method.signature(), method.name());
            case VAR_DECLARATION_SUBKIND:
            case VAR_DECLARATION_WITH_INITIALIZER_SUBKIND:
            case TEMP_VAR_EXPRESSION_SUBKIND:
                VarSnippet var = (VarSnippet) key;
                return new MemberInfo(var.typeName(), var.name());
            default:
                throw new AssertionError("Unknown snippet : " + key.kind() + " in expression " + key.toString());
        }
    }

    public String diagnosticsToString(List<Diag> diagnostics) {
        StringWriter writer = new StringWriter();
        for (Diag diag : diagnostics) {
            writer.write("Error --\n");
            for (String line : diag.getMessage(null).split("\\r?\\n")) {
                writer.write(String.format("%s\n", line));
            }
        }
        return writer.toString().replace("\n", System.lineSeparator());
    }

    public boolean hasFatalError(List<Diag> diagnostics) {
        for (Diag diag : diagnostics) {
            if (diag.isError()) {
                return true;
            }
        }
        return false;
    }

    public static EventChain chain(STEInfo mainInfo, STEInfo... updates) {
        return chain(mainInfo, IGNORE_VALUE, null, updates);
    }

    public static EventChain chain(STEInfo mainInfo, String value, Class<? extends Throwable> exceptionClass, STEInfo... updates) {
        return new EventChain(mainInfo, value, exceptionClass, updates);
    }

    public static STEInfo ste(Snippet key, Status previousStatus, Status status,
                Boolean isSignatureChange, Snippet causeKey) {
        return new STEInfo(key, previousStatus, status, isSignatureChange, causeKey);
    }

    public static STEInfo added(Status status) {
        return new STEInfo(MAIN_SNIPPET, NONEXISTENT, status, status.isDefined(), null);
    }

    public static class EventChain {
        public final STEInfo mainInfo;
        public final STEInfo[] updates;
        public final String value;
        public final Class<? extends Throwable> exceptionClass;

        public EventChain(STEInfo mainInfo, String value, Class<? extends Throwable> exceptionClass, STEInfo... updates) {
            this.mainInfo = mainInfo;
            this.updates = updates;
            this.value = value;
            this.exceptionClass = exceptionClass;
        }
    }

    public static class STEInfo {

        STEInfo(Snippet snippet, Status previousStatus, Status status,
                Boolean isSignatureChange, Snippet causeSnippet) {
            this.snippet = snippet;
            this.previousStatus = previousStatus;
            this.status = status;
            this.checkIsSignatureChange = isSignatureChange != null;
            this.isSignatureChange = checkIsSignatureChange ? isSignatureChange : false;
            this.causeSnippet = causeSnippet;
            assertTrue(snippet != null, "Bad test set-up. The match snippet must not be null");
        }

        final Snippet snippet;
        final Status previousStatus;
        final Status status;
        final boolean isSignatureChange;
        final Snippet causeSnippet;

         final boolean checkIsSignatureChange;
        public Snippet snippet() {
            return snippet;
        }
        public Status previousStatus() {
            return previousStatus;
        }
        public Status status() {
            return status;
        }
        public boolean isSignatureChange() {
            if (!checkIsSignatureChange) {
                throw new IllegalStateException("isSignatureChange value is undefined");
            }
            return isSignatureChange;
        }
        public Snippet causeSnippet() {
            return causeSnippet;
        }
        public String value() {
            return null;
        }
        public Exception exception() {
            return null;
        }

        public void assertMatch(SnippetEvent ste, Snippet mainSnippet) {
            assertKeyMatch(ste, ste.snippet(), snippet(), mainSnippet);
            assertStatusMatch(ste, ste.previousStatus(), previousStatus());
            assertStatusMatch(ste, ste.status(), status());
            if (checkIsSignatureChange) {
                assertEquals(ste.isSignatureChange(), isSignatureChange(),
                        "Expected " +
                                (isSignatureChange()? "" : "no ") +
                                "signature-change, got: " +
                                (ste.isSignatureChange()? "" : "no ") +
                                "signature-change" +
                        "\n   expected-event: " + this + "\n   got-event: " + toString(ste));
            }
            assertKeyMatch(ste, ste.causeSnippet(), causeSnippet(), mainSnippet);
        }

        private void assertKeyMatch(SnippetEvent ste, Snippet sn, Snippet expected, Snippet mainSnippet) {
            Snippet testKey = expected;
            if (testKey != null) {
                if (expected == MAIN_SNIPPET) {
                    assertNotNull(mainSnippet, "MAIN_SNIPPET used, test must pass value to assertMatch");
                    testKey = mainSnippet;
                }
                if (ste.causeSnippet() == null && ste.status() != DROPPED && expected != MAIN_SNIPPET) {
                    // Source change, always new snippet -- only match id()
                    assertTrue(sn != testKey,
                            "Main-event: Expected new snippet to be != : " + testKey
                            + "\n   got-event: " + toString(ste));
                    assertEquals(sn.id(), testKey.id(), "Expected IDs to match: " + testKey + ", got: " + sn
                            + "\n   expected-event: " + this + "\n   got-event: " + toString(ste));
                } else {
                    assertEquals(sn, testKey, "Expected key to be: " + testKey + ", got: " + sn
                            + "\n   expected-event: " + this + "\n   got-event: " + toString(ste));
                }
            }
        }

        private void assertStatusMatch(SnippetEvent ste, Status status, Status expected) {
            if (expected != null) {
                assertEquals(status, expected, "Expected status to be: " + expected + ", got: " + status +
                        "\n   expected-event: " + this + "\n   got-event: " + toString(ste));
            }
        }

        @Override
        public String toString() {
            return "STEInfo key: " +
                    (snippet()==MAIN_SNIPPET? "MAIN_SNIPPET" : (snippet()==null? "ignore" : snippet().id())) +
                    " before: " + previousStatus() +
                    " status: " + status() + " sig: " + isSignatureChange() +
                    " cause: " + (causeSnippet()==null? "null" : causeSnippet().id());
        }

        private String toString(SnippetEvent ste) {
            return "key: " + (ste.snippet()==MAIN_SNIPPET? "MAIN_SNIPPET" : ste.snippet().id()) + " before: " + ste.previousStatus()
                    + " status: " + ste.status() + " sig: " + ste.isSignatureChange()
                    + " cause: " + ste.causeSnippet();
        }
    }
}

Messung
CHZG
88969994

¤ Dauer der Verarbeitung: 0.90 Sekunden  ¤

*Bot Zugriff