@@ -68,7 +68,7 @@ public static AnalysisResult writeAnalysis(JSONWriter jwriter, Iterable<? extend
6868 }
6969 analysedMethods .add (methodToAnalyse );
7070
71- jwriter .value (getSignatureJSONArray (methodToAnalyse , cg ));
71+ jwriter .value (getSignatureJSONArray (methodToAnalyse , cg , pathToClassFiles ));
7272
7373 Iterator <Edge > edgesOut = cg .edgesOutOf (methodToAnalyse );
7474 while (edgesOut .hasNext ()) {
@@ -106,7 +106,7 @@ public static AnalysisResult writeAnalysis(JSONWriter jwriter, Iterable<? extend
106106 return new AnalysisResult (phantoms , badPhantoms );
107107 }
108108
109- private static JSONArray getSignatureJSONArray (SootMethod methodToAnalyse , CallGraph cg ) {
109+ private static JSONArray getSignatureJSONArray (SootMethod methodToAnalyse , CallGraph cg , Iterable <? extends Path > pathToClassFiles ) {
110110 TargetSignature targetSignature = getFormattedTargetSignature (methodToAnalyse );
111111 JSONArray callee = new JSONArray ();
112112 callee .put (targetSignature .getMethod ());
@@ -123,21 +123,30 @@ private static JSONArray getSignatureJSONArray(SootMethod methodToAnalyse, CallG
123123 Edge e = edgesInto .next ();
124124 MethodOrMethodContext source = e .getSrc ();
125125 SootMethod sourceMethod = source instanceof MethodContext ? source .method () : (SootMethod ) source ;
126- SourceSignature sourceSignature = getFormattedSourceSignature (sourceMethod , e .srcStmt () == null ? -1 : e .srcStmt ().getJavaSourceStartLineNumber ());
126+ SourceSignature sourceSignature = getFormattedSourceSignature (
127+ sourceMethod ,
128+ e .srcStmt () == null ? -1 : e .srcStmt ().getJavaSourceStartLineNumber (),
129+ pathToClassFiles
130+ );
127131 JSONArray caller = new JSONArray ();
128132 caller .put (sourceSignature .getMethod ());
129133 caller .put (sourceSignature .getLineNumber ());
134+ caller .put (sourceSignature .getFileName ());
130135 callers .put (caller );
131136 }
132137 callee .put (callers );
133138
134139 return callee ;
135140 }
136141
137- private static SourceSignature getFormattedSourceSignature (SootMethod method , int lineNumber ) {
142+ private static SourceSignature getFormattedSourceSignature (SootMethod method , int lineNumber , Iterable <? extends Path > pathToClassFiles ) {
138143 return method == null
139- ? new SourceSignature ("-" , -1 )
140- : new SourceSignature (getSignatureString (method ), lineNumber );
144+ ? new SourceSignature ("-" , -1 , "-" )
145+ : new SourceSignature (
146+ getSignatureString (method ),
147+ lineNumber ,
148+ getProbableSourceName (method , pathToClassFiles )
149+ );
141150 }
142151
143152 private static TargetSignature getFormattedTargetSignature (SootMethod method ) {
@@ -169,6 +178,26 @@ private static String getSignatureString(SootMethod method) {
169178 return sb .toString ();
170179 }
171180
181+ private static String getModuleString (SootMethod method ) {
182+ StringBuilder sb = new StringBuilder ();
183+ String classString = method .getDeclaringClass ().toString ();
184+ boolean foundDot = false ;
185+ for (int i = 0 ; i < classString .length (); i ++) {
186+ char c = classString .charAt (i );
187+ if (c != '.' ) {
188+ sb .append (c );
189+ } else {
190+ foundDot = true ;
191+ break ;
192+ }
193+ }
194+ if (!foundDot ) {
195+ return "" ;
196+ }
197+ return sb .toString ();
198+ }
199+
200+
172201 private static String getProbableName (SootClass c ) {
173202 if (c .isJavaLibraryClass ()) {
174203 return "-" ;
@@ -183,6 +212,20 @@ private static String getProbableName(SootClass c) {
183212 return className ;
184213 }
185214
215+ private static String getProbableSourceName (SootMethod method , Iterable <? extends Path > pathToClassFiles ) {
216+ String moduleName = getModuleString (method );
217+ String onlyDeclaringClassName = method .getDeclaringClass ().getName ().replaceFirst (moduleName + "." , "/" );
218+ if (moduleName .length () == 0 ) {
219+ return "<unknown>" ;
220+ }
221+ for (Path path : pathToClassFiles ) {
222+ if (path .toString ().endsWith (moduleName )) {
223+ return path .toString () + onlyDeclaringClassName + ".java" ;
224+ }
225+ }
226+ return "-" ;
227+ }
228+
186229 private static String getParameterClass (Type parameter ) {
187230 String [] paramType = parameter .toString ().split ("\\ ." );
188231 return paramType [paramType .length -1 ];
0 commit comments