You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Eric Chow <ec...@macaucabletv.com> on 2004/06/30 09:07:25 UTC
Retrieve all the values of variables in the class ?
Hello,
How can I get the all variable values in the class including all the globale
constant values and local variable values ??
For example,
public class A {
private static final String s = "Hello World";
public int sum(int a, in b) {
int x = 100;
return a + b + x;
}
}
How can I get the value of "x" in the method sum and the value of String s
???
Eric
==========================
If you know what you are doing,
it is not called RESEARCH!
==========================
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: Retrieve all the values of variables in the class ?
Posted by Yasir Siraj <ya...@yahoo.com>.
It's working fine for me.
Regards.
Yasir Siraj.
IMP-DCS
Chalmers University Of Technology
Goteborg, Sweden.
--- Eric Chow <ec...@macaucabletv.com> wrote:
> Thank you very much.
> In fact, I tried this before I posted the question.
> But it just can't get the values ???? (only display
> the null value) !!!
>
>
> Did you tried it ??
>
> Eric
>
>
>
> ----- Original Message -----
> From: "Yasir Siraj" <ya...@yahoo.com>
> To: "BCEL Users List"
> <bc...@jakarta.apache.org>; "Eric Chow"
> <ec...@macaucabletv.com>
> Sent: Wednesday, June 30, 2004 5:24 PM
> Subject: Re: Retrieve all the values of variables in
> the class ?
>
>
> > Here's an example.
> >
> > public void test() {
> > JavaClass jClass;
> > ConstantPool cp;
> > ConstantPoolGen cpg;
> > jClass = new
> ClassParser("HelloWorld.class").parse();
> > cp = jClass.getConstantPool();
> > cpg = new ConstantPoolGen(cp);
> > String className = jClass.getClassName();
> > Method methods[] = jClass.getMethods();
> > Field fields[] = jClass.getFields();
> > for (int i = 0; i < fields.length; i++) {
> > System.out.println(fields[i].getName());
> > System.out.println(fields[i].getConstantValue);
> > }
> > for (int j = 0; j < methods.length; j++) {
> > MethodGen mg = new MethodGen(methods[j],
> className,
> > cpg);
> > LocalVariableGen vGen[] = mg.getLocalVariables();
> > for (int k = 0; k < vGen.length; k++) {
> > System.out.println(vGen[k].getName());
> > }
> > }
> > }
> >
> > I hope now, u'll get the idea on how to do
> things..
> >
> > Regards.
> > Yasir Siraj.
> > IMP-DCS
> > Chalmers University Of Technology
> > Goteborg, Sweden.
> >
> >
> > =====
> >
> > Regards.
> >
> > Yasir Siraj.
> >
> >
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > New and Improved Yahoo! Mail - 100MB free storage!
> > http://promotions.yahoo.com/new_mail
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> bcel-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> bcel-user-help@jakarta.apache.org
> >
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> bcel-user-help@jakarta.apache.org
>
>
=====
Regards.
Yasir Siraj.
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: Retrieve all the values of variables in the class ?
Posted by Eric Chow <ec...@macaucabletv.com>.
Thank you very much.
In fact, I tried this before I posted the question.
But it just can't get the values ???? (only display the null value) !!!
Did you tried it ??
Eric
----- Original Message -----
From: "Yasir Siraj" <ya...@yahoo.com>
To: "BCEL Users List" <bc...@jakarta.apache.org>; "Eric Chow"
<ec...@macaucabletv.com>
Sent: Wednesday, June 30, 2004 5:24 PM
Subject: Re: Retrieve all the values of variables in the class ?
> Here's an example.
>
> public void test() {
> JavaClass jClass;
> ConstantPool cp;
> ConstantPoolGen cpg;
> jClass = new ClassParser("HelloWorld.class").parse();
> cp = jClass.getConstantPool();
> cpg = new ConstantPoolGen(cp);
> String className = jClass.getClassName();
> Method methods[] = jClass.getMethods();
> Field fields[] = jClass.getFields();
> for (int i = 0; i < fields.length; i++) {
> System.out.println(fields[i].getName());
> System.out.println(fields[i].getConstantValue);
> }
> for (int j = 0; j < methods.length; j++) {
> MethodGen mg = new MethodGen(methods[j], className,
> cpg);
> LocalVariableGen vGen[] = mg.getLocalVariables();
> for (int k = 0; k < vGen.length; k++) {
> System.out.println(vGen[k].getName());
> }
> }
> }
>
> I hope now, u'll get the idea on how to do things..
>
> Regards.
> Yasir Siraj.
> IMP-DCS
> Chalmers University Of Technology
> Goteborg, Sweden.
>
>
> =====
>
> Regards.
>
> Yasir Siraj.
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> New and Improved Yahoo! Mail - 100MB free storage!
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: Retrieve all the values of variables in the class ?
Posted by Yasir Siraj <ya...@yahoo.com>.
Here's an example.
public void test() {
JavaClass jClass;
ConstantPool cp;
ConstantPoolGen cpg;
jClass = new ClassParser("HelloWorld.class").parse();
cp = jClass.getConstantPool();
cpg = new ConstantPoolGen(cp);
String className = jClass.getClassName();
Method methods[] = jClass.getMethods();
Field fields[] = jClass.getFields();
for (int i = 0; i < fields.length; i++) {
System.out.println(fields[i].getName());
System.out.println(fields[i].getConstantValue);
}
for (int j = 0; j < methods.length; j++) {
MethodGen mg = new MethodGen(methods[j], className,
cpg);
LocalVariableGen vGen[] = mg.getLocalVariables();
for (int k = 0; k < vGen.length; k++) {
System.out.println(vGen[k].getName());
}
}
}
I hope now, u'll get the idea on how to do things..
Regards.
Yasir Siraj.
IMP-DCS
Chalmers University Of Technology
Goteborg, Sweden.
=====
Regards.
Yasir Siraj.
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: Retrieve all the values of variables in the class ?
Posted by Eric Chow <ec...@macaucabletv.com>.
Would you please to show me a complete example ???
Eric
----- Original Message -----
From: "Yasir Siraj" <ya...@yahoo.com>
To: "BCEL Users List" <bc...@jakarta.apache.org>; "Eric Chow"
<ec...@macaucabletv.com>
Sent: Wednesday, June 30, 2004 3:56 PM
Subject: Re: Retrieve all the values of variables in the class ?
> Hello,
> To get all class variables & their values, u can
> use this
> Field fields[] = jClass.getFields();
> for (int i = 0; i < fields.length; i++) {
> fields[i].getName();
> fields[i].getConstantValue();
> }
>
> For method variables, u can use
> MethodGen mGen = new MethodGen(method,
> className,constantpoolgen );
> mGen.getLocalVariables();
>
> I hope this will help.
>
> Regards.
> Yasir Siraj.
> IMP-DCS
> Chalmers University Of Technology
> Goteborg, Sweden.
>
> --- Eric Chow <ec...@macaucabletv.com> wrote:
> > Hello,
> >
> > How can I get the all variable values in the class
> > including all the globale
> > constant values and local variable values ??
> >
> > For example,
> >
> > public class A {
> > private static final String s = "Hello World";
> >
> > public int sum(int a, in b) {
> > int x = 100;
> > return a + b + x;
> > }
> > }
> >
> >
> > How can I get the value of "x" in the method sum and
> > the value of String s
> > ???
> >
> >
> > Eric
> >
> >
> > ==========================
> > If you know what you are doing,
> > it is not called RESEARCH!
> > ==========================
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > bcel-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > bcel-user-help@jakarta.apache.org
> >
> >
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 50x more storage than other providers!
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: Retrieve all the values of variables in the class ?
Posted by Yasir Siraj <ya...@yahoo.com>.
Hello,
To get all class variables & their values, u can
use this
Field fields[] = jClass.getFields();
for (int i = 0; i < fields.length; i++) {
fields[i].getName();
fields[i].getConstantValue();
}
For method variables, u can use
MethodGen mGen = new MethodGen(method,
className,constantpoolgen );
mGen.getLocalVariables();
I hope this will help.
Regards.
Yasir Siraj.
IMP-DCS
Chalmers University Of Technology
Goteborg, Sweden.
--- Eric Chow <ec...@macaucabletv.com> wrote:
> Hello,
>
> How can I get the all variable values in the class
> including all the globale
> constant values and local variable values ??
>
> For example,
>
> public class A {
> private static final String s = "Hello World";
>
> public int sum(int a, in b) {
> int x = 100;
> return a + b + x;
> }
> }
>
>
> How can I get the value of "x" in the method sum and
> the value of String s
> ???
>
>
> Eric
>
>
> ==========================
> If you know what you are doing,
> it is not called RESEARCH!
> ==========================
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> bcel-user-help@jakarta.apache.org
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org