Skip to content

Commit 7b26cd2

Browse files
committed
Clean up.
1 parent d4ce559 commit 7b26cd2

File tree

3 files changed

+77
-80
lines changed

3 files changed

+77
-80
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public StreamAnalyzer(boolean visitDocTags, boolean findImplicitEntryPoints, boo
8181

8282
/**
8383
* Analyzes this {@link StreamAnalyzer}'s streams.
84-
*
84+
*
8585
* @return {@link Map} of project's analyzed along with the entry points used.
8686
*/
8787
public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException {
@@ -171,7 +171,7 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException
171171
/**
172172
* Builds the call graph that is part of the
173173
* {@link EclipseProjectAnalysisEngine}.
174-
*
174+
*
175175
* @param engine
176176
* The EclipseProjectAnalysisEngine for which to build the call
177177
* graph.

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/ConvertToParallelStreamRefactoringProcessor.java

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
/**
6464
* The activator class controls the plug-in life cycle
65-
*
65+
*
6666
* @author <a href="mailto:[email protected]">Raffi
6767
* Khatchadourian</a>
6868
*/
@@ -102,7 +102,7 @@ private static void logWarning(String message) {
102102
/**
103103
* Minimum logging level. One of the constants in
104104
* org.eclipse.core.runtime.IStatus.
105-
*
105+
*
106106
* @param level
107107
* The minimum logging level to set.
108108
* @see org.eclipse.core.runtime.IStatus.
@@ -118,30 +118,35 @@ public static void setLoggingLevel(int level) {
118118
*/
119119
private TimeCollector excludedTimeCollector = new TimeCollector();
120120

121+
private IJavaProject[] javaProjects;
122+
121123
/** Does the refactoring use a working copy layer? */
122124
private final boolean layer;
123125

126+
private Map<IJavaProject, Collection<Entrypoint>> projectToEntryPoints;
127+
124128
private SearchEngine searchEngine = new SearchEngine();
125129

126130
/** The code generation settings, or <code>null</code> */
127131
private CodeGenerationSettings settings;
128132

133+
private Set<Stream> streamSet;
134+
129135
private Map<ITypeRoot, CompilationUnit> typeRootToCompilationUnitMap = new HashMap<>();
130136

131137
private Map<IType, ITypeHierarchy> typeToTypeHierarchyMap = new HashMap<>();
132138

133-
private IJavaProject[] javaProjects;
134-
135-
private Set<Stream> streamSet;
136-
137-
private Map<IJavaProject, Collection<Entrypoint>> projectToEntryPoints;
138-
139139
private boolean useImplicitEntrypoints = true;
140140

141141
public ConvertToParallelStreamRefactoringProcessor() throws JavaModelException {
142142
this(null, null, false, true, Optional.empty());
143143
}
144144

145+
public ConvertToParallelStreamRefactoringProcessor(final CodeGenerationSettings settings,
146+
Optional<IProgressMonitor> monitor) throws JavaModelException {
147+
this(null, settings, false, true, monitor);
148+
}
149+
145150
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
146151
final CodeGenerationSettings settings, boolean layer, boolean useImplicitEntrypoints,
147152
Optional<IProgressMonitor> monitor) throws JavaModelException {
@@ -155,22 +160,17 @@ public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
155160
}
156161
}
157162

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);
161167
}
162168

163169
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
164170
final CodeGenerationSettings settings, Optional<IProgressMonitor> monitor) throws JavaModelException {
165171
this(javaProjects, settings, false, true, monitor);
166172
}
167173

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-
174174
public ConvertToParallelStreamRefactoringProcessor(Optional<IProgressMonitor> monitor) throws JavaModelException {
175175
this(null, null, false, true, monitor);
176176
}
@@ -190,35 +190,33 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
190190
this.getJavaProjects().length * 1000);
191191
final RefactoringStatus status = new RefactoringStatus();
192192
StreamAnalyzer analyzer = new StreamAnalyzer(false, this.getUseImplicitEntrypoints());
193-
setStreamSet(analyzer.getStreamSet());
193+
this.setStreamSet(analyzer.getStreamSet());
194194

195195
for (IJavaProject jproj : this.getJavaProjects()) {
196196
IPackageFragmentRoot[] roots = jproj.getPackageFragmentRoots();
197197
for (IPackageFragmentRoot root : roots) {
198198
IJavaElement[] children = root.getChildren();
199-
for (IJavaElement child : children) {
199+
for (IJavaElement child : children)
200200
if (child.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
201201
IPackageFragment fragment = (IPackageFragment) child;
202202
ICompilationUnit[] units = fragment.getCompilationUnits();
203203
for (ICompilationUnit unit : units) {
204-
CompilationUnit compilationUnit = getCompilationUnit(unit, subMonitor.split(1));
204+
CompilationUnit compilationUnit = this.getCompilationUnit(unit, subMonitor.split(1));
205205
compilationUnit.accept(analyzer);
206206
}
207207
}
208-
}
209208
}
210209
}
211210

212211
// analyze and set entry points.
213-
projectToEntryPoints = analyzer.analyze();
214-
212+
this.projectToEntryPoints = analyzer.analyze();
213+
215214
// map empty set to unprocessed projects.
216215
for (IJavaProject project : this.getJavaProjects())
217216
this.projectToEntryPoints.computeIfAbsent(project, p -> Collections.emptySet());
218-
219217

220218
// get the status of each stream.
221-
RefactoringStatus collectedStatus = getStreamSet().stream().map(Stream::getStatus)
219+
RefactoringStatus collectedStatus = this.getStreamSet().stream().map(Stream::getStatus)
222220
.collect(() -> new RefactoringStatus(), (a, b) -> a.merge(b), (a, b) -> a.merge(b));
223221
status.merge(collectedStatus);
224222

@@ -245,14 +243,6 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
245243
}
246244
}
247245

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-
256246
@Override
257247
public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
258248
throws CoreException, OperationCanceledException {
@@ -288,12 +278,11 @@ private RefactoringStatus checkProjectCompliance(IJavaProject destinationProject
288278
}
289279

290280
private RefactoringStatus checkStructure(IMember member) throws JavaModelException {
291-
if (!member.isStructureKnown()) {
281+
if (!member.isStructureKnown())
292282
return RefactoringStatus.createErrorStatus(
293283
MessageFormat.format(Messages.CUContainsCompileErrors, getElementLabel(member, ALL_FULLY_QUALIFIED),
294284
getElementLabel(member.getCompilationUnit(), ALL_FULLY_QUALIFIED)),
295285
JavaStatusContext.create(member.getCompilationUnit()));
296-
}
297286
return new RefactoringStatus();
298287
}
299288

@@ -305,9 +294,9 @@ private RefactoringStatus checkWritabilitiy(IMember member, PreconditionFailure
305294
}
306295

307296
public void clearCaches() {
308-
getTypeToTypeHierarchyMap().clear();
309-
getCompilationUnitToCompilationUnitRewriteMap().clear();
310-
getTypeRootToCompilationUnitMap().clear();
297+
this.getTypeToTypeHierarchyMap().clear();
298+
this.getCompilationUnitToCompilationUnitRewriteMap().clear();
299+
this.getTypeRootToCompilationUnitMap().clear();
311300
}
312301

313302
@Override
@@ -322,8 +311,8 @@ public Change createChange(IProgressMonitor pm) throws CoreException, OperationC
322311
.filter(cu -> !manager.containsChangesIn(cu)).toArray(ICompilationUnit[]::new);
323312

324313
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),
327316
Optional.of(new SubProgressMonitor(pm, IProgressMonitor.UNKNOWN)));
328317
}
329318

@@ -335,7 +324,7 @@ public Change createChange(IProgressMonitor pm) throws CoreException, OperationC
335324
ConvertStreamToParallelRefactoringDescriptor descriptor = new ConvertStreamToParallelRefactoringDescriptor(
336325
null, "TODO", null, arguments, flags);
337326

338-
return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), manager.getAllChanges());
327+
return new DynamicValidationRefactoringChange(descriptor, this.getProcessorName(), manager.getAllChanges());
339328
} finally {
340329
pm.done();
341330
this.clearCaches();
@@ -395,22 +384,38 @@ public Object[] getElements() {
395384
return null;
396385
}
397386

387+
public Collection<Entrypoint> getEntryPoints(IJavaProject javaProject) {
388+
return this.projectToEntryPoints.get(javaProject);
389+
}
390+
398391
public TimeCollector getExcludedTimeCollector() {
399-
return excludedTimeCollector;
392+
return this.excludedTimeCollector;
400393
}
401394

402395
@Override
403396
public String getIdentifier() {
404397
return ConvertStreamToParallelRefactoringDescriptor.REFACTORING_ID;
405398
}
406399

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+
407408
@Override
408409
public String getProcessorName() {
409410
return Messages.Name;
410411
}
411412

412413
private SearchEngine getSearchEngine() {
413-
return searchEngine;
414+
return this.searchEngine;
415+
}
416+
417+
public Set<Stream> getStreamSet() {
418+
return this.streamSet;
414419
}
415420

416421
private ITypeHierarchy getTypeHierarchy(IType type, Optional<IProgressMonitor> monitor) throws JavaModelException {
@@ -428,12 +433,20 @@ private ITypeHierarchy getTypeHierarchy(IType type, Optional<IProgressMonitor> m
428433
}
429434
}
430435

436+
protected Map<ITypeRoot, CompilationUnit> getTypeRootToCompilationUnitMap() {
437+
return this.typeRootToCompilationUnitMap;
438+
}
439+
431440
protected Map<IType, ITypeHierarchy> getTypeToTypeHierarchyMap() {
432-
return typeToTypeHierarchyMap;
441+
return this.typeToTypeHierarchyMap;
433442
}
434443

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;
437450
}
438451

439452
@Override
@@ -467,23 +480,7 @@ private void manageCompilationUnit(final TextEditBasedChangeManager manager, Com
467480
manager.manage(rewrite.getCu(), change);
468481
}
469482

470-
protected IJavaProject[] getJavaProjects() {
471-
return javaProjects;
472-
}
473-
474-
public Set<Stream> getStreamSet() {
475-
return streamSet;
476-
}
477-
478483
protected void setStreamSet(Set<Stream> streamSet) {
479484
this.streamSet = streamSet;
480485
}
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-
}
489486
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
public class EvaluateConvertToParallelStreamRefactoringHandler extends AbstractHandler {
7575

7676
private static final boolean BUILD_WORKSPACE = false;
77+
private static final boolean FIND_IMPLICIT_ENTRYPOINTS_DEFAULT = true;
78+
private static final String FIND_IMPLICIT_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitEntrypoints";
7779
private static final int LOGGING_LEVEL = IStatus.INFO;
7880
private static final boolean PERFORM_CHANGE_DEFAULT = false;
7981
private static final String PERFORM_CHANGE_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.performChange";
80-
private static final boolean FIND_IMPLICIT_ENTRYPOINTS_DEFAULT = true;
81-
private static final String FIND_IMPLICIT_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitEntrypoints";
8282

8383
private static String[] buildAttributeColumns(String attribute) {
8484
return new String[] { "subject", "stream", "start pos", "length", "method", "type FQN", attribute };
@@ -124,6 +124,11 @@ private static int getMethodLinesOfCode(IMethod method) {
124124
}
125125
}
126126

127+
private static Collection<Entrypoint> getProjectEntryPoints(IJavaProject javaProject,
128+
ConvertToParallelStreamRefactoringProcessor processor) {
129+
return processor.getEntryPoints(javaProject);
130+
}
131+
127132
private static int getProjectLinesOfCode(IJavaProject javaProject) {
128133
AbstractMetricSource metricSource = Dispatcher.getAbstractMetricSource(javaProject);
129134

@@ -449,11 +454,6 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
449454
return null;
450455
}
451456

452-
private static Collection<Entrypoint> getProjectEntryPoints(IJavaProject javaProject,
453-
ConvertToParallelStreamRefactoringProcessor processor) {
454-
return processor.getEntryPoints(javaProject);
455-
}
456-
457457
private Set<SearchMatch> findReferences(Set<? extends IJavaElement> elements) throws CoreException {
458458
Set<SearchMatch> ret = new HashSet<>();
459459
for (IJavaElement elem : elements)
@@ -470,15 +470,6 @@ public void acceptSearchMatch(SearchMatch match) throws CoreException {
470470
return ret;
471471
}
472472

473-
private boolean shouldPerformChange() {
474-
String performChangePropertyValue = System.getenv(PERFORM_CHANGE_PROPERTY_KEY);
475-
476-
if (performChangePropertyValue == null)
477-
return PERFORM_CHANGE_DEFAULT;
478-
else
479-
return Boolean.valueOf(performChangePropertyValue);
480-
}
481-
482473
private boolean shouldFindImplicitEntrypoints() {
483474
String findImplicitEntrypoits = System.getenv(FIND_IMPLICIT_ENTRYPOINTS_PROPERTY_KEY);
484475

@@ -487,4 +478,13 @@ private boolean shouldFindImplicitEntrypoints() {
487478
else
488479
return Boolean.valueOf(findImplicitEntrypoits);
489480
}
481+
482+
private boolean shouldPerformChange() {
483+
String performChangePropertyValue = System.getenv(PERFORM_CHANGE_PROPERTY_KEY);
484+
485+
if (performChangePropertyValue == null)
486+
return PERFORM_CHANGE_DEFAULT;
487+
else
488+
return Boolean.valueOf(performChangePropertyValue);
489+
}
490490
}

0 commit comments

Comments
 (0)