1
1
package edu .cuny .hunter .streamrefactoring .core .safe ;
2
2
3
3
import java .util .Iterator ;
4
+ import java .util .logging .Logger ;
4
5
5
6
import com .ibm .wala .classLoader .CallSiteReference ;
6
7
import com .ibm .wala .classLoader .IMethod ;
17
18
import com .ibm .wala .util .collections .Pair ;
18
19
import com .ibm .wala .util .strings .Atom ;
19
20
21
+ import edu .cuny .hunter .streamrefactoring .core .utils .LoggerNames ;
22
+
20
23
public class Util {
21
24
22
25
/**
@@ -35,6 +38,8 @@ public class Util {
35
38
private static final TypeName STREAM_SUPPORT_TYPE_NAME = TypeName
36
39
.string2TypeName ("Ljava/util/stream/StreamSupport" );
37
40
41
+ private static final Logger LOGGER = Logger .getLogger (LoggerNames .LOGGER_NAME );
42
+
38
43
/**
39
44
* True iff the given {@link InstanceKey} corresponds with the given
40
45
* {@link SSAInvokeInstruction} in the given {@link CallGraph}. In other words,
@@ -56,6 +61,9 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
56
61
// graph.
57
62
Iterator <Pair <CGNode , NewSiteReference >> creationSites = instanceKey .getCreationSites (callGraph );
58
63
64
+ CallSiteReference instructionCallSite = instruction .getCallSite ();
65
+ LOGGER .fine ("instruction call site is: " + instructionCallSite );
66
+
59
67
// for each creation site.
60
68
while (creationSites .hasNext ()) {
61
69
Pair <CGNode , NewSiteReference > pair = creationSites .next ();
@@ -76,14 +84,19 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
76
84
// for each call site reference.
77
85
for (int i = 0 ; i < callSiteRefs .length ; i ++) {
78
86
CallSiteReference callSiteReference = callSiteRefs [i ];
87
+ LOGGER .fine ("Call site reference at " + i + " is: " + callSiteReference );
88
+
79
89
IMethod method = methods [i ];
80
- CallSiteReference instructionCallSite = instruction . getCallSite ( );
90
+ LOGGER . fine ( "Method at " + i + " is: " + method );
81
91
82
92
// if the call site reference equals the call site corresponding
83
93
// to the creation instruction.
84
94
if (callSiteReference .equals (instructionCallSite )
85
- && method .getReference ().getSignature ().equals (instructionEnclosingMethod .getSignature ()))
95
+ && method .getReference ().getSignature ().equals (instructionEnclosingMethod .getSignature ())) {
96
+ LOGGER .fine ("Match found. Instance key: " + instanceKey + " corresponds with instruction: "
97
+ + instruction + "." );
86
98
return true ;
99
+ }
87
100
// workaround #80.
88
101
else if (callSiteReference .getProgramCounter () == instructionCallSite .getProgramCounter ()) {
89
102
// compare declared targets.
@@ -103,6 +116,8 @@ else if (callSiteReference.getProgramCounter() == instructionCallSite.getProgram
103
116
}
104
117
}
105
118
}
119
+ LOGGER .fine ("No match found. Instance key: " + instanceKey + " does not correspond with instruction: "
120
+ + instruction + "." );
106
121
return false ;
107
122
}
108
123
0 commit comments