Skip to content

Commit c6f436c

Browse files
committed
Workaround #80.
1 parent f5cdc46 commit c6f436c

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallString;
1212
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallStringContextSelector;
1313
import com.ibm.wala.ssa.SSAInvokeInstruction;
14+
import com.ibm.wala.types.MethodReference;
15+
import com.ibm.wala.types.TypeName;
1416
import com.ibm.wala.util.collections.Pair;
17+
import com.ibm.wala.util.strings.Atom;
1518

1619
public class Util {
1720

@@ -52,11 +55,28 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
5255
CallSiteReference[] callSiteRefs = callString.getCallSiteRefs();
5356

5457
// for each call site reference.
55-
for (CallSiteReference callSiteReference : callSiteRefs)
58+
for (CallSiteReference callSiteReference : callSiteRefs) {
59+
CallSiteReference instructionCallSite = instruction.getCallSite();
60+
5661
// if the call site reference equals the call site corresponding
5762
// to the creation instruction.
58-
if (callSiteReference.equals(instruction.getCallSite()))
63+
if (callSiteReference.equals(instructionCallSite))
5964
return true;
65+
// workaround #80.
66+
else if (callSiteReference.getProgramCounter() == instructionCallSite.getProgramCounter()) {
67+
// compare declared targets.
68+
MethodReference callSiteDeclaredTarget = callSiteReference.getDeclaredTarget();
69+
MethodReference instructionCallDeclaredTarget = instructionCallSite.getDeclaredTarget();
70+
71+
if (callSiteDeclaredTarget.getDeclaringClass().getName()
72+
.equals(instructionCallDeclaredTarget.getDeclaringClass().getName())
73+
&& callSiteDeclaredTarget.getDeclaringClass().getName()
74+
.equals(TypeName.string2TypeName("Ljava/util/Arrays"))
75+
&& callSiteDeclaredTarget.getName().equals(instructionCallDeclaredTarget.getName())
76+
&& callSiteDeclaredTarget.getName().equals(Atom.findOrCreateAsciiAtom("stream")))
77+
return true;
78+
}
79+
}
6080
}
6181
return false;
6282
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
class A {
88
@EntryPoint
99
void m() {
10-
Arrays.stream(new Object[1]);
10+
Arrays.stream(new Object[1]).count();
1111
}
1212
}

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,13 @@ public void testArraysAsList() throws Exception {
355355
}
356356

357357
/**
358-
* Fix https://github.com/ponder-lab/Java-8-Stream-Refactoring/issues/80.
359-
*
360-
* @throws Exception
358+
* Test #80.
361359
*/
362360
public void testArraysStream() throws Exception {
363-
// Should fail per #80.
364361
helper(new StreamAnalysisExpectedResult("Arrays.stream(new Object[1])",
365-
Collections.singleton(ExecutionMode.SEQUENTIAL), null, false, false, false, null, null, null,
366-
RefactoringStatus.ERROR, Collections.singleton(PreconditionFailure.CURRENTLY_NOT_HANDLED)));
362+
Collections.singleton(ExecutionMode.SEQUENTIAL), EnumSet.of(Ordering.ORDERED), false, false, false,
363+
EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL), PreconditionSuccess.P2,
364+
Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK, Collections.emptySet()));
367365
}
368366

369367
public void testBitSet() throws Exception {

0 commit comments

Comments
 (0)