开发者

Determining method dependency in an Object Oriented class

开发者 https://www.devze.com 2023-03-19 00:02 出处:网络
Is anyone aware of any methodology to try and determine the method and instance variable dependencies that exact for a single method in an object oriented class? For example, if I have the following c

Is anyone aware of any methodology to try and determine the method and instance variable dependencies that exact for a single method in an object oriented class? For example, if I have the following code:

public class Foo {
   private int x;
   private int y;

   public Foo() {
      x = 1;
      y = 2;
   }

   public void doFoo() {
      doJaa(x);
      x++;      
   }

   private void doJaa(int xVar) {
      System.out.println("x is: " + xVar);
   }

   private void nop() {
      System.out.println("Nada!");
   }
}

What I was looking to do was to take a method, say method 'doFoo' and determine all of its instance variable and method dependencies (I would like to determine these dependencies at build-time). In this case, those dependencies would be 'int x', 'Foo()' and 'doJaa(int x)'. There are no dependencies between method 'nop' and 'doJaa' however. Is there a name for this type of analysis, just so I can search for more information around it? I am aware of the following analysis techniques

  1. Control flow graph (No use to me)
  2. Program Dependence graph
  3. System Dependence graph

1 isn't much use to me as it's concerned with control flow. 2 is concerned with control and data dependencies either within a single method or across method boundaries开发者_运维问答. I have researched this and it isn't really what I want as it's too granular. 3 is a follow on from 2 and again is way too granular for what I need.


I know only one tool JDepend: http://www.clarkware.com/software/JDepend.html

But I doubt it works on one method basics. if it does not help you you need to implement your own logic probably using byte-code manipulation (engineering) library.


for such special purpose, it is hard to find any off shelf software for you to use.

it can be done by static analyzing of java byte code, i don't know why you need such function, what the real benefit to analyze it. if it is just a special purpose for you, i think you need to write such tool by your self.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号