Skip to content

Commit 75751a7

Browse files
committed
Add option to discover Java FX entry points.
1 parent 7d223c1 commit 75751a7

File tree

5 files changed

+81
-18
lines changed

5 files changed

+81
-18
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ private static File getEntryPointsFile(IPath directory, String fileName) {
121121

122122
private boolean findImplicitEntryPoints = true;
123123

124+
private boolean findImplicitJavaFXEntryPoints;
125+
124126
private boolean findImplicitTestEntryPoints;
125127

126128
/**
@@ -148,10 +150,11 @@ public StreamAnalyzer(boolean visitDocTags, boolean findImplicitEntryPoints) {
148150
}
149151

150152
public StreamAnalyzer(boolean visitDocTags, boolean findImplicitEntryPoints, boolean findImplicitTestEntryPoints,
151-
boolean findImplicitBenchmarkEntryPoints) {
153+
boolean findImplicitBenchmarkEntryPoints, boolean findImplicitJavaFXEntryPoints) {
152154
this(visitDocTags, findImplicitEntryPoints);
153155
this.findImplicitTestEntryPoints = findImplicitTestEntryPoints;
154156
this.findImplicitBenchmarkEntryPoints = findImplicitBenchmarkEntryPoints;
157+
this.findImplicitJavaFXEntryPoints = findImplicitJavaFXEntryPoints;
155158
}
156159

157160
public StreamAnalyzer(boolean visitDocTags, int nForStreams) {
@@ -165,8 +168,10 @@ public StreamAnalyzer(boolean visitDocTags, int nForStreams, boolean findImplici
165168
}
166169

167170
public StreamAnalyzer(boolean visitDocTags, int nForStreams, boolean findImplicitEntryPoints,
168-
boolean findImplicitTestEntryPoints, boolean findImplicitBenchmarkEntryPoints) {
169-
this(visitDocTags, findImplicitEntryPoints, findImplicitTestEntryPoints, findImplicitBenchmarkEntryPoints);
171+
boolean findImplicitTestEntryPoints, boolean findImplicitBenchmarkEntryPoints,
172+
boolean findImplicitJavaFXEntryPoints) {
173+
this(visitDocTags, findImplicitEntryPoints, findImplicitTestEntryPoints, findImplicitBenchmarkEntryPoints,
174+
findImplicitJavaFXEntryPoints);
170175
this.nForStreams = nForStreams;
171176
}
172177

@@ -344,6 +349,14 @@ protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<Ins
344349
// add them as well.
345350
addImplicitEntryPoints(entryPoints, benchmarkEntryPoints);
346351
}
352+
353+
if (this.shouldFindImplicitJavaFXEntryPoints()) {
354+
// try to find benchmark entry points.
355+
Set<Entrypoint> benchmarkEntryPoints = Util.findJavaFXEntryPoints(engine.getClassHierarchy());
356+
357+
// add them as well.
358+
addImplicitEntryPoints(entryPoints, benchmarkEntryPoints);
359+
}
347360
}
348361

349362
if (entryPoints.isEmpty()) {
@@ -397,6 +410,10 @@ public void setFindImplicitEntryPoints(boolean findImplicitEntryPoints) {
397410
this.findImplicitEntryPoints = findImplicitEntryPoints;
398411
}
399412

413+
public void setFindImplicitJavaFXEntryPoints(boolean findImplicitJavaFXEntryPoints) {
414+
this.findImplicitJavaFXEntryPoints = findImplicitJavaFXEntryPoints;
415+
}
416+
400417
public void setFindImplicitTestEntryPoints(boolean findImplicitTestEntryPoints) {
401418
this.findImplicitTestEntryPoints = findImplicitTestEntryPoints;
402419
}
@@ -421,6 +438,10 @@ public boolean shouldFindImplicitEntryPoints() {
421438
return this.findImplicitEntryPoints;
422439
}
423440

441+
public boolean shouldFindImplicitJavaFXEntryPoints() {
442+
return this.findImplicitJavaFXEntryPoints;
443+
}
444+
424445
public boolean shouldFindImplicitTestEntryPoints() {
425446
return this.findImplicitTestEntryPoints;
426447
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ public boolean visit(MethodInvocation node) {
118118
private static final String BENCHMARK_ANNOTATION_NAME = "org.openjdk.jmh.annotations.Benchmark";
119119

120120
private static final String BENCHMARK_SETUP_ANNOTATION_NAME = "org.openjdk.jmh.annotations.Setup";
121+
121122
private static final String ENTRYPOINT_ANNOTATION_NAME = "edu.cuny.hunter.streamrefactoring.annotations.EntryPoint";
123+
124+
private static final String FXML_ANNOTATION_NAME = "javafx.fxml.FXML";
125+
122126
private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);
123127

124128
private static void addEntryPoint(Set<Entrypoint> result, final IMethod method, IClassHierarchy classHierarchy) {
@@ -319,6 +323,10 @@ public static int findIndexOfFirstClientMethod(IMethod[] methods) {
319323
return -1; // not found.
320324
}
321325

326+
public static Set<Entrypoint> findJavaFXEntryPoints(IClassHierarchy classHierarchy) {
327+
return findEntryPoints(classHierarchy, tn -> isFXML(tn));
328+
}
329+
322330
static Set<ITypeBinding> getAllInterfaces(ITypeBinding type) {
323331
Set<ITypeBinding> ret = new HashSet<>();
324332
ITypeBinding[] interfaces = type.getInterfaces();
@@ -648,6 +656,10 @@ private static boolean isEntryPointClass(TypeName typeName) {
648656
return AnalysisUtils.walaTypeNameToJavaName(typeName).equals(ENTRYPOINT_ANNOTATION_NAME);
649657
}
650658

659+
private static boolean isFXML(TypeName typeName) {
660+
return AnalysisUtils.walaTypeNameToJavaName(typeName).equals(FXML_ANNOTATION_NAME);
661+
}
662+
651663
public static boolean isIterable(IClass clazz) {
652664
return Util.isType(clazz, "java/lang", "Iterable");
653665
}

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,31 @@ public static void setLoggingLevel(int level) {
148148

149149
private boolean useImplicitEntrypoints = true;
150150

151+
private boolean useImplicitJavaFXEntrypoints = false;
152+
151153
private boolean useImplicitTestEntrypoints = false;
152154

153155
public ConvertToParallelStreamRefactoringProcessor() throws JavaModelException {
154-
this(null, null, false, true, false, false, Optional.empty());
156+
this(null, null, false, true, false, false, false, Optional.empty());
155157
}
156158

157159
public ConvertToParallelStreamRefactoringProcessor(final CodeGenerationSettings settings,
158160
Optional<IProgressMonitor> monitor) throws JavaModelException {
159-
this(null, settings, false, true, false, false, monitor);
161+
this(null, settings, false, true, false, false, false, monitor);
160162
}
161163

162164
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
163165
final CodeGenerationSettings settings, boolean layer, boolean useImplicitEntrypoints,
164166
boolean useImplicitTestEntrypoints, boolean useImplicitBenchmarkEntrypoints,
165-
Optional<IProgressMonitor> monitor) throws JavaModelException {
167+
boolean useImplicitJavaFXEntrypoints, Optional<IProgressMonitor> monitor) throws JavaModelException {
166168
try {
167169
this.javaProjects = javaProjects;
168170
this.settings = settings;
169171
this.layer = layer;
170172
this.useImplicitEntrypoints = useImplicitEntrypoints;
171173
this.useImplicitTestEntrypoints = useImplicitTestEntrypoints;
172174
this.useImplicitBenchmarkEntrypoints = useImplicitBenchmarkEntrypoints;
175+
this.useImplicitJavaFXEntrypoints = useImplicitJavaFXEntrypoints;
173176
} finally {
174177
monitor.ifPresent(IProgressMonitor::done);
175178
}
@@ -178,31 +181,31 @@ public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
178181
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
179182
final CodeGenerationSettings settings, boolean layer, int nForStreams, boolean useImplicitEntrypoints,
180183
boolean useImplicitTestEntrypoints, boolean useImplicitBenchmarkEntrypoints,
181-
Optional<IProgressMonitor> monitor) throws JavaModelException {
184+
boolean useImplicitJavaFXEntrypoints, Optional<IProgressMonitor> monitor) throws JavaModelException {
182185
this(javaProjects, settings, layer, useImplicitEntrypoints, useImplicitTestEntrypoints,
183-
useImplicitBenchmarkEntrypoints, monitor);
186+
useImplicitBenchmarkEntrypoints, useImplicitJavaFXEntrypoints, monitor);
184187
this.nForStreams = nForStreams;
185188
}
186189

187190
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
188191
final CodeGenerationSettings settings, boolean useImplicitJoinpoints, Optional<IProgressMonitor> monitor)
189192
throws JavaModelException {
190-
this(javaProjects, settings, false, useImplicitJoinpoints, false, false, monitor);
193+
this(javaProjects, settings, false, useImplicitJoinpoints, false, false, false, monitor);
191194
}
192195

193196
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
194197
final CodeGenerationSettings settings, int nForStreams, boolean useImplicitJoinpoints,
195198
Optional<IProgressMonitor> monitor) throws JavaModelException {
196-
this(javaProjects, settings, false, nForStreams, useImplicitJoinpoints, false, false, monitor);
199+
this(javaProjects, settings, false, nForStreams, useImplicitJoinpoints, false, false, false, monitor);
197200
}
198201

199202
public ConvertToParallelStreamRefactoringProcessor(IJavaProject[] javaProjects,
200203
final CodeGenerationSettings settings, Optional<IProgressMonitor> monitor) throws JavaModelException {
201-
this(javaProjects, settings, false, true, false, false, monitor);
204+
this(javaProjects, settings, false, true, false, false, false, monitor);
202205
}
203206

204207
public ConvertToParallelStreamRefactoringProcessor(Optional<IProgressMonitor> monitor) throws JavaModelException {
205-
this(null, null, false, true, false, false, monitor);
208+
this(null, null, false, true, false, false, false, monitor);
206209
}
207210

208211
private RefactoringStatus checkExistence(IMember member, PreconditionFailure failure) {
@@ -220,7 +223,8 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
220223
this.getJavaProjects().length * 1000);
221224
final RefactoringStatus status = new RefactoringStatus();
222225
StreamAnalyzer analyzer = new StreamAnalyzer(false, this.getNForStreams(), this.getUseImplicitEntrypoints(),
223-
this.getUseImplicitTestEntrypoints(), this.getUseImplicitBenchmarkEntrypoints());
226+
this.getUseImplicitTestEntrypoints(), this.getUseImplicitBenchmarkEntrypoints(),
227+
this.getUseImplicitJavaFXEntrypoints());
224228
this.setStreamSet(analyzer.getStreamSet());
225229

226230
for (IJavaProject jproj : this.getJavaProjects()) {
@@ -500,6 +504,10 @@ private boolean getUseImplicitEntrypoints() {
500504
return this.useImplicitEntrypoints;
501505
}
502506

507+
private boolean getUseImplicitJavaFXEntrypoints() {
508+
return this.useImplicitJavaFXEntrypoints;
509+
}
510+
503511
private boolean getUseImplicitTestEntrypoints() {
504512
return this.useImplicitTestEntrypoints;
505513
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/utils/Util.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,22 @@
3737
public final class Util {
3838
public static ConvertToParallelStreamRefactoringProcessor createConvertToParallelStreamRefactoringProcessor(
3939
IJavaProject[] projects, boolean useImplicitEntrypoints, boolean useImplicitTestEntrypoints,
40-
boolean useImplicitBenchmarkEntrypoints, Optional<IProgressMonitor> monitor) throws JavaModelException {
40+
boolean useImplicitBenchmarkEntrypoints, boolean useImplicitJavaFXEntrypoints,
41+
Optional<IProgressMonitor> monitor) throws JavaModelException {
4142
CodeGenerationSettings settings = JavaPreferencesSettings.getCodeGenerationSettings(projects[0]);
4243
ConvertToParallelStreamRefactoringProcessor processor = new ConvertToParallelStreamRefactoringProcessor(
4344
projects, settings, false, useImplicitEntrypoints, useImplicitTestEntrypoints,
44-
useImplicitBenchmarkEntrypoints, monitor);
45+
useImplicitBenchmarkEntrypoints, useImplicitJavaFXEntrypoints, monitor);
4546
return processor;
4647
}
4748

4849
public static ConvertToParallelStreamRefactoringProcessor createConvertToParallelStreamRefactoringProcessor(
4950
IJavaProject[] projects, int nForStreams, boolean useImplicitEntrypoints,
5051
boolean useImplicitTestEntrypoints, boolean useImplicitBenchmarkEntrypoints,
51-
Optional<IProgressMonitor> monitor) throws JavaModelException {
52+
boolean useImplicitJavaFXEntrypoints, Optional<IProgressMonitor> monitor) throws JavaModelException {
5253
ConvertToParallelStreamRefactoringProcessor processor = createConvertToParallelStreamRefactoringProcessor(
53-
projects, useImplicitEntrypoints, useImplicitTestEntrypoints, useImplicitBenchmarkEntrypoints, monitor);
54+
projects, useImplicitEntrypoints, useImplicitTestEntrypoints, useImplicitBenchmarkEntrypoints,
55+
useImplicitJavaFXEntrypoints, monitor);
5456
processor.setNForStreams(nForStreams);
5557
return processor;
5658
}

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,29 @@ public class EvaluateConvertToParallelStreamRefactoringHandler extends AbstractH
8888
private static final boolean FIND_IMPLICIT_BENCHMARK_ENTRYPOINTS_DEFAULT = false;
8989

9090
private static final String FIND_IMPLICIT_BENCHMARK_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitBenchmarkEntrypoints";
91+
9192
private static final boolean FIND_IMPLICIT_ENTRYPOINTS_DEFAULT = false;
9293

9394
private static final String FIND_IMPLICIT_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitEntrypoints";
95+
96+
private static final boolean FIND_IMPLICIT_JAVAFX_ENTRYPOINTS_DEFAULT = false;
97+
98+
private static final String FIND_IMPLICIT_JAVAFX_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitJavaFXEntrypoints";
99+
94100
private static final boolean FIND_IMPLICIT_TEST_ENTRYPOINTS_DEFAULT = false;
95101

96102
private static final String FIND_IMPLICIT_TEST_ENTRYPOINTS_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.findImplicitTestEntrypoints";
103+
97104
private static final Logger LOGGER = Logger.getLogger(LOGGER_NAME);
98105

99106
private static final int LOGGING_LEVEL = IStatus.INFO;
107+
100108
private static final int N_TO_USE_FOR_STREAMS_DEFAULT = 2;
101109

102110
private static final String N_TO_USE_FOR_STREAMS_PROPERTY_KEY = "nToUseForStreams";
103111

104112
private static final boolean PERFORM_CHANGE_DEFAULT = false;
113+
105114
private static final String PERFORM_CHANGE_PROPERTY_KEY = "edu.cuny.hunter.streamrefactoring.eval.performChange";
106115

107116
private static String[] buildAttributeColumns(String attribute) {
@@ -241,6 +250,15 @@ private static boolean shouldFindImplicitEntrypoints() {
241250
return Boolean.valueOf(findImplicitEntrypoits);
242251
}
243252

253+
private static boolean shouldFindImplicitJavaFXEntrypoints() {
254+
String findImplicitJavaFXEntrypoints = System.getenv(FIND_IMPLICIT_JAVAFX_ENTRYPOINTS_PROPERTY_KEY);
255+
256+
if (findImplicitJavaFXEntrypoints == null)
257+
return FIND_IMPLICIT_JAVAFX_ENTRYPOINTS_DEFAULT;
258+
else
259+
return Boolean.valueOf(findImplicitJavaFXEntrypoints);
260+
}
261+
244262
private static boolean shouldFindImplicitTestEntrypoints() {
245263
String findImplicitTestEntrypoints = System.getenv(FIND_IMPLICIT_TEST_ENTRYPOINTS_PROPERTY_KEY);
246264

@@ -341,6 +359,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
341359
boolean shouldFindImplicitEntrypoints = shouldFindImplicitEntrypoints();
342360
boolean shouldFindImplicitTestEntrypoints = shouldFindImplicitTestEntrypoints();
343361
boolean shouldFindImplicitBenchmarkEntrypoints = shouldFindImplicitBenchmarkEntrypoints();
362+
boolean shouldFindImplicitJavaFXEntrypoints = shouldFindImplicitJavaFXEntrypoints();
344363

345364
for (IJavaProject javaProject : javaProjects) {
346365
if (!javaProject.isStructureKnown())
@@ -360,7 +379,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
360379
resultsTimeCollector.start();
361380
processor = createConvertToParallelStreamRefactoringProcessor(new IJavaProject[] { javaProject },
362381
nToUseForStreams, shouldFindImplicitEntrypoints, shouldFindImplicitTestEntrypoints,
363-
shouldFindImplicitBenchmarkEntrypoints, Optional.of(monitor));
382+
shouldFindImplicitBenchmarkEntrypoints, shouldFindImplicitJavaFXEntrypoints,
383+
Optional.of(monitor));
364384
resultsTimeCollector.stop();
365385
ConvertToParallelStreamRefactoringProcessor.setLoggingLevel(LOGGING_LEVEL);
366386

0 commit comments

Comments
 (0)