Skip to content

Commit 6a32928

Browse files
authored
Merge pull request #182 from ponder-lab/ctors
Ctors
2 parents 452e2ca + dd7a028 commit 6a32928

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ private String findStreamCreationMethod(TypeAbstraction typeAbstraction) {
9696
private String findStreamCreationMethod(IClass type) {
9797
Collection<com.ibm.wala.classLoader.IMethod> allMethods = type.getAllMethods();
9898
for (com.ibm.wala.classLoader.IMethod method : allMethods) {
99-
TypeReference returnType = method.getReturnType();
99+
TypeReference typeToCheck = Util.getEvaluationType(method);
100+
100101
// find the first one that returns a stream.
101-
if (Util.implementsBaseStream(returnType, this.getClassHierarchy()))
102+
if (Util.implementsBaseStream(typeToCheck, this.getClassHierarchy()))
102103
return method.getName().toString();
103104
}
104105

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ private static Collection<? extends InstanceKey> getAdditionalNecessaryReceivers
272272
// who's the caller?
273273
LOGGER.fine(() -> "Called method is: " + calledMethod);
274274

275-
TypeReference returnType = calledMethod.getReturnType();
276-
LOGGER.fine(() -> "Return type is: " + returnType);
275+
TypeReference evaluationType = Util.getEvaluationType(calledMethod);
276+
LOGGER.fine(() -> "Evaluation type is: " + evaluationType);
277277

278-
boolean implementsBaseStream = Util.implementsBaseStream(returnType, hierarchy);
278+
boolean implementsBaseStream = Util.implementsBaseStream(evaluationType, hierarchy);
279279
LOGGER.fine(() -> "Is it a stream? " + implementsBaseStream);
280280

281281
if (implementsBaseStream) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,4 +687,23 @@ private static boolean wouldOrderingBeConsistent(final Collection<TypeAbstractio
687687

688688
private Util() {
689689
}
690+
691+
/**
692+
* If it's a ctor, return the declaring class, otherwise, return the return
693+
* type.
694+
*
695+
* @param method
696+
* The {@link IMethod} in question.
697+
* @return The declaring class of target if target is a ctor and the return type
698+
* otherwise.
699+
*/
700+
public static TypeReference getEvaluationType(IMethod method) {
701+
// if it's a ctor.
702+
if (method.isInit())
703+
// then, use the declaring type.
704+
return method.getDeclaringClass().getReference();
705+
else // otherwise.
706+
// use the return type.
707+
return method.getReturnType();
708+
}
690709
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallString;
1515
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallStringContext;
1616
import com.ibm.wala.ipa.callgraph.propagation.cfa.nCFAContextSelector;
17+
import com.ibm.wala.types.TypeReference;
1718

1819
import edu.cuny.hunter.streamrefactoring.core.analysis.Util;
1920

@@ -126,7 +127,8 @@ protected Map<CallStringTriple, CallStringWithReceivers> getCallStringWithReceiv
126127
*/
127128
@Override
128129
protected int getLength(CGNode caller, CallSiteReference site, IMethod target) {
129-
boolean implementsBaseStream = Util.implementsBaseStream(target.getReturnType(), target.getClassHierarchy());
130+
TypeReference typeToCheck = Util.getEvaluationType(target);
131+
boolean implementsBaseStream = Util.implementsBaseStream(typeToCheck, target.getClassHierarchy());
130132

131133
if (implementsBaseStream)
132134
return CONTEXT_LENGTH_FOR_STREAMS;

0 commit comments

Comments
 (0)