1
1
package edu .cuny .hunter .streamrefactoring .eval .handlers ;
2
2
3
+ import static edu .cuny .hunter .streamrefactoring .core .utils .LoggerNames .LOGGER_NAME ;
3
4
import static edu .cuny .hunter .streamrefactoring .core .utils .Util .createConvertToParallelStreamRefactoringProcessor ;
4
5
6
+ import java .io .File ;
7
+ import java .io .FileReader ;
5
8
import java .io .FileWriter ;
6
9
import java .io .IOException ;
7
10
import java .io .PrintWriter ;
11
+ import java .io .Reader ;
8
12
import java .util .ArrayList ;
9
13
import java .util .Arrays ;
10
14
import java .util .Collection ;
13
17
import java .util .List ;
14
18
import java .util .Objects ;
15
19
import java .util .Optional ;
20
+ import java .util .Properties ;
16
21
import java .util .Set ;
22
+ import java .util .logging .Logger ;
17
23
import java .util .stream .Collectors ;
18
24
19
25
import org .apache .commons .csv .CSVFormat ;
24
30
import org .eclipse .core .resources .IncrementalProjectBuilder ;
25
31
import org .eclipse .core .resources .ResourcesPlugin ;
26
32
import org .eclipse .core .runtime .CoreException ;
33
+ import org .eclipse .core .runtime .IPath ;
27
34
import org .eclipse .core .runtime .IProgressMonitor ;
28
35
import org .eclipse .core .runtime .IStatus ;
29
36
import org .eclipse .core .runtime .NullProgressMonitor ;
74
81
*/
75
82
public class EvaluateConvertToParallelStreamRefactoringHandler extends AbstractHandler {
76
83
84
+ private static final String EVALUATION_PROPERTIES_FILE_NAME = "eval.properties" ;
85
+
86
+ private static final Logger LOGGER = Logger .getLogger (LOGGER_NAME );
87
+
77
88
private static final boolean BUILD_WORKSPACE = false ;
89
+
78
90
private static final boolean FIND_IMPLICIT_BENCHMARK_ENTRYPOINTS_DEFAULT = false ;
79
91
private static final String FIND_IMPLICIT_BENCHMARK_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitBenchmarkEntrypoints" ;
92
+
80
93
private static final boolean FIND_IMPLICIT_ENTRYPOINTS_DEFAULT = false ;
81
94
private static final String FIND_IMPLICIT_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitEntrypoints" ;
95
+
82
96
private static final boolean FIND_IMPLICIT_TEST_ENTRYPOINTS_DEFAULT = false ;
83
97
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
+
84
102
private static final int LOGGING_LEVEL = IStatus .INFO ;
103
+
85
104
private static final boolean PERFORM_CHANGE_DEFAULT = false ;
86
105
private static final String PERFORM_CHANGE_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.performChange" ;
87
106
@@ -189,8 +208,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
189
208
IJavaProject [] javaProjects = Util .getSelectedJavaProjectsFromEvent (event );
190
209
191
210
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" ));
194
213
195
214
for (Refactoring refactoring : Refactoring .values ())
196
215
resultsHeader .add (refactoring .toString ());
@@ -235,6 +254,11 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
235
254
236
255
entryPointsTXTPrinter = new PrintWriter ("entry_points.txt" );
237
256
257
+ // set up analysis parameters for all projects.
258
+ boolean shouldFindImplicitEntrypoints = shouldFindImplicitEntrypoints ();
259
+ boolean shouldFindImplicitTestEntrypoints = shouldFindImplicitTestEntrypoints ();
260
+ boolean shouldFindImplicitBenchmarkEntrypoints = shouldFindImplicitBenchmarkEntrypoints ();
261
+
238
262
for (IJavaProject javaProject : javaProjects ) {
239
263
if (!javaProject .isStructureKnown ())
240
264
throw new IllegalStateException (
@@ -246,15 +270,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
246
270
// lines of code
247
271
resultsPrinter .print (getProjectLinesOfCode (javaProject ));
248
272
249
- // set up analysis.
273
+ // set up analysis for single project .
250
274
TimeCollector resultsTimeCollector = new TimeCollector ();
251
- boolean shouldFindImplicitEntrypoints = shouldFindImplicitEntrypoints ();
252
- boolean shouldFindImplicitTestEntrypoints = shouldFindImplicitTestEntrypoints ();
253
- boolean shouldFindImplicitBenchmarkEntrypoints = shouldFindImplicitBenchmarkEntrypoints ();
275
+ int nToUseForStreams = getNForStreams (javaProject );
254
276
255
277
resultsTimeCollector .start ();
256
278
processor = createConvertToParallelStreamRefactoringProcessor (new IJavaProject [] { javaProject },
257
- shouldFindImplicitEntrypoints , shouldFindImplicitTestEntrypoints ,
279
+ nToUseForStreams , shouldFindImplicitEntrypoints , shouldFindImplicitTestEntrypoints ,
258
280
shouldFindImplicitBenchmarkEntrypoints , Optional .of (monitor ));
259
281
resultsTimeCollector .stop ();
260
282
ConvertToParallelStreamRefactoringProcessor .setLoggingLevel (LOGGING_LEVEL );
@@ -276,6 +298,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
276
298
entryPointsTXTPrinter .println (method .getSignature ());
277
299
}
278
300
301
+ // N.
302
+ resultsPrinter .print (nToUseForStreams );
303
+
279
304
// #streams.
280
305
resultsPrinter .print (processor .getStreamSet ().size ());
281
306
@@ -521,4 +546,32 @@ private static boolean shouldPerformChange() {
521
546
else
522
547
return Boolean .valueOf (performChangePropertyValue );
523
548
}
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
+ }
524
577
}
0 commit comments