-
1. Re: Passing an Extra Parameter to the New generated Method..
chiba Jun 26, 2003 10:29 AM (in response to ravipal)What do you want to do with b passed
to methodAx? -
2. Re: Passing an Extra Parameter to the New generated Method..
ravipal Jun 26, 2003 9:17 PM (in response to ravipal)b is my own class.. which measures the memory used by the Methods.. in the class.
It is somethign like this :
class MyClass {
int usage = 0;
statis getMyClassObj() {
.........
return new MyClass();
..........
}
}
So i measure for every class and method the memory used.
Hope this helps.
-- Ravi Pal -
3. Chiba-comment pl: Passing an Extra Parameter to the New gene
ravipal Jul 9, 2003 5:20 AM (in response to ravipal)Hello Chibba.. i was waiting for your comments on this. Whether it is possible or not?
i hope you will answer?
--Ravi Pal -
4. Re: Chiba-comment pl: Passing an Extra Parameter to the New
chiba Jul 9, 2003 2:45 PM (in response to ravipal)I'll add this feature to Javassist. So, please
help me design the API for that.
What I'd like to know is what you want to
do with b in the generated method Ax:
> Generated Method :
> MethodAx(int a, new MyClass b) {
> return a+2;
> }
In other words, let me know the body of Ax.
The example above does not use b at all!
Thanks,
Chiba -
5. Re: Chiba-comment pl: Passing an Extra Parameter to the New
ravipal Jul 9, 2003 11:17 PM (in response to ravipal)chiba,
well 'b' is an object of custome class. it could do anything. Over here in my case i am trying to manipulate some hidden variable in that object.
MethodAx(int a, new MyClass b) {
b.set(returning+"a+2");
....
..
b.setUsageMemory(calculateMemory());
...
return a+2;
}
Something like this.
The easy way can be to introduce the new MyClass() object in the Existing method only... which will be very easy like :
MethodA(int a) {
MyClass b = new MyClass();
...//any statements in original method
return a+2
}
But the problem is that if i keep on doing this in each and every method it is going to consume lots of memory in my case.. so i just want a wrapper which will redirect all the Method Invocations to my New METHOD Methodx(int a ,new MyClass b).... so that my application is not affected at all.
in any case i achieved 80% of my goal i could get the new Method Generated and i generate a new class also but the error i get is i could not invoke the new method from the original method. that is my problem.
In the example below : methoda is original method and i generate methodax with extra parameter.. i am able to do that successfully i guess (When i decompile my class file i can see the new method).
Originaly i have this method in the class :
methoda(int a) {
..
// any statements.
..
}
What i want is another method like this :
methodax(int a, MyClass b) {
//some statements plus my own statements
}
I can get like that without a problem. But i want to change the original method body to invoke the new gerenated method.
What i want is :
methoda(int a) {
methodax(int a, new myClass()) // i am not able to achieve this
}
What i get is (when i decompile my generated class):
methoda(int a) {
methodax(new Object[]{
new Integer(a), new MyClass(<no parameter>)
});
}
and when i try to run the Class using > java testClass
it gives errror that Some variable is not registered and you are trying to access it.
So... what i get is that the Method invocation which i want to make is.. a problem.
So if you could help me getting this it will be a big help. Thanks a lot.
--Ravi