Skip to content

Commit d584ae2

Browse files
committed
Clean up.
1 parent 6a32928 commit d584ae2

File tree

2 files changed

+73
-44
lines changed

2 files changed

+73
-44
lines changed

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

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class StreamAnalyzer extends ASTVisitor {
4848

4949
private static final Logger LOGGER = Logger.getLogger(LoggerNames.LOGGER_NAME);
5050

51-
private static final String ENTRY_POINT_FILE = "entry_points.txt";
51+
private static final String ENTRY_POINT_FILENAME = "entry_points.txt";
5252

5353
private static void addImplicitEntryPoints(Collection<Entrypoint> target, Iterable<Entrypoint> source) {
5454
for (Entrypoint implicitEntryPoint : source)
@@ -189,15 +189,20 @@ public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException
189189
* graph.
190190
* @return The {@link Entrypoint}s used in building the {@link CallGraph}.
191191
*/
192-
protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<InstanceKey> engine) throws IOException, CoreException, CallGraphBuilderCancelException, CancelException {
192+
protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<InstanceKey> engine)
193+
throws IOException, CoreException, CallGraphBuilderCancelException, CancelException {
193194
// if we haven't built the call graph yet.
194195
if (!this.enginesWithBuiltCallGraphsToEntrypointsUsed.keySet().contains(engine)) {
195-
196196
Set<Entrypoint> entryPoints;
197+
197198
// find the entry_points.txt in the project directory
198-
File entryPointFile = getEntryPointsFile(engine.getProject().getResource().getLocation(), ENTRY_POINT_FILE);
199+
File entryPointFile = getEntryPointsFile(engine.getProject().getResource().getLocation(),
200+
ENTRY_POINT_FILENAME);
201+
202+
// if the file was found,
199203
if (entryPointFile != null) {
200-
// find explicit entry points from entry_points.txt
204+
// find explicit entry points from entry_points.txt. Ignore the explicit
205+
// (annotation-based) entry points.
201206
entryPoints = findEntryPointsFromFile(engine.getClassHierarchy(), entryPointFile);
202207
entryPoints.forEach(ep -> LOGGER.info(() -> "Adding explicit entry point from file: " + ep));
203208
} else {
@@ -206,7 +211,7 @@ protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<Ins
206211
entryPoints.forEach(ep -> LOGGER.info(() -> "Adding explicit entry point: " + ep));
207212
}
208213

209-
if (this.findImplicitEntryPoints) {
214+
if (this.shouldFindImplicitEntryPoints()) {
210215
// also find implicit entry points.
211216
Iterable<Entrypoint> mainEntrypoints = makeMainEntrypoints(engine.getClassHierarchy().getScope(),
212217
engine.getClassHierarchy());
@@ -215,15 +220,15 @@ protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<Ins
215220
addImplicitEntryPoints(entryPoints, mainEntrypoints);
216221
}
217222

218-
if (this.findImplicitTestEntryPoints) {
223+
if (this.shouldFindImplicitTestEntryPoints()) {
219224
// try to find test entry points.
220225
Iterable<Entrypoint> jUnitEntryPoints = JUnitEntryPoints.make(engine.getClassHierarchy());
221226

222227
// add them as well.
223228
addImplicitEntryPoints(entryPoints, jUnitEntryPoints);
224229
}
225230

226-
if (this.findImplicitBenchmarkEntryPoints) {
231+
if (this.shouldFindImplicitBenchmarkEntryPoints()) {
227232
// try to find benchmark entry points.
228233
Set<Entrypoint> benchmarkEntryPoints = Util.findBenchmarkEntryPoints(engine.getClassHierarchy());
229234

@@ -279,20 +284,21 @@ private static Set<Entrypoint> findEntryPointsFromFile(IClassHierarchy classHier
279284
}
280285

281286
/**
282-
* Search entry_points.txt in project directory recursively
287+
* Search entry_points.txt in project directory recursively.
283288
*
284-
* @param directory:
285-
* project directory
286-
* @param fileName:
287-
* the target file
288-
* @return null: the file does not exist / file: find the file
289+
* @param directory
290+
* Project directory.
291+
* @param fileName
292+
* The target file.
293+
* @return null if the file does not exist and file if we found the file.
289294
*/
290295
private static File getEntryPointsFile(IPath directory, String fileName) {
291-
// If file does not exist, find the file in upper level
296+
// If file does not exist, find the file in upper level.
292297
Path directoryPath = Paths.get(directory.toString());
298+
293299
File file;
294300
do {
295-
file = new File(directoryPath.resolve(ENTRY_POINT_FILE).toString());
301+
file = new File(directoryPath.resolve(ENTRY_POINT_FILENAME).toString());
296302
directoryPath = directoryPath.getParent();
297303
} while (!file.exists() && directoryPath != null);
298304

@@ -310,10 +316,26 @@ public void setFindImplicitEntryPoints(boolean findImplicitEntryPoints) {
310316
this.findImplicitEntryPoints = findImplicitEntryPoints;
311317
}
312318

319+
public boolean shouldFindImplicitEntryPoints() {
320+
return findImplicitEntryPoints;
321+
}
322+
313323
public void setFindImplicitTestEntryPoints(boolean findImplicitTestEntryPoints) {
314324
this.findImplicitTestEntryPoints = findImplicitTestEntryPoints;
315325
}
316326

327+
public boolean shouldFindImplicitTestEntryPoints() {
328+
return findImplicitTestEntryPoints;
329+
}
330+
331+
public boolean shouldFindImplicitBenchmarkEntryPoints() {
332+
return findImplicitBenchmarkEntryPoints;
333+
}
334+
335+
public void setFindImplicitBenchmarkEntryPoints(boolean findImplicitBenchmarkEntryPoints) {
336+
this.findImplicitBenchmarkEntryPoints = findImplicitBenchmarkEntryPoints;
337+
}
338+
317339
/**
318340
* @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
319341
*/

edu.cuny.hunter.streamrefactoring.tests/test cases/edu/cuny/hunter/streamrefactoring/ui/tests/ConvertStreamToParallelRefactoringTest.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
*
3-
*/
41
package edu.cuny.hunter.streamrefactoring.ui.tests;
52

63
import java.io.File;
@@ -75,7 +72,7 @@ public class ConvertStreamToParallelRefactoringTest extends RefactoringTest {
7572

7673
private static final int RETRY_DELAY = 1000;
7774

78-
private static final String ENTRY_POINT_FILE = "entry_points.txt";
75+
private static final String ENTRY_POINT_FILENAME = "entry_points.txt";
7976

8077
static {
8178
LOGGER.setLevel(Level.FINER);
@@ -133,49 +130,61 @@ public static Test setUpTest(Test test) {
133130
}
134131

135132
/**
136-
* @return Path: an absolute path of entry_points.txt in the project directory
133+
* @return an absolute path of entry_points.txt in the project directory.
137134
*/
138-
private Path getAbsoluteProjectPath() {
139-
return this.getAbsolutePath(this.getTestPath() + this.getName()).resolve(ENTRY_POINT_FILE);
135+
private Path getEntryPointFileProjectSourcePath() {
136+
return getAbsolutePath(this.getTestPath() + this.getName()).resolve(ENTRY_POINT_FILENAME);
140137
}
141138

142139
/**
143-
* @return Path: an absolute path of entry_points.txt in the project directory
144-
* of junit workspace
140+
* @return The {@link Path} of where the entry points file should be copied to
141+
* for the current project under test.
145142
*/
146-
private Path getDestinationProjectPath() {
147-
return getDestinationPath(this.getPackageP().getJavaProject());
143+
private Path getEntryPointFileProjectDestinationPath() {
144+
return getEntryPointFileDestinationPath(this.getPackageP().getJavaProject());
148145
}
149146

150147
/**
151-
* @return Path: an absolute path of entry_points.txt in the junit workspace
148+
* @return The {@link Path} of where the entry_points.txt file should be copied
149+
* to in the junit workspace.
152150
*/
153-
private Path getDestinationWorkSpacePath() {
154-
return getDestinationPath(this.getPackageP().getJavaProject().getParent());
151+
@SuppressWarnings("unused")
152+
private Path getDestinationWorkspacePath() {
153+
return getEntryPointFileDestinationPath(this.getPackageP().getJavaProject().getParent());
155154
}
156155

157-
private Path getDestinationPath(IJavaElement element) {
158-
return Paths.get(element.getResource().getLocation().toString() + File.separator + ENTRY_POINT_FILE);
156+
/**
157+
* Returns the path of where the entry points file should be copied relative to
158+
* the given {@link IJavaElement}.
159+
*
160+
* @param element
161+
* The {@link IJavaElement} in question.
162+
* @return The {@link Path} where the entry points file should be copied
163+
* relative to the given {@link IJavaElement}.
164+
*/
165+
private static Path getEntryPointFileDestinationPath(IJavaElement element) {
166+
return Paths.get(element.getResource().getLocation().toString() + File.separator + ENTRY_POINT_FILENAME);
159167
}
160168

161169
@Override
162170
protected void setUp() throws Exception {
163171
super.setUp();
164172

165173
// this is the source path.
166-
Path absoluteProjectPath = getAbsoluteProjectPath();
174+
Path entryPointFileProjectSourcePath = getEntryPointFileProjectSourcePath();
175+
Path entryPointFileProjectDestinationPath = getEntryPointFileProjectDestinationPath();
167176

168177
// TODO: we also need to copy entry_points.txt to workspace directory here
169178
// something like copyEntryPointFile(absoluteProjectPath,
170179
// getDestinationWorkSpacePath())
171-
if (copyEntryPointFile(absoluteProjectPath, getDestinationProjectPath()))
172-
LOGGER.info(() -> "Copy entry_points.txt successfully");
180+
if (copyEntryPointFile(entryPointFileProjectSourcePath, entryPointFileProjectDestinationPath))
181+
LOGGER.info("Copied " + ENTRY_POINT_FILENAME + " successfully.");
173182
else
174-
LOGGER.info(() -> "entry_points.txt does not exist");
183+
LOGGER.info(ENTRY_POINT_FILENAME + " does not exist.");
175184
}
176185

177186
/**
178-
* Copy entry_points.txt from cuurent directory to the corresponding directory
187+
* Copy entry_points.txt from current directory to the corresponding directory
179188
* in junit-workspace
180189
*
181190
* @return true: copy successfully / false: the source file does not exist
@@ -418,7 +427,7 @@ protected void tearDown() throws Exception {
418427
final boolean pExists = getPackageP().exists();
419428

420429
// this is destination path.
421-
Path destinationProjectPath = getDestinationProjectPath();
430+
Path destinationProjectPath = getEntryPointFileProjectDestinationPath();
422431

423432
if (getEntryPointFile(destinationProjectPath) != null)
424433
Files.delete(destinationProjectPath);
@@ -809,8 +818,7 @@ public void testWithoutEntryPoint() throws Exception {
809818
}
810819

811820
/**
812-
* Test #172.
813-
* This is a control group for testing entry point file.
821+
* Test #172. This is a control group for testing entry point file.
814822
*/
815823
public void testEntryPointFile() throws Exception {
816824
helper(new StreamAnalysisExpectedResult("h1.stream()", Collections.singleton(ExecutionMode.SEQUENTIAL),
@@ -820,8 +828,7 @@ public void testEntryPointFile() throws Exception {
820828
}
821829

822830
/**
823-
* Test #172.
824-
* Test correct entry point file.
831+
* Test #172. Test correct entry point file.
825832
*/
826833
public void testEntryPointFile1() throws Exception {
827834
helper(new StreamAnalysisExpectedResult("h1.stream()", Collections.singleton(ExecutionMode.SEQUENTIAL),
@@ -831,8 +838,8 @@ public void testEntryPointFile1() throws Exception {
831838
}
832839

833840
/**
834-
* Test #172.
835-
* Test entry point file which is not corresponding to the source code.
841+
* Test #172. Test entry point file which is not corresponding to the source
842+
* code.
836843
*/
837844
public void testEntryPointFile2() throws Exception {
838845
helper(new StreamAnalysisExpectedResult("h1.stream()", null, null, false, false, false, null, null, null,

0 commit comments

Comments
 (0)