11
11
import java .util .HashSet ;
12
12
import java .util .Iterator ;
13
13
import java .util .Map ;
14
+ import java .util .Optional ;
14
15
import java .util .Scanner ;
15
16
import java .util .Set ;
16
17
import java .util .logging .Level ;
42
43
import com .ibm .wala .util .scope .JUnitEntryPoints ;
43
44
44
45
import edu .cuny .hunter .streamrefactoring .core .utils .LoggerNames ;
46
+ import edu .cuny .hunter .streamrefactoring .core .utils .TimeCollector ;
45
47
import edu .cuny .hunter .streamrefactoring .core .wala .EclipseProjectAnalysisEngine ;
46
48
47
49
@ SuppressWarnings ("restriction" )
@@ -51,7 +53,7 @@ public class StreamAnalyzer extends ASTVisitor {
51
53
52
54
private static final int N_FOR_STREAMS_DEFAULT = 2 ;
53
55
54
- private static final String ENTRY_POINT_FILE = "entry_points.txt" ;
56
+ private static final String ENTRY_POINT_FILENAME = "entry_points.txt" ;
55
57
56
58
private static void addImplicitEntryPoints (Collection <Entrypoint > target , Iterable <Entrypoint > source ) {
57
59
for (Entrypoint implicitEntryPoint : source )
@@ -117,11 +119,24 @@ public StreamAnalyzer(boolean visitDocTags, int nForStreams, boolean findImplici
117
119
118
120
/**
119
121
* Analyzes this {@link StreamAnalyzer}'s streams.
120
- *
121
- * @return {@link Map} of project's analyzed along with the entry points used.
122
+ *
123
+ * @return A {@link Map} of project's analyzed along with the entry points used.
124
+ * @see #analyze(Optional).
122
125
*/
123
126
public Map <IJavaProject , Collection <Entrypoint >> analyze () throws CoreException {
124
- LOGGER .info (() -> "Using N = " + this .getNForStreams ());
127
+ return this .analyze (Optional .empty ());
128
+ }
129
+
130
+ /**
131
+ * Analyzes this {@link StreamAnalyzer}'s streams.
132
+ *
133
+ * @param collector
134
+ * To exclude from the time certain parts of the analysis.
135
+ * @return A {@link Map} of project's analyzed along with the entry points used.
136
+ * @see #analyze().
137
+ */
138
+ public Map <IJavaProject , Collection <Entrypoint >> analyze (Optional <TimeCollector > collector ) throws CoreException {
139
+ LOGGER .info (() -> "Using N = " + this .getNForStreams () + "." );
125
140
126
141
Map <IJavaProject , Collection <Entrypoint >> ret = new HashMap <>();
127
142
@@ -132,6 +147,9 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException
132
147
// process each project.
133
148
for (IJavaProject project : projectToStreams .keySet ()) {
134
149
// create the analysis engine for the project.
150
+ // exclude from the analysis because the IR will be built here.
151
+
152
+ collector .ifPresent (TimeCollector ::start );
135
153
EclipseProjectAnalysisEngine <InstanceKey > engine = null ;
136
154
try {
137
155
engine = new EclipseProjectAnalysisEngine <>(project , this .getNForStreams ());
@@ -140,11 +158,12 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException
140
158
LOGGER .log (Level .SEVERE , "Could not create analysis engine for: " + project .getElementName (), e );
141
159
throw new RuntimeException (e );
142
160
}
161
+ collector .ifPresent (TimeCollector ::stop );
143
162
144
163
// build the call graph for the project.
145
164
Collection <Entrypoint > entryPoints = null ;
146
165
try {
147
- entryPoints = this .buildCallGraph (engine );
166
+ entryPoints = this .buildCallGraph (engine , collector );
148
167
} catch (IOException | CoreException | CancelException e ) {
149
168
LOGGER .log (Level .SEVERE ,
150
169
"Exception encountered while building call graph for: " + project .getElementName () + "." , e );
@@ -213,18 +232,27 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException
213
232
* @param engine
214
233
* The EclipseProjectAnalysisEngine for which to build the call
215
234
* graph.
235
+ * @param collector
236
+ * A {@link TimeCollector} to exclude entry point finding.
216
237
* @return The {@link Entrypoint}s used in building the {@link CallGraph}.
217
238
*/
218
- protected Collection <Entrypoint > buildCallGraph (EclipseProjectAnalysisEngine <InstanceKey > engine )
239
+ protected Collection <Entrypoint > buildCallGraph (EclipseProjectAnalysisEngine <InstanceKey > engine ,
240
+ Optional <TimeCollector > collector )
219
241
throws IOException , CoreException , CallGraphBuilderCancelException , CancelException {
220
242
// if we haven't built the call graph yet.
221
243
if (!this .enginesWithBuiltCallGraphsToEntrypointsUsed .keySet ().contains (engine )) {
222
-
244
+ // find entry points (but exclude it from the time).
245
+ collector .ifPresent (TimeCollector ::start );
223
246
Set <Entrypoint > entryPoints ;
247
+
224
248
// find the entry_points.txt in the project directory
225
- File entryPointFile = getEntryPointsFile (engine .getProject ().getResource ().getLocation (), ENTRY_POINT_FILE );
249
+ File entryPointFile = getEntryPointsFile (engine .getProject ().getResource ().getLocation (),
250
+ ENTRY_POINT_FILENAME );
251
+
252
+ // if the file was found,
226
253
if (entryPointFile != null ) {
227
- // find explicit entry points from entry_points.txt
254
+ // find explicit entry points from entry_points.txt. Ignore the explicit
255
+ // (annotation-based) entry points.
228
256
entryPoints = findEntryPointsFromFile (engine .getClassHierarchy (), entryPointFile );
229
257
entryPoints .forEach (ep -> LOGGER .info (() -> "Adding explicit entry point from file: " + ep ));
230
258
} else {
@@ -233,7 +261,7 @@ protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<Ins
233
261
entryPoints .forEach (ep -> LOGGER .info (() -> "Adding explicit entry point: " + ep ));
234
262
}
235
263
236
- if (this .findImplicitEntryPoints ) {
264
+ if (this .shouldFindImplicitEntryPoints () ) {
237
265
// also find implicit entry points.
238
266
Iterable <Entrypoint > mainEntrypoints = makeMainEntrypoints (engine .getClassHierarchy ().getScope (),
239
267
engine .getClassHierarchy ());
@@ -242,15 +270,15 @@ protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<Ins
242
270
addImplicitEntryPoints (entryPoints , mainEntrypoints );
243
271
}
244
272
245
- if (this .findImplicitTestEntryPoints ) {
273
+ if (this .shouldFindImplicitTestEntryPoints () ) {
246
274
// try to find test entry points.
247
275
Iterable <Entrypoint > jUnitEntryPoints = JUnitEntryPoints .make (engine .getClassHierarchy ());
248
276
249
277
// add them as well.
250
278
addImplicitEntryPoints (entryPoints , jUnitEntryPoints );
251
279
}
252
280
253
- if (this .findImplicitBenchmarkEntryPoints ) {
281
+ if (this .shouldFindImplicitBenchmarkEntryPoints () ) {
254
282
// try to find benchmark entry points.
255
283
Set <Entrypoint > benchmarkEntryPoints = Util .findBenchmarkEntryPoints (engine .getClassHierarchy ());
256
284
@@ -263,6 +291,8 @@ protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<Ins
263
291
return entryPoints ;
264
292
}
265
293
294
+ collector .ifPresent (TimeCollector ::stop );
295
+
266
296
// set options.
267
297
AnalysisOptions options = engine .getDefaultOptions (entryPoints );
268
298
// Turn off reflection analysis.
@@ -306,20 +336,21 @@ private static Set<Entrypoint> findEntryPointsFromFile(IClassHierarchy classHier
306
336
}
307
337
308
338
/**
309
- * Search entry_points.txt in project directory recursively
339
+ * Search entry_points.txt in project directory recursively.
310
340
*
311
- * @param directory:
312
- * project directory
313
- * @param fileName:
314
- * the target file
315
- * @return null: the file does not exist / file: find the file
341
+ * @param directory
342
+ * Project directory.
343
+ * @param fileName
344
+ * The target file.
345
+ * @return null if the file does not exist and file if we found the file.
316
346
*/
317
347
private static File getEntryPointsFile (IPath directory , String fileName ) {
318
- // If file does not exist, find the file in upper level
348
+ // If file does not exist, find the file in upper level.
319
349
Path directoryPath = Paths .get (directory .toString ());
350
+
320
351
File file ;
321
352
do {
322
- file = new File (directoryPath .resolve (ENTRY_POINT_FILE ).toString ());
353
+ file = new File (directoryPath .resolve (ENTRY_POINT_FILENAME ).toString ());
323
354
directoryPath = directoryPath .getParent ();
324
355
} while (!file .exists () && directoryPath != null );
325
356
@@ -337,10 +368,26 @@ public void setFindImplicitEntryPoints(boolean findImplicitEntryPoints) {
337
368
this .findImplicitEntryPoints = findImplicitEntryPoints ;
338
369
}
339
370
371
+ public boolean shouldFindImplicitEntryPoints () {
372
+ return findImplicitEntryPoints ;
373
+ }
374
+
340
375
public void setFindImplicitTestEntryPoints (boolean findImplicitTestEntryPoints ) {
341
376
this .findImplicitTestEntryPoints = findImplicitTestEntryPoints ;
342
377
}
343
378
379
+ public boolean shouldFindImplicitTestEntryPoints () {
380
+ return findImplicitTestEntryPoints ;
381
+ }
382
+
383
+ public boolean shouldFindImplicitBenchmarkEntryPoints () {
384
+ return findImplicitBenchmarkEntryPoints ;
385
+ }
386
+
387
+ public void setFindImplicitBenchmarkEntryPoints (boolean findImplicitBenchmarkEntryPoints ) {
388
+ this .findImplicitBenchmarkEntryPoints = findImplicitBenchmarkEntryPoints ;
389
+ }
390
+
344
391
/**
345
392
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
346
393
*/
0 commit comments