Pregunta

I want to know how a particular variable in Java class is used. Are there any static code analysis tools which help me trace out the variable.

For example:

Class A {
     int trackMe;
     function usedHere(trackMe);
     B bobject = new B(trackMe); 
     ...

    }

Class B {
      B (int var) {
         copyOfTrackMe = var;
      }
    }

In the above example if I want to track the variable "trackMe". I should be notified by the tool that trackMe is passed to function usedHere and also to constructor of B where a copy is made.

Any inputs are appreciated.

******* EDIT *******
I do not want to run the Code or alter the code in order to achieve this. So I guess none of the IDE debuggers won't get the job done.

¿Fue útil?

Solución

Most IDEs can do this via search. For example, in eclipse, highlighting the field trackMe and then pressing control+H will bring up the Java search dialog. Clicking on "search" will then show all the places in your workspace where that field is directly referenced.

Otros consejos

maybe i'm not understanding you correctly, but this sounds strange. perhaps if you say why you want to do, it could be clearer. However, if you haven't tried using the standard debugger found in any decent IDE, you should try that and see if it that's what you want. You can watch a variable, and see how it's content's are changing.

However, if this is something you want to do in code, you can try wrapping the variable in an object and writing a special getter method which would output some information whenever it is called such as:

class MyVarWrapper {
  private int myVar;
  public void MyVarWrapper(int n) {
    myVar = n;
  }

  public int getMyVar(String info) {
    System.out.println(info);
    return myVar;
  }
}

May look a bit convoluted, but info is limited after all :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top