Skip to content

Commit

Permalink
Workaround #80.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed Dec 21, 2017
1 parent f5cdc46 commit c6f436c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallString;
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallStringContextSelector;
import com.ibm.wala.ssa.SSAInvokeInstruction;
import com.ibm.wala.types.MethodReference;
import com.ibm.wala.types.TypeName;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.strings.Atom;

public class Util {

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

// for each call site reference.
for (CallSiteReference callSiteReference : callSiteRefs)
for (CallSiteReference callSiteReference : callSiteRefs) {
CallSiteReference instructionCallSite = instruction.getCallSite();

// if the call site reference equals the call site corresponding
// to the creation instruction.
if (callSiteReference.equals(instruction.getCallSite()))
if (callSiteReference.equals(instructionCallSite))
return true;
// workaround #80.
else if (callSiteReference.getProgramCounter() == instructionCallSite.getProgramCounter()) {
// compare declared targets.
MethodReference callSiteDeclaredTarget = callSiteReference.getDeclaredTarget();
MethodReference instructionCallDeclaredTarget = instructionCallSite.getDeclaredTarget();

if (callSiteDeclaredTarget.getDeclaringClass().getName()
.equals(instructionCallDeclaredTarget.getDeclaringClass().getName())
&& callSiteDeclaredTarget.getDeclaringClass().getName()
.equals(TypeName.string2TypeName("Ljava/util/Arrays"))
&& callSiteDeclaredTarget.getName().equals(instructionCallDeclaredTarget.getName())
&& callSiteDeclaredTarget.getName().equals(Atom.findOrCreateAsciiAtom("stream")))
return true;
}
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
class A {
@EntryPoint
void m() {
Arrays.stream(new Object[1]);
Arrays.stream(new Object[1]).count();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,13 @@ public void testArraysAsList() throws Exception {
}

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

public void testBitSet() throws Exception {
Expand Down

0 comments on commit c6f436c

Please sign in to comment.