0

I have created a hierarchy of unimplemented functions in a Java class, and I'd like to keep track of the functions that can be implemented, given the ones that have already been implemented.

As an example, here is a long chain of unimplemented function dependencies that I'd like to analyze programmatically, to determine which functions can be implemented (given the ones that have already been implemented).

//requires the functions b and c
public static void a(){

}

//does not require any functions to be implemented before being implemented
public static void b(){

}

//requires the function b
public static void c(){

}

public static void d(){ //requires the function a

}

public static void e(){ //requires the function a and c

}

public static void f(){ //requires the function a and c

}

//requires the functions a and f
public static void g(){

}

Is there any way to determine which of the above functions can be implemented here (given a list of already-implemented functions)? In Javascript, solving this problem is straightforward (because it's possible to set properties of each function in the function's prototype), but in Java, I have not yet found a simple and concise solution.

Anderson Green
  • 30,230
  • 67
  • 195
  • 328
  • in Java I can solve, but not in simple mode. This part of the code is used in the cracking a decompiled and obfuscated code... –  Sep 03 '12 at 18:52
  • What is "simple mode", and how does this question relate to the decompilation of code? – Anderson Green Sep 03 '12 at 19:16
  • You can implement functions in any order. If you use interfaces, you can test the functions in any order as well. – Peter Lawrey Sep 03 '12 at 19:20
  • Yes, you can implement functions in any order. However, in this case I'm trying to require the functions to be implemented in a specific order, based on the functions that have already been implemented. – Anderson Green Sep 03 '12 at 19:28

2 Answers2

0

In your example, all of your methods have implementation, even with a empty body. To detected methods without implementation, you will need to mark them abstract (your class will be abstract too) and you will need to write some reflexive code. If you want to introspect the code inside each method, you can deal with its stack trace. Take a look here: How do I find the caller of a method using stacktrace or reflection?

Community
  • 1
  • 1
davidbuzatto
  • 9,207
  • 1
  • 43
  • 50
  • I still need to find a way to keep track of methods that are completely implemented (and working properly), as well as methods that are still being written (and therefore a work in progress). – Anderson Green Sep 03 '12 at 19:15
  • I didn't understand why you need this, but it seems that you are trying to do something like unit testing... Maybe some static code analyser tool would help you: http://en.wikipedia.org/wiki/List_of_tools_for_static_code_analysis – davidbuzatto Sep 03 '12 at 19:18
  • I have changed the question's title to clarify my intentions. – Anderson Green Sep 03 '12 at 19:31
0

The idea of interfaces seems perfectly suited to what you're doing. Here's a hierarchy of interfaces that keeps track of functions a through d:

interface HasA extends HasB, HasC {
    public static void a();
}

interface HasB {
    public static void b();
}

interface HasC extends HasB {
    public static void c();
}


interface HasD extends HasA {
    public static void d();
}

A class that implements HasA (for example) won't compile unless it defines the methods a, b, and c.

Vectornaut
  • 473
  • 5
  • 11
  • I'm dealing with methods that require other methods within a single class, not multiple classes. I need to determine (programmatically) whether a given method is implemented or not, so that I can determine which of the other methods can be implemented. – Anderson Green Sep 03 '12 at 19:13