Skip to content

Commit 78e3b11

Browse files
committed
Filter streams from the evaluation.
1 parent cdae3ee commit 78e3b11

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

edu.cuny.hunter.streamrefactoring.eval/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui,
1212
org.eclipse.jdt.core,
1313
org.eclipse.ltk.core.refactoring,
1414
edu.cuny.citytech.refactoring.common.core;bundle-version="1.1.0",
15-
net.sourceforge.metrics;bundle-version="1.3.8"
15+
net.sourceforge.metrics;bundle-version="1.3.8",
16+
com.google.guava;bundle-version="21.0.0"
1617
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
1718
Bundle-ClassPath: .,
1819
lib/commons-csv-1.1.jar

edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.IOException;
77
import java.util.ArrayList;
88
import java.util.Arrays;
9+
import java.util.Collection;
910
import java.util.Collections;
1011
import java.util.HashSet;
1112
import java.util.List;
@@ -48,6 +49,10 @@
4849
import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
4950
import org.osgi.framework.FrameworkUtil;
5051

52+
import com.google.common.collect.Sets;
53+
import com.google.common.collect.Sets.SetView;
54+
55+
import edu.cuny.hunter.streamrefactoring.core.analysis.PreconditionFailure;
5156
import edu.cuny.hunter.streamrefactoring.core.analysis.PreconditionSuccess;
5257
import edu.cuny.hunter.streamrefactoring.core.analysis.Refactoring;
5358
import edu.cuny.hunter.streamrefactoring.core.analysis.Stream;
@@ -236,18 +241,34 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
236241
// #streams.
237242
resultsPrinter.print(processor.getStreamSet().size());
238243

239-
// #optimization available streams. These are the "filtered" streams. No
240-
// filtering currently.
241-
resultsPrinter.print(processor.getStreamSet().size());
244+
// #optimization available streams. These are the "filtered" streams.
245+
Set<Stream> candidates = processor.getStreamSet().parallelStream().filter(s -> {
246+
String pluginId = FrameworkUtil.getBundle(Stream.class).getSymbolicName();
242247

243-
// candidate streams and their attributes.
244-
for (Stream stream : processor.getStreamSet()) {
248+
// error related to reachability.
249+
RefactoringStatusEntry reachabilityError = s.getStatus().getEntryMatchingCode(pluginId,
250+
PreconditionFailure.STREAM_CODE_NOT_REACHABLE.getCode());
251+
252+
// error related to missing entry points.
253+
RefactoringStatusEntry entryPointError = s.getStatus().getEntryMatchingCode(pluginId,
254+
PreconditionFailure.NO_ENTRY_POINT.getCode());
255+
256+
// filter streams without such errors.
257+
return reachabilityError == null && entryPointError == null;
258+
}).collect(Collectors.toSet());
259+
260+
resultsPrinter.print(candidates.size()); // number.
261+
262+
// candidate streams.
263+
for (Stream stream : candidates)
245264
candidateStreamPrinter.printRecord(javaProject.getElementName(), stream.getCreation(),
246265
stream.getCreation().getStartPosition(), stream.getCreation().getLength(),
247266
Util.getMethodIdentifier(stream.getEnclosingEclipseMethod()),
248267
stream.getEnclosingType() == null ? null
249268
: stream.getEnclosingType().getFullyQualifiedName());
250269

270+
// stream attributes.
271+
for (Stream stream : processor.getStreamSet()) {
251272
streamAttributesPrinter.printRecord(javaProject.getElementName(), stream.getCreation(),
252273
stream.getCreation().getStartPosition(), stream.getCreation().getLength(),
253274
Util.getMethodIdentifier(stream.getEnclosingEclipseMethod()),
@@ -259,10 +280,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
259280
: stream.getStatus().getEntryWithHighestSeverity().getSeverity());
260281

261282
String method = Util.getMethodIdentifier(stream.getEnclosingEclipseMethod());
283+
262284
printStreamAttributesWithMultipleValues(stream.getActions(), streamActionsPrinter, stream,
263285
method, javaProject);
286+
264287
printStreamAttributesWithMultipleValues(stream.getPossibleExecutionModes(),
265288
streamExecutionModePrinter, stream, method, javaProject);
289+
266290
printStreamAttributesWithMultipleValues(stream.getPossibleOrderings(), streamOrderingPrinter,
267291
stream, method, javaProject);
268292

@@ -279,16 +303,20 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
279303
stream.getEnclosingType().getFullyQualifiedName());
280304

281305
// failed streams.
282-
for (Stream stream : processor.getUnoptimizableStreams())
306+
SetView<Stream> failures = Sets.difference(candidates, processor.getOptimizableStreams());
307+
308+
for (Stream stream : failures)
283309
nonOptimizedStreamPrinter.printRecord(javaProject.getElementName(), stream.getCreation(),
284310
stream.getCreation().getStartPosition(), stream.getCreation().getLength(),
285311
Util.getMethodIdentifier(stream.getEnclosingEclipseMethod()),
286312
stream.getEnclosingType() == null ? null
287313
: stream.getEnclosingType().getFullyQualifiedName());
288314

289315
// failed preconditions.
290-
List<RefactoringStatusEntry> errorEntries = Arrays.stream(status.getEntries())
291-
.filter(RefactoringStatusEntry::isError).collect(Collectors.toList());
316+
Collection<RefactoringStatusEntry> errorEntries = failures.parallelStream().map(Stream::getStatus)
317+
.flatMap(s -> Arrays.stream(s.getEntries())).filter(RefactoringStatusEntry::isError)
318+
.collect(Collectors.toSet());
319+
292320
resultsPrinter.print(errorEntries.size()); // number.
293321

294322
for (RefactoringStatusEntry entry : errorEntries)
@@ -301,6 +329,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
301329
+ correspondingElement.getClass());
302330

303331
Stream failedStream = (Stream) correspondingElement;
332+
304333
errorPrinter.printRecord(javaProject.getElementName(), failedStream.getCreation(),
305334
failedStream.getCreation().getStartPosition(),
306335
failedStream.getCreation().getLength(),

0 commit comments

Comments
 (0)