33362
+ − 1
/*
+ − 2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ − 3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ − 4
*
+ − 5
* This code is free software; you can redistribute it and/or modify it
+ − 6
* under the terms of the GNU General Public License version 2 only, as
+ − 7
* published by the Free Software Foundation. Oracle designates this
+ − 8
* particular file as subject to the "Classpath" exception as provided
+ − 9
* by Oracle in the LICENSE file that accompanied this code.
+ − 10
*
+ − 11
* This code is distributed in the hope that it will be useful, but WITHOUT
+ − 12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 14
* version 2 for more details (a copy is included in the LICENSE file that
+ − 15
* accompanied this code).
+ − 16
*
+ − 17
* You should have received a copy of the GNU General Public License version
+ − 18
* 2 along with this work; if not, write to the Free Software Foundation,
+ − 19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ − 20
*
+ − 21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ − 22
* or visit www.oracle.com if you need additional information or have any
+ − 23
* questions.
+ − 24
*/
+ − 25
+ − 26
package jdk.jshell;
+ − 27
+ − 28
import java.util.ArrayList;
+ − 29
import java.util.Collection;
+ − 30
import java.util.stream.Collectors;
+ − 31
+ − 32
/**
+ − 33
* List of diagnostics, with convenient operations.
+ − 34
*
+ − 35
* @author Robert Field
+ − 36
*/
+ − 37
@SuppressWarnings("serial") // serialVersionUID intentionally omitted
+ − 38
final class DiagList extends ArrayList<Diag> {
+ − 39
+ − 40
private int cntNotStmt = 0;
+ − 41
private int cntUnreach = 0;
+ − 42
private int cntResolve = 0;
+ − 43
private int cntOther = 0;
+ − 44
+ − 45
DiagList() {
+ − 46
super();
+ − 47
}
+ − 48
+ − 49
DiagList(Diag d) {
+ − 50
super();
+ − 51
add(d);
+ − 52
}
+ − 53
+ − 54
DiagList(Collection<? extends Diag> c) {
+ − 55
super();
+ − 56
addAll(c);
+ − 57
}
+ − 58
+ − 59
private void tally(Diag d) {
+ − 60
if (d.isError()) {
+ − 61
if (d.isUnreachableError()) {
+ − 62
++cntUnreach;
+ − 63
} else if (d.isNotAStatementError()) {
+ − 64
++cntNotStmt;
+ − 65
} else if (d.isResolutionError()) {
+ − 66
++cntResolve;
+ − 67
} else {
+ − 68
++cntOther;
+ − 69
}
+ − 70
}
+ − 71
}
+ − 72
+ − 73
@Override
+ − 74
public boolean addAll(Collection<? extends Diag> c) {
+ − 75
return c.stream().filter(d -> add(d)).count() > 0;
+ − 76
}
+ − 77
+ − 78
@Override
+ − 79
public Diag set(int index, Diag element) {
+ − 80
throw new UnsupportedOperationException();
+ − 81
}
+ − 82
+ − 83
@Override
+ − 84
public void add(int index, Diag element) {
+ − 85
throw new UnsupportedOperationException();
+ − 86
}
+ − 87
+ − 88
@Override
+ − 89
public boolean add(Diag d) {
+ − 90
boolean added = super.add(d);
+ − 91
if (added) {
+ − 92
tally(d);
+ − 93
}
+ − 94
return added;
+ − 95
}
+ − 96
+ − 97
@Override
+ − 98
public boolean addAll(int index, Collection<? extends Diag> c) {
+ − 99
throw new UnsupportedOperationException();
+ − 100
}
+ − 101
+ − 102
@Override
+ − 103
public boolean remove(Object o) {
+ − 104
throw new UnsupportedOperationException();
+ − 105
}
+ − 106
+ − 107
DiagList ofUnit(Unit u) {
+ − 108
return this.stream()
+ − 109
.filter(d -> d.unitOrNull() == u)
+ − 110
.collect(Collectors.toCollection(() -> new DiagList()));
+ − 111
}
+ − 112
+ − 113
boolean hasErrors() {
+ − 114
return (cntNotStmt + cntResolve + cntUnreach + cntOther) > 0;
+ − 115
}
+ − 116
+ − 117
boolean hasResolutionErrorsAndNoOthers() {
+ − 118
return cntResolve > 0 && (cntNotStmt + cntUnreach + cntOther) == 0;
+ − 119
}
+ − 120
+ − 121
boolean hasUnreachableError() {
+ − 122
return cntUnreach > 0;
+ − 123
}
+ − 124
+ − 125
boolean hasNotStatement() {
+ − 126
return cntNotStmt > 0;
+ − 127
}
+ − 128
+ − 129
boolean hasOtherThanNotStatementErrors() {
+ − 130
return (cntResolve + cntUnreach + cntOther) > 0;
+ − 131
}
+ − 132
+ − 133
}