Skip to content

Commit 1f782d4

Browse files
committed
Evaluation code for #178.
1 parent aa610f5 commit 1f782d4

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ You should have the following projects in your workspace:
4141

4242
### Running the Evaluator
4343

44-
[annotations]: https://github.com/ponder-lab/edu.cuny.hunter.streamrefactoring.annotations
44+
#### Configuring the Evaluation
45+
46+
A file named `eval.properties` can be placed at the project root. The following keys are available:
47+
48+
Key | Value Type | Description
49+
---------------- | ---------- | ----------
50+
nToUseForStreams | Integer | The value of N to use while building the nCFA for stream types.
4551

4652
### Further Information
4753

4854
See the [wiki][wiki] for further information.
4955

5056
[wiki]: https://github.com/ponder-lab/Java-8-Stream-Refactoring/wiki
57+
[annotations]: https://github.com/ponder-lab/edu.cuny.hunter.streamrefactoring.annotations

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

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package edu.cuny.hunter.streamrefactoring.eval.handlers;
22

3+
import static edu.cuny.hunter.streamrefactoring.core.utils.LoggerNames.LOGGER_NAME;
34
import static edu.cuny.hunter.streamrefactoring.core.utils.Util.createConvertToParallelStreamRefactoringProcessor;
45

6+
import java.io.File;
7+
import java.io.FileReader;
58
import java.io.FileWriter;
69
import java.io.IOException;
710
import java.io.PrintWriter;
11+
import java.io.Reader;
812
import java.util.ArrayList;
913
import java.util.Arrays;
1014
import java.util.Collection;
@@ -13,7 +17,9 @@
1317
import java.util.List;
1418
import java.util.Objects;
1519
import java.util.Optional;
20+
import java.util.Properties;
1621
import java.util.Set;
22+
import java.util.logging.Logger;
1723
import java.util.stream.Collectors;
1824

1925
import org.apache.commons.csv.CSVFormat;
@@ -24,6 +30,7 @@
2430
import org.eclipse.core.resources.IncrementalProjectBuilder;
2531
import org.eclipse.core.resources.ResourcesPlugin;
2632
import org.eclipse.core.runtime.CoreException;
33+
import org.eclipse.core.runtime.IPath;
2734
import org.eclipse.core.runtime.IProgressMonitor;
2835
import org.eclipse.core.runtime.IStatus;
2936
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -74,14 +81,26 @@
7481
*/
7582
public class EvaluateConvertToParallelStreamRefactoringHandler extends AbstractHandler {
7683

84+
private static final String EVALUATION_PROPERTIES_FILE_NAME = "eval.properties";
85+
86+
private static final Logger LOGGER = Logger.getLogger(LOGGER_NAME);
87+
7788
private static final boolean BUILD_WORKSPACE = false;
89+
7890
private static final boolean FIND_IMPLICIT_BENCHMARK_ENTRYPOINTS_DEFAULT = false;
7991
private static final String FIND_IMPLICIT_BENCHMARK_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitBenchmarkEntrypoints";
92+
8093
private static final boolean FIND_IMPLICIT_ENTRYPOINTS_DEFAULT = false;
8194
private static final String FIND_IMPLICIT_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitEntrypoints";
95+
8296
private static final boolean FIND_IMPLICIT_TEST_ENTRYPOINTS_DEFAULT = false;
8397
private static final String FIND_IMPLICIT_TEST_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitTestEntrypoints";
98+
99+
private static final int N_TO_USE_FOR_STREAMS_DEFAULT = 2;
100+
private static final String N_TO_USE_FOR_STREAMS_PROPERTY_KEY = "nToUseForStreams";
101+
84102
private static final int LOGGING_LEVEL = IStatus.INFO;
103+
85104
private static final boolean PERFORM_CHANGE_DEFAULT = false;
86105
private static final String PERFORM_CHANGE_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.performChange";
87106

@@ -189,8 +208,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
189208
IJavaProject[] javaProjects = Util.getSelectedJavaProjectsFromEvent(event);
190209

191210
List<String> resultsHeader = new ArrayList<>(
192-
Arrays.asList("subject", "SLOC", "#entrypoints", "#streams", "#optimization available streams",
193-
"#optimizable streams", "#failed preconditions"));
211+
Arrays.asList("subject", "SLOC", "#entrypoints", "N", "#streams",
212+
"#optimization available streams", "#optimizable streams", "#failed preconditions"));
194213

195214
for (Refactoring refactoring : Refactoring.values())
196215
resultsHeader.add(refactoring.toString());
@@ -235,6 +254,11 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
235254

236255
entryPointsTXTPrinter = new PrintWriter("entry_points.txt");
237256

257+
// set up analysis parameters for all projects.
258+
boolean shouldFindImplicitEntrypoints = shouldFindImplicitEntrypoints();
259+
boolean shouldFindImplicitTestEntrypoints = shouldFindImplicitTestEntrypoints();
260+
boolean shouldFindImplicitBenchmarkEntrypoints = shouldFindImplicitBenchmarkEntrypoints();
261+
238262
for (IJavaProject javaProject : javaProjects) {
239263
if (!javaProject.isStructureKnown())
240264
throw new IllegalStateException(
@@ -246,15 +270,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
246270
// lines of code
247271
resultsPrinter.print(getProjectLinesOfCode(javaProject));
248272

249-
// set up analysis.
273+
// set up analysis for single project.
250274
TimeCollector resultsTimeCollector = new TimeCollector();
251-
boolean shouldFindImplicitEntrypoints = shouldFindImplicitEntrypoints();
252-
boolean shouldFindImplicitTestEntrypoints = shouldFindImplicitTestEntrypoints();
253-
boolean shouldFindImplicitBenchmarkEntrypoints = shouldFindImplicitBenchmarkEntrypoints();
275+
int nToUseForStreams = getNForStreams(javaProject);
254276

255277
resultsTimeCollector.start();
256278
processor = createConvertToParallelStreamRefactoringProcessor(new IJavaProject[] { javaProject },
257-
shouldFindImplicitEntrypoints, shouldFindImplicitTestEntrypoints,
279+
nToUseForStreams, shouldFindImplicitEntrypoints, shouldFindImplicitTestEntrypoints,
258280
shouldFindImplicitBenchmarkEntrypoints, Optional.of(monitor));
259281
resultsTimeCollector.stop();
260282
ConvertToParallelStreamRefactoringProcessor.setLoggingLevel(LOGGING_LEVEL);
@@ -276,6 +298,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
276298
entryPointsTXTPrinter.println(method.getSignature());
277299
}
278300

301+
// N.
302+
resultsPrinter.print(nToUseForStreams);
303+
279304
// #streams.
280305
resultsPrinter.print(processor.getStreamSet().size());
281306

@@ -521,4 +546,32 @@ private static boolean shouldPerformChange() {
521546
else
522547
return Boolean.valueOf(performChangePropertyValue);
523548
}
549+
550+
private static int getNForStreams(IJavaProject project) throws IOException, JavaModelException {
551+
Properties properties = new Properties();
552+
IPath filePath = project.getCorrespondingResource().getLocation().append(EVALUATION_PROPERTIES_FILE_NAME);
553+
File file = filePath.toFile();
554+
555+
if (file.exists())
556+
try (Reader reader = new FileReader(file)) {
557+
properties.load(reader);
558+
559+
String nToUseForStreams = properties.getProperty(N_TO_USE_FOR_STREAMS_PROPERTY_KEY);
560+
561+
if (nToUseForStreams == null) {
562+
int ret = N_TO_USE_FOR_STREAMS_DEFAULT;
563+
LOGGER.info("Using default N for streams: " + ret + ".");
564+
return ret;
565+
} else {
566+
int ret = Integer.valueOf(nToUseForStreams);
567+
LOGGER.info("Using properties file N for streams: " + ret + ".");
568+
return ret;
569+
}
570+
}
571+
else {
572+
int ret = N_TO_USE_FOR_STREAMS_DEFAULT;
573+
LOGGER.info("Using default N for streams: " + ret + ".");
574+
return ret;
575+
}
576+
}
524577
}

0 commit comments

Comments
 (0)