getting parameter names of amethod

In reflection API it is possible to find out type of parameters of a method, is there any way to discover parameter names to?

I think parameter names are just stored in classes when they are compiled with debug information on, so I want to get them then. And I know there must be a way, cause some IDEs likeIDEA do that.

By the way is there any way to mark a class that it only compiles with debug info on? (or always have the parameter names?)

[471 byte] By [AmirPashaa] at [2007-9-25]
# 1

> In reflection API it is possible to find out type of

> parameters of a method, is there any way to discover

> parameter names to?

No

> I think parameter names are just stored in classes

> when they are compiled with debug information on,

No

> And I know there must be a

> way, cause some IDEs like IDEA do that.

They get them from the source or the Javadoc.

> By the way is there any way to mark a class that it

> only compiles with debug info on? (or always have the

> parameter names?)

No

ejpa at 2007-7-14 > top of java,Core,Core APIs...
# 2
what about Mirror API (which is included in tools.jar installed with JDK 5)?I've heard it can be used to get parameter names, if so how should I work with it?
AmirPashaa at 2007-7-14 > top of java,Core,Core APIs...
# 3
Err, look it up?Maybe the parameter names are in the debug info, they're certainly not in the standard .class format.
ejpa at 2007-7-14 > top of java,Core,Core APIs...
# 4

But there must be a way, just look at http://static.springframework.org/spring/docs/2.0-rc2/reference/aop.html#d0e7328 .

Consider @AfterReturning's returning attribute in 6.2.4.2. After returning advice and @AfterThrowing's throwing attribute in 6.2.4.3. After throwing advice! they all work with pure Java 5 (not only with AspectJ),

So I believe there must be way. I think I must dig the Spring's codes ;) Anybody can help?

AmirPashaa at 2007-7-14 > top of java,Core,Core APIs...
# 5
These Spring things don't seem to show any parameter names, I don't know why you think that's relevant.Look up the JDI API in the JDK documentation. It was your idea in the first place.
ejpa at 2007-7-14 > top of java,Core,Core APIs...
# 6

> I think parameter names are just stored in classes when they are compiled with debug information on

Sort of. You should be able to use the LocalVariableTable to match them up. However, reflection doesn't support it. You'll have to parse the class file with something like ASM or BCEL.

YAT_Archivista at 2007-7-14 > top of java,Core,Core APIs...
# 7
or JDI, that's what we've been talking about ...
ejpa at 2007-7-14 > top of java,Core,Core APIs...
# 8
Using JDI on your own VM sounds horrible.
YAT_Archivista at 2007-7-14 > top of java,Core,Core APIs...
# 9
I agree. Using a disassembler on your own .class files ditto. The original problem is probably horrible as well, and also probably quite unnnecessary. The OP might really be looking for an obfuscator.
ejpa at 2007-7-14 > top of java,Core,Core APIs...