Since java screw over in terms of ordering methods and fields, I want to determine the exact order they are declared in.
Since Java 6 (or so) the JVM usually returns the members in random order, I looked at Javassist, ASM and Bcel. Bcel does not support Java 8, Javassist is a pain since it seems to not value the right ordering between methods and fields (it uses fields first, methods later even if fields are in between methods).
So ASM seams to be the best bet but it has only string representation, which is a pain.
Does anyone knows a better way?
[Update]
The idea is to use annotations for the current method to bind content for the former method. I write a precompiler for C/ASM and thats how it should look like:
public class Test {
public native int add(int a, int b);
@C("return a + b;")
public native int sub(int a, int b); @C({
"int result = a - b;",
"return result;"
})
public native int power2(int a); @ASM({
"mov eax, a",
"shl eax, 1"
})
private boolean eof;
}
As you can see the idea was to use a final field eof to bind the annotation of the last method to it. Well it seams I will make the eof field mandatory and use a convention on that.
[update2] I just updated the code to correct for and also show alternative formatting.