Skip to content

Commit 0afe344

Browse files
committed
Fall back to ORDERED for initial ordering in case of a problem.
1 parent 49f9d15 commit 0afe344

File tree

1 file changed

+33
-32
lines changed
  • edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis

1 file changed

+33
-32
lines changed

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

+33-32
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.
@@ -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();
@@ -609,14 +587,37 @@ private void inferInitialOrdering()
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;
@@ -789,7 +790,7 @@ protected void buildCallGraph() throws IOException, CoreException, CallGraphBuil
789790
// methods
790791
// and use those as entry points.
791792
try {
792-
getAnalysisEngine().buildSafeCallGraph(options);
793+
getAnalysisEngine().buildSafeCallGraph(options);
793794
} catch (IllegalStateException e) {
794795
LOGGER.log(Level.SEVERE, e, () -> "Exception encountered while building call graph for Stream: " + this
795796
+ " in project: " + this.getCreationJavaProject());

0 commit comments

Comments
 (0)