I am looking for a way to extract all the methods calling printc(String)
method from a separate main program.
In IntelliJ IDE I can do so by go to the method void printc(String txt)
and click Ctrl+Alt+H
to get the expected results like this:
)
but I would like to implement such functionality in my own program (without use of an IDE)
For example:
package com.controller;
import com.mgr.ServiceBean;
import com.ser.B;
**//Java file**
public class A extends ServiceBean {
void a() {
}
void a1() {
super.printc("calle of c");
}
void a2(B boo) {
super.printc("calle of c");
}
}
======
package com.ser
import com.mgr.C
import com.mgr.ServiceBean
**//Groovy file**
public class B extends ServiceBean {
void b1() {
}
void b2() {
super.printc("calle of c")
}
}
=====
package com.mgr
**//Groovy file**
trait C
{
String test() {
return "test"
}
boolean printc(String methodName) {
if(methodName!=null)
return true
false
}
}
=========
package com.mgr
**//Groovy file**
class ServiceBean implements C {
}
============
//Need logic which accepts
class Main{
public static void main(String args[]){
Main m=new Main();
m.FindUsage("C","void printc(String)")
}
Collection FindUsage(String ClassName, String methodname){
// XXX Logic missing
return **“[A.a1(),A.a2(Integer),B.b2()]”**
}
}
NOTE: i can’t use stack trace to get the results as the A, B, C classes are completely different src and I am not running them, main is a separate program.
How can I find all the methods that call a given method in Java? --> doesn't include caller of Groovy classes