Skip to content

Commit 25f026c

Browse files
authored
Merge pull request #123 from ponder-lab/issue_120
Fall back to ORDERED
2 parents 5bf1932 + 0afe344 commit 25f026c

File tree

4 files changed

+50
-45
lines changed

4 files changed

+50
-45
lines changed

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

+42-34
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,7 @@ public Stream(MethodInvocation streamCreation) throws ClassHierarchyException, I
188188
this.orderingInference = new OrderingInference(this.getClassHierarchy());
189189

190190
this.inferInitialExecution();
191-
192-
try {
193-
this.inferInitialOrdering();
194-
} catch (InconsistentPossibleOrderingException e) {
195-
LOGGER.log(Level.WARNING, "Exception caught while processing: " + streamCreation, e);
196-
addStatusEntry(PreconditionFailure.INCONSISTENT_POSSIBLE_STREAM_SOURCE_ORDERING,
197-
"Stream: " + streamCreation + " has inconsistent possible source orderings.");
198-
} catch (NoniterableException e) {
199-
LOGGER.log(Level.WARNING, "Exception caught while processing: " + streamCreation, e);
200-
addStatusEntry(PreconditionFailure.NON_ITERABLE_POSSIBLE_STREAM_SOURCE,
201-
"Stream: " + streamCreation + " has a non-iterable possible source.");
202-
} catch (NoninstantiableException e) {
203-
LOGGER.log(Level.WARNING, "Exception caught while processing: " + streamCreation, e);
204-
addStatusEntry(PreconditionFailure.NON_INSTANTIABLE_POSSIBLE_STREAM_SOURCE, "Stream: " + streamCreation
205-
+ " has a non-instantiable possible source with type: " + e.getSourceType() + ".");
206-
} catch (CannotExtractSpliteratorException e) {
207-
LOGGER.log(Level.WARNING, "Exception caught while processing: " + streamCreation, e);
208-
addStatusEntry(PreconditionFailure.NON_DETERMINABLE_STREAM_SOURCE_ORDERING,
209-
"Cannot extract spliterator from type: " + e.getFromType() + " for stream: " + streamCreation
210-
+ ".");
211-
}
191+
this.inferInitialOrdering();
212192

213193
try {
214194
// start the state machine.
@@ -468,7 +448,7 @@ public TypeDeclaration getEnclosingTypeDeclaration() {
468448
return enclosingTypeDeclaration;
469449
}
470450

471-
private TypeReference getEnclosingTypeReference() {
451+
public TypeReference getEnclosingTypeReference() {
472452
JDTIdentityMapper mapper = getJDTIdentifyMapper(getEnclosingTypeDeclaration());
473453
TypeReference ref = mapper.getTypeRef(getEnclosingTypeDeclaration().resolveBinding());
474454

@@ -572,10 +552,8 @@ private void inferInitialExecution() {
572552
this.setInitialExecutionMode(ExecutionMode.SEQUENTIAL);
573553
}
574554

575-
private void inferInitialOrdering()
576-
throws IOException, CoreException, ClassHierarchyException, InvalidClassFileException,
577-
InconsistentPossibleOrderingException, NoniterableException, NoninstantiableException,
578-
CannotExtractSpliteratorException, CallGraphBuilderCancelException, CancelException {
555+
private void inferInitialOrdering() throws IOException, CoreException, ClassHierarchyException,
556+
InvalidClassFileException, CallGraphBuilderCancelException, CancelException {
579557
ITypeBinding expressionTypeBinding = this.getCreation().getExpression().resolveTypeBinding();
580558
String expressionTypeQualifiedName = expressionTypeBinding.getErasure().getQualifiedName();
581559
IMethodBinding calledMethodBinding = this.getCreation().resolveMethodBinding();
@@ -604,19 +582,42 @@ private void inferInitialOrdering()
604582
node = this.getEnclosingMethodNode();
605583
} catch (NoEnclosingMethodNodeFoundException e) {
606584
LOGGER.log(Level.WARNING, "Can't find enclosing method node for " + this.getCreation()
607-
+ ". Falling back to " + Ordering.ORDERED, e);
585+
+ ". Falling back to: " + Ordering.ORDERED + ".", e);
608586
this.setInitialOrdering(Ordering.ORDERED);
609587
return;
610588
}
611589

612-
Collection<TypeAbstraction> possibleTypes = getPossibleTypesInterprocedurally(node, valueNumber,
613-
this.getAnalysisEngine().getHeapGraph().getHeapModel(),
614-
this.getAnalysisEngine().getPointerAnalysis(), this, LOGGER);
590+
Collection<TypeAbstraction> possibleTypes = null;
591+
IMethod calledMethod = null;
592+
Ordering ordering = null;
593+
try {
594+
possibleTypes = getPossibleTypesInterprocedurally(node, valueNumber,
595+
this.getAnalysisEngine().getHeapGraph().getHeapModel(),
596+
this.getAnalysisEngine().getPointerAnalysis(), this, LOGGER);
615597

616-
// Possible types: check each one.
617-
IMethod calledMethod = (IMethod) calledMethodBinding.getJavaElement();
598+
// Possible types: check each one.
599+
calledMethod = (IMethod) calledMethodBinding.getJavaElement();
618600

619-
Ordering ordering = this.getOrderingInference().inferOrdering(possibleTypes, calledMethod);
601+
ordering = this.getOrderingInference().inferOrdering(possibleTypes, calledMethod);
602+
} catch (NoniterableException e) {
603+
LOGGER.log(Level.WARNING, "Stream: " + this.getCreation()
604+
+ " has a non-iterable possible source. Falling back to: " + Ordering.ORDERED + ".", e);
605+
ordering = Ordering.ORDERED;
606+
} catch (NoninstantiableException e) {
607+
LOGGER.log(Level.WARNING,
608+
"Stream: " + this.getCreation() + " has a non-instantiable possible source with type: "
609+
+ e.getSourceType() + ". Falling back to: " + Ordering.ORDERED + ".",
610+
e);
611+
ordering = Ordering.ORDERED;
612+
} catch (CannotExtractSpliteratorException e) {
613+
LOGGER.log(Level.WARNING, "Cannot extract spliterator from type: " + e.getFromType() + " for stream: "
614+
+ this.getCreation() + ". Falling back to: " + Ordering.ORDERED + ".", e);
615+
ordering = Ordering.ORDERED;
616+
} catch (InconsistentPossibleOrderingException e) {
617+
LOGGER.log(Level.WARNING, "Stream: " + this.getCreation()
618+
+ " has inconsistent possible source orderings. Falling back to: " + Ordering.ORDERED + ".", e);
619+
ordering = Ordering.ORDERED;
620+
}
620621

621622
if (ordering == null) {
622623
ordering = Ordering.ORDERED;
@@ -656,6 +657,7 @@ protected CGNode getEnclosingMethodNode() throws IOException, CoreException, NoE
656657
* in the {@link CallGraph} are {@link FakeRootMethod}s.
657658
* @apiNote The may be an issue here related to #106.
658659
*/
660+
@SuppressWarnings("unused")
659661
private static boolean allFake(Set<CGNode> nodes, CallGraph callGraph) {
660662
// for each node.
661663
for (CGNode cgNode : nodes) {
@@ -787,7 +789,13 @@ protected void buildCallGraph() throws IOException, CoreException, CallGraphBuil
787789
// Doesn't make sense. Maybe we need to collect all enclosing
788790
// methods
789791
// and use those as entry points.
790-
getAnalysisEngine().buildSafeCallGraph(options);
792+
try {
793+
getAnalysisEngine().buildSafeCallGraph(options);
794+
} catch (IllegalStateException e) {
795+
LOGGER.log(Level.SEVERE, e, () -> "Exception encountered while building call graph for Stream: " + this
796+
+ " in project: " + this.getCreationJavaProject());
797+
throw e;
798+
}
791799
// TODO: Can I slice the graph so that only nodes relevant to the
792800
// instance in question are present?
793801

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/wala/EclipseProjectAnalysisEngine.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public IClassHierarchy buildClassHierarchy() {
126126
}
127127

128128
public CallGraph buildSafeCallGraph(AnalysisOptions options)
129-
throws IllegalArgumentException, CallGraphBuilderCancelException, CancelException {
129+
throws CallGraphBuilderCancelException, CancelException {
130130
LOGGER.entering(this.getClass().getName(), "buildSafeCallGraph", this.callGraphBuilder);
131131

132132
if (callGraphBuilder == null) {

edu.cuny.hunter.streamrefactoring.tests/resources/ConvertStreamToParallel/testDoubleStreamOf/in/A.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
public class A {
88
@EntryPoint
99
void m() {
10-
DoubleStream.of(1.111)
11-
.count();
10+
DoubleStream.of(1.111).count();
1211
}
1312
}

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
public class ConvertStreamToParallelRefactoringTest extends RefactoringTest {
5959

6060
/**
61-
* The name of the directory containing resources under the project
62-
* directory.
61+
* The name of the directory containing resources under the project directory.
6362
*/
6463
private static final String RESOURCE_PATH = "resources";
6564

@@ -223,10 +222,9 @@ private Path getAbsolutionPath(String fileName) {
223222
*
224223
* @see
225224
* org.eclipse.jdt.ui.tests.refactoring.RefactoringTest#getFileContents(java
226-
* .lang.String) Had to override this method because, since this plug-in is
227-
* a fragment (at least I think that this is the reason), it doesn't have an
228-
* activator and the bundle is resolving to the eclipse refactoring test
229-
* bundle.
225+
* .lang.String) Had to override this method because, since this plug-in is a
226+
* fragment (at least I think that this is the reason), it doesn't have an
227+
* activator and the bundle is resolving to the eclipse refactoring test bundle.
230228
*/
231229
@Override
232230
public String getFileContents(String fileName) throws IOException {
@@ -474,8 +472,8 @@ public void testCollectionFromParameter2() throws Exception {
474472
*/
475473
public void testCollectionFromParameter3() throws Exception {
476474
helper(new StreamAnalysisExpectedResult("h.parallelStream()", Collections.singleton(ExecutionMode.PARALLEL),
477-
Collections.singleton(Ordering.UNORDERED), false, true, false, null, null, null, RefactoringStatus.ERROR,
478-
EnumSet.of(PreconditionFailure.UNORDERED)));
475+
Collections.singleton(Ordering.UNORDERED), false, true, false, null, null, null,
476+
RefactoringStatus.ERROR, EnumSet.of(PreconditionFailure.UNORDERED)));
479477
}
480478

481479
/**

0 commit comments

Comments
 (0)