Anyone know how to get parameter name?

M

Mike Schilling

Chris Uppal said:
Mike Schilling wrote:

[me:]
Quibble: debuggers know them, so the parameter names must be stored when
compiling for debug. It's presumably possible to open up the classfile
and read them.

Of course, there's no guarenteed way to open the classfile...

<grin>

Or any guarantee that the debugging info (local variable tables) will be
present (and correct) if you do manage to open it...

Well, that too.
 
R

Roedy Green

No Roedy, it's a reality (the optional reality, that's all...). :)

Most of the time if you are decompiling code it won't be your own and
at won't have the -g switch to compile it. So most of the time the
illusion holds.
 
P

Piotr Kobzda

Roedy said:
Most of the time if you are decompiling code it won't be your own and
at won't have the -g switch to compile it. So most of the time the
illusion holds.

In other words, it is illusion with exceptions, right?
Can not call these exceptions an optional reality?


Regards,
piotr
 
R

Roedy Green

In other words, it is illusion with exceptions, right?
Can not call these exceptions an optional reality?

I don't see any disagreement in what we each have said.
 
P

Piotr Kobzda

Roedy said:
I don't see any disagreement in what we each have said.

Yes, you are right. I missed your advice treating as opponent's
comment. Sorry for that.


Regards,
piotr
 
Joined
Apr 28, 2008
Messages
3
Reaction score
0
How to get the parameter Names that are stored in Class file using -g:var option

Hi...

How to get the Parameter Names that are stored in the LocalVariableTable_attribute structure of the
generated class file.plz help me
 
Joined
Apr 28, 2008
Messages
3
Reaction score
0
how to get parameter names that are there in the .class file

hi...

package piotrk.example.asm;

import java.io.IOException;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.EmptyVisitor;

/**
* This is a simple example showing how to retrieve Local Variable
Table (LVT)
* information (including method parameter names) from a class file using
* <em>ObjectWeb ASM 2.1</em>.
* <p>
* <b>Important:</b> To see expected results this should be compiled with
* <em>-g:vars</em> option.
*
* @author piotrk
*/
public class ShowLVT {

public static void main(String[] args) throws IOException {

String className = ShowLVT.class.getName();

new ClassReader(className)
.accept(new EmptyVisitor() {

@Override
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
System.out.println("method name=" + name + ", desc=" +
desc);
return this;
}

@Override
public void visitLocalVariable(String name, String desc,
String signature, Label start, Label end, int index) {
System.out.println("local name=" + name + ", desc=" + desc
+ ", index=" + index);
}

}, false);

}
}


Is it possible to get the Parameter Names that are stored in the .class file using javac filename.java -g:vars
 
Joined
Jan 27, 2010
Messages
27
Reaction score
0
Getting information of a class structure at runtime using Java reflection

A simple way to get the class structure information of the Class we are using in our application.

Step1: Create the Class object of the class we want to explore at run time or the class which is getting added at runtime.
Step2: As we are looking for the structure of the class, get all Constructors, Fields and methods by invoking respective functions of the Class.
Step3: print them in java console or use them as required.

Hope u like this tip.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top