Skip to content

Commit 705d7ca

Browse files
committed
2 parents 8513b20 + 4924a70 commit 705d7ca

File tree

7 files changed

+189
-94
lines changed

7 files changed

+189
-94
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ private PreconditionFailure(int code) {
3737
public int getCode() {
3838
return code;
3939
}
40+
41+
public static void main(String[] args) {
42+
System.out.println("code,name");
43+
for (PreconditionFailure failure : PreconditionFailure.values())
44+
System.out.println(failure.getCode() + "," + failure);
45+
}
4046
}

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

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.io.IOException;
66
import java.util.Collection;
7+
import java.util.HashMap;
78
import java.util.HashSet;
89
import java.util.Iterator;
910
import java.util.Map;
@@ -23,6 +24,7 @@
2324
import com.ibm.safe.internal.exceptions.PropertiesException;
2425
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
2526
import com.ibm.wala.ipa.callgraph.AnalysisOptions.ReflectionOptions;
27+
import com.ibm.wala.ipa.callgraph.CallGraph;
2628
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
2729
import com.ibm.wala.ipa.callgraph.Entrypoint;
2830
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
@@ -46,7 +48,12 @@ private static void addImplicitEntryPoints(Collection<Entrypoint> target, Iterab
4648
LOGGER.info(() -> "Adding implicit entry point: " + implicitEntryPoint);
4749
}
4850

49-
private Set<EclipseProjectAnalysisEngine<InstanceKey>> enginesWithBuiltCallGraphs = new HashSet<>();
51+
/**
52+
* Map from {@link EclipseProjectAnalysisEngine}s that have their
53+
* {@link CallGraph}s built to the {@link Entrypoint}s that were used to build
54+
* the graph.
55+
*/
56+
private Map<EclipseProjectAnalysisEngine<InstanceKey>, Collection<Entrypoint>> enginesWithBuiltCallGraphsToEntrypointsUsed = new HashMap<>();
5057

5158
private boolean findImplicitEntryPoints = true;
5259

@@ -72,7 +79,14 @@ public StreamAnalyzer(boolean visitDocTags, boolean findImplicitEntryPoints, boo
7279
this.findImplicitTestEntryPoints = findImplicitTestEntryPoints;
7380
}
7481

75-
public void analyze() throws CoreException {
82+
/**
83+
* Analyzes this {@link StreamAnalyzer}'s streams.
84+
*
85+
* @return {@link Map} of project's analyzed along with the entry points used.
86+
*/
87+
public Map<IJavaProject, Collection<Entrypoint>> analyze() throws CoreException {
88+
Map<IJavaProject, Collection<Entrypoint>> ret = new HashMap<>();
89+
7690
// collect the projects to be analyzed.
7791
Map<IJavaProject, Set<Stream>> projectToStreams = this.getStreamSet().stream().filter(s -> s.getStatus().isOK())
7892
.collect(Collectors.groupingBy(Stream::getCreationJavaProject, Collectors.toSet()));
@@ -90,21 +104,24 @@ public void analyze() throws CoreException {
90104
}
91105

92106
// build the call graph for the project.
107+
Collection<Entrypoint> entryPoints = null;
93108
try {
94-
this.buildCallGraph(engine);
95-
} catch (NoEntryPointException e) {
96-
LOGGER.log(Level.WARNING,
97-
"No entry point exception caught while processing: " + engine.getProject().getElementName(), e);
109+
entryPoints = this.buildCallGraph(engine);
110+
} catch (IOException | CoreException | CancelException e) {
111+
LOGGER.log(Level.SEVERE,
112+
"Exception encountered while building call graph for: " + project.getElementName() + ".", e);
113+
throw new RuntimeException(e);
114+
}
115+
116+
// save the entry points.
117+
ret.put(project, entryPoints);
98118

119+
if (entryPoints.isEmpty()) {
99120
// add a status entry for each stream in the project
100121
for (Stream stream : projectToStreams.get(project))
101122
stream.addStatusEntry(PreconditionFailure.NO_ENTRY_POINT,
102123
"Project: " + engine.getProject().getElementName() + " has no entry points.");
103-
return;
104-
} catch (IOException | CoreException | CancelException e) {
105-
LOGGER.log(Level.SEVERE,
106-
"Exception encountered while building call graph for: " + project.getElementName() + ".", e);
107-
throw new RuntimeException(e);
124+
return ret;
108125
}
109126

110127
OrderingInference orderingInference = new OrderingInference(engine.getClassHierarchy());
@@ -147,12 +164,23 @@ public void analyze() throws CoreException {
147164
.collect(Collectors.toSet()))
148165
stream.check();
149166
} // end for each stream.
167+
168+
return ret;
150169
}
151170

152-
protected void buildCallGraph(EclipseProjectAnalysisEngine<InstanceKey> engine)
153-
throws IOException, CoreException, CallGraphBuilderCancelException, CancelException, NoEntryPointException {
171+
/**
172+
* Builds the call graph that is part of the
173+
* {@link EclipseProjectAnalysisEngine}.
174+
*
175+
* @param engine
176+
* The EclipseProjectAnalysisEngine for which to build the call
177+
* graph.
178+
* @return The {@link Entrypoint}s used in building the {@link CallGraph}.
179+
*/
180+
protected Collection<Entrypoint> buildCallGraph(EclipseProjectAnalysisEngine<InstanceKey> engine)
181+
throws IOException, CoreException, CallGraphBuilderCancelException, CancelException {
154182
// if we haven't built the call graph yet.
155-
if (!this.enginesWithBuiltCallGraphs.contains(engine)) {
183+
if (!this.enginesWithBuiltCallGraphsToEntrypointsUsed.keySet().contains(engine)) {
156184
// find explicit entry points.
157185
Set<Entrypoint> entryPoints = Util.findEntryPoints(engine.getClassHierarchy());
158186
entryPoints.forEach(ep -> LOGGER.info(() -> "Adding explicit entry point: " + ep));
@@ -175,8 +203,7 @@ protected void buildCallGraph(EclipseProjectAnalysisEngine<InstanceKey> engine)
175203
}
176204

177205
if (entryPoints.isEmpty())
178-
throw new NoEntryPointException(
179-
"Project: " + engine.getProject().getElementName() + " has no entry points.");
206+
LOGGER.warning(() -> "Project: " + engine.getProject().getElementName() + " has no entry points.");
180207

181208
// set options.
182209
AnalysisOptions options = engine.getDefaultOptions(entryPoints);
@@ -193,8 +220,9 @@ protected void buildCallGraph(EclipseProjectAnalysisEngine<InstanceKey> engine)
193220
}
194221
// TODO: Can I slice the graph so that only nodes relevant to the
195222
// instance in question are present?
196-
this.enginesWithBuiltCallGraphs.add(engine);
223+
this.enginesWithBuiltCallGraphsToEntrypointsUsed.put(engine, entryPoints);
197224
}
225+
return this.enginesWithBuiltCallGraphsToEntrypointsUsed.get(engine);
198226
}
199227

200228
public Set<Stream> getStreamSet() {

0 commit comments

Comments
 (0)