author | rfield |
Wed, 08 Feb 2017 10:43:16 -0800 | |
changeset 43758 | 868af3718a21 |
parent 42827 | 36468b5fa7f4 |
permissions | -rw-r--r-- |
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) { |
|
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
37644
diff
changeset
|
75 |
return c.stream().filter(this::add).count() > 0; |
33362 | 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() |
|
37644
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
33362
diff
changeset
|
109 |
.filter(d -> { |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
33362
diff
changeset
|
110 |
Snippet snn = d.snippetOrNull(); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
33362
diff
changeset
|
111 |
return snn == u.snippet(); |
33cf53901cac
8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents:
33362
diff
changeset
|
112 |
}) |
42827
36468b5fa7f4
8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents:
37644
diff
changeset
|
113 |
.collect(Collectors.toCollection(DiagList::new)); |
33362 | 114 |
} |
115 |
||
116 |
boolean hasErrors() { |
|
117 |
return (cntNotStmt + cntResolve + cntUnreach + cntOther) > 0; |
|
118 |
} |
|
119 |
||
120 |
boolean hasResolutionErrorsAndNoOthers() { |
|
121 |
return cntResolve > 0 && (cntNotStmt + cntUnreach + cntOther) == 0; |
|
122 |
} |
|
123 |
||
124 |
boolean hasUnreachableError() { |
|
125 |
return cntUnreach > 0; |
|
126 |
} |
|
127 |
||
128 |
boolean hasNotStatement() { |
|
129 |
return cntNotStmt > 0; |
|
130 |
} |
|
131 |
||
132 |
boolean hasOtherThanNotStatementErrors() { |
|
133 |
return (cntResolve + cntUnreach + cntOther) > 0; |
|
134 |
} |
|
135 |
||
136 |
} |