62
62
63
63
/**
64
64
* The activator class controls the plug-in life cycle
65
- *
65
+ *
66
66
* @author <a href="mailto:[email protected] ">Raffi
67
67
* Khatchadourian</a>
68
68
*/
@@ -102,7 +102,7 @@ private static void logWarning(String message) {
102
102
/**
103
103
* Minimum logging level. One of the constants in
104
104
* org.eclipse.core.runtime.IStatus.
105
- *
105
+ *
106
106
* @param level
107
107
* The minimum logging level to set.
108
108
* @see org.eclipse.core.runtime.IStatus.
@@ -118,30 +118,35 @@ public static void setLoggingLevel(int level) {
118
118
*/
119
119
private TimeCollector excludedTimeCollector = new TimeCollector ();
120
120
121
+ private IJavaProject [] javaProjects ;
122
+
121
123
/** Does the refactoring use a working copy layer? */
122
124
private final boolean layer ;
123
125
126
+ private Map <IJavaProject , Collection <Entrypoint >> projectToEntryPoints ;
127
+
124
128
private SearchEngine searchEngine = new SearchEngine ();
125
129
126
130
/** The code generation settings, or <code>null</code> */
127
131
private CodeGenerationSettings settings ;
128
132
133
+ private Set <Stream > streamSet ;
134
+
129
135
private Map <ITypeRoot , CompilationUnit > typeRootToCompilationUnitMap = new HashMap <>();
130
136
131
137
private Map <IType , ITypeHierarchy > typeToTypeHierarchyMap = new HashMap <>();
132
138
133
- private IJavaProject [] javaProjects ;
134
-
135
- private Set <Stream > streamSet ;
136
-
137
- private Map <IJavaProject , Collection <Entrypoint >> projectToEntryPoints ;
138
-
139
139
private boolean useImplicitEntrypoints = true ;
140
140
141
141
public ConvertToParallelStreamRefactoringProcessor () throws JavaModelException {
142
142
this (null , null , false , true , Optional .empty ());
143
143
}
144
144
145
+ public ConvertToParallelStreamRefactoringProcessor (final CodeGenerationSettings settings ,
146
+ Optional <IProgressMonitor > monitor ) throws JavaModelException {
147
+ this (null , settings , false , true , monitor );
148
+ }
149
+
145
150
public ConvertToParallelStreamRefactoringProcessor (IJavaProject [] javaProjects ,
146
151
final CodeGenerationSettings settings , boolean layer , boolean useImplicitEntrypoints ,
147
152
Optional <IProgressMonitor > monitor ) throws JavaModelException {
@@ -155,22 +160,17 @@ public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
155
160
}
156
161
}
157
162
158
- public ConvertToParallelStreamRefactoringProcessor (final CodeGenerationSettings settings ,
159
- Optional <IProgressMonitor > monitor ) throws JavaModelException {
160
- this (null , settings , false , true , monitor );
163
+ public ConvertToParallelStreamRefactoringProcessor (IJavaProject [] javaProjects ,
164
+ final CodeGenerationSettings settings , boolean useImplicitJoinpoints , Optional <IProgressMonitor > monitor )
165
+ throws JavaModelException {
166
+ this (javaProjects , settings , false , useImplicitJoinpoints , monitor );
161
167
}
162
168
163
169
public ConvertToParallelStreamRefactoringProcessor (IJavaProject [] javaProjects ,
164
170
final CodeGenerationSettings settings , Optional <IProgressMonitor > monitor ) throws JavaModelException {
165
171
this (javaProjects , settings , false , true , monitor );
166
172
}
167
173
168
- public ConvertToParallelStreamRefactoringProcessor (IJavaProject [] javaProjects ,
169
- final CodeGenerationSettings settings , boolean useImplicitJoinpoints , Optional <IProgressMonitor > monitor )
170
- throws JavaModelException {
171
- this (javaProjects , settings , false , useImplicitJoinpoints , monitor );
172
- }
173
-
174
174
public ConvertToParallelStreamRefactoringProcessor (Optional <IProgressMonitor > monitor ) throws JavaModelException {
175
175
this (null , null , false , true , monitor );
176
176
}
@@ -190,35 +190,33 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
190
190
this .getJavaProjects ().length * 1000 );
191
191
final RefactoringStatus status = new RefactoringStatus ();
192
192
StreamAnalyzer analyzer = new StreamAnalyzer (false , this .getUseImplicitEntrypoints ());
193
- setStreamSet (analyzer .getStreamSet ());
193
+ this . setStreamSet (analyzer .getStreamSet ());
194
194
195
195
for (IJavaProject jproj : this .getJavaProjects ()) {
196
196
IPackageFragmentRoot [] roots = jproj .getPackageFragmentRoots ();
197
197
for (IPackageFragmentRoot root : roots ) {
198
198
IJavaElement [] children = root .getChildren ();
199
- for (IJavaElement child : children ) {
199
+ for (IJavaElement child : children )
200
200
if (child .getElementType () == IJavaElement .PACKAGE_FRAGMENT ) {
201
201
IPackageFragment fragment = (IPackageFragment ) child ;
202
202
ICompilationUnit [] units = fragment .getCompilationUnits ();
203
203
for (ICompilationUnit unit : units ) {
204
- CompilationUnit compilationUnit = getCompilationUnit (unit , subMonitor .split (1 ));
204
+ CompilationUnit compilationUnit = this . getCompilationUnit (unit , subMonitor .split (1 ));
205
205
compilationUnit .accept (analyzer );
206
206
}
207
207
}
208
- }
209
208
}
210
209
}
211
210
212
211
// analyze and set entry points.
213
- projectToEntryPoints = analyzer .analyze ();
214
-
212
+ this . projectToEntryPoints = analyzer .analyze ();
213
+
215
214
// map empty set to unprocessed projects.
216
215
for (IJavaProject project : this .getJavaProjects ())
217
216
this .projectToEntryPoints .computeIfAbsent (project , p -> Collections .emptySet ());
218
-
219
217
220
218
// get the status of each stream.
221
- RefactoringStatus collectedStatus = getStreamSet ().stream ().map (Stream ::getStatus )
219
+ RefactoringStatus collectedStatus = this . getStreamSet ().stream ().map (Stream ::getStatus )
222
220
.collect (() -> new RefactoringStatus (), (a , b ) -> a .merge (b ), (a , b ) -> a .merge (b ));
223
221
status .merge (collectedStatus );
224
222
@@ -245,14 +243,6 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
245
243
}
246
244
}
247
245
248
- public Collection <Entrypoint > getEntryPoints (IJavaProject javaProject ) {
249
- return this .projectToEntryPoints .get (javaProject );
250
- }
251
-
252
- private boolean getUseImplicitEntrypoints () {
253
- return this .useImplicitEntrypoints ;
254
- }
255
-
256
246
@ Override
257
247
public RefactoringStatus checkInitialConditions (IProgressMonitor pm )
258
248
throws CoreException , OperationCanceledException {
@@ -288,12 +278,11 @@ private RefactoringStatus checkProjectCompliance(IJavaProject destinationProject
288
278
}
289
279
290
280
private RefactoringStatus checkStructure (IMember member ) throws JavaModelException {
291
- if (!member .isStructureKnown ()) {
281
+ if (!member .isStructureKnown ())
292
282
return RefactoringStatus .createErrorStatus (
293
283
MessageFormat .format (Messages .CUContainsCompileErrors , getElementLabel (member , ALL_FULLY_QUALIFIED ),
294
284
getElementLabel (member .getCompilationUnit (), ALL_FULLY_QUALIFIED )),
295
285
JavaStatusContext .create (member .getCompilationUnit ()));
296
- }
297
286
return new RefactoringStatus ();
298
287
}
299
288
@@ -305,9 +294,9 @@ private RefactoringStatus checkWritabilitiy(IMember member, PreconditionFailure
305
294
}
306
295
307
296
public void clearCaches () {
308
- getTypeToTypeHierarchyMap ().clear ();
309
- getCompilationUnitToCompilationUnitRewriteMap ().clear ();
310
- getTypeRootToCompilationUnitMap ().clear ();
297
+ this . getTypeToTypeHierarchyMap ().clear ();
298
+ this . getCompilationUnitToCompilationUnitRewriteMap ().clear ();
299
+ this . getTypeRootToCompilationUnitMap ().clear ();
311
300
}
312
301
313
302
@ Override
@@ -322,8 +311,8 @@ public Change createChange(IProgressMonitor pm) throws CoreException, OperationC
322
311
.filter (cu -> !manager .containsChangesIn (cu )).toArray (ICompilationUnit []::new );
323
312
324
313
for (ICompilationUnit cu : units ) {
325
- CompilationUnit compilationUnit = getCompilationUnit (cu , pm );
326
- manageCompilationUnit (manager , getCompilationUnitRewrite (cu , compilationUnit ),
314
+ CompilationUnit compilationUnit = this . getCompilationUnit (cu , pm );
315
+ this . manageCompilationUnit (manager , this . getCompilationUnitRewrite (cu , compilationUnit ),
327
316
Optional .of (new SubProgressMonitor (pm , IProgressMonitor .UNKNOWN )));
328
317
}
329
318
@@ -335,7 +324,7 @@ public Change createChange(IProgressMonitor pm) throws CoreException, OperationC
335
324
ConvertStreamToParallelRefactoringDescriptor descriptor = new ConvertStreamToParallelRefactoringDescriptor (
336
325
null , "TODO" , null , arguments , flags );
337
326
338
- return new DynamicValidationRefactoringChange (descriptor , getProcessorName (), manager .getAllChanges ());
327
+ return new DynamicValidationRefactoringChange (descriptor , this . getProcessorName (), manager .getAllChanges ());
339
328
} finally {
340
329
pm .done ();
341
330
this .clearCaches ();
@@ -395,22 +384,38 @@ public Object[] getElements() {
395
384
return null ;
396
385
}
397
386
387
+ public Collection <Entrypoint > getEntryPoints (IJavaProject javaProject ) {
388
+ return this .projectToEntryPoints .get (javaProject );
389
+ }
390
+
398
391
public TimeCollector getExcludedTimeCollector () {
399
- return excludedTimeCollector ;
392
+ return this . excludedTimeCollector ;
400
393
}
401
394
402
395
@ Override
403
396
public String getIdentifier () {
404
397
return ConvertStreamToParallelRefactoringDescriptor .REFACTORING_ID ;
405
398
}
406
399
400
+ protected IJavaProject [] getJavaProjects () {
401
+ return this .javaProjects ;
402
+ }
403
+
404
+ public Set <Stream > getOptimizableStreams () {
405
+ return this .getStreamSet ().parallelStream ().filter (s -> !s .getStatus ().hasError ()).collect (Collectors .toSet ());
406
+ }
407
+
407
408
@ Override
408
409
public String getProcessorName () {
409
410
return Messages .Name ;
410
411
}
411
412
412
413
private SearchEngine getSearchEngine () {
413
- return searchEngine ;
414
+ return this .searchEngine ;
415
+ }
416
+
417
+ public Set <Stream > getStreamSet () {
418
+ return this .streamSet ;
414
419
}
415
420
416
421
private ITypeHierarchy getTypeHierarchy (IType type , Optional <IProgressMonitor > monitor ) throws JavaModelException {
@@ -428,12 +433,20 @@ private ITypeHierarchy getTypeHierarchy(IType type, Optional<IProgressMonitor> m
428
433
}
429
434
}
430
435
436
+ protected Map <ITypeRoot , CompilationUnit > getTypeRootToCompilationUnitMap () {
437
+ return this .typeRootToCompilationUnitMap ;
438
+ }
439
+
431
440
protected Map <IType , ITypeHierarchy > getTypeToTypeHierarchyMap () {
432
- return typeToTypeHierarchyMap ;
441
+ return this . typeToTypeHierarchyMap ;
433
442
}
434
443
435
- protected Map <ITypeRoot , CompilationUnit > getTypeRootToCompilationUnitMap () {
436
- return typeRootToCompilationUnitMap ;
444
+ public Set <Stream > getUnoptimizableStreams () {
445
+ return this .getStreamSet ().parallelStream ().filter (s -> s .getStatus ().hasError ()).collect (Collectors .toSet ());
446
+ }
447
+
448
+ private boolean getUseImplicitEntrypoints () {
449
+ return this .useImplicitEntrypoints ;
437
450
}
438
451
439
452
@ Override
@@ -467,23 +480,7 @@ private void manageCompilationUnit(final TextEditBasedChangeManager manager, Com
467
480
manager .manage (rewrite .getCu (), change );
468
481
}
469
482
470
- protected IJavaProject [] getJavaProjects () {
471
- return javaProjects ;
472
- }
473
-
474
- public Set <Stream > getStreamSet () {
475
- return streamSet ;
476
- }
477
-
478
483
protected void setStreamSet (Set <Stream > streamSet ) {
479
484
this .streamSet = streamSet ;
480
485
}
481
-
482
- public Set <Stream > getOptimizableStreams () {
483
- return this .getStreamSet ().parallelStream ().filter (s -> !s .getStatus ().hasError ()).collect (Collectors .toSet ());
484
- }
485
-
486
- public Set <Stream > getUnoptimizableStreams () {
487
- return this .getStreamSet ().parallelStream ().filter (s -> s .getStatus ().hasError ()).collect (Collectors .toSet ());
488
- }
489
486
}
0 commit comments