"chiba" wrote : I think you want to replace cascaded method calls
| with another expression.
|
| But I'm wondering whether or not such replacement
| is used frequently enough to be included in the Javassist
| API. Do you think the Javassist API includes a method
| for replacing two-cascaded method calls, three-cascaded,
| ...? I would like to know your thought.
|
| Thank you,
I wrote a search/replace class myself that is quite useful in fact. It is a bit
low-level, but still user friendly.
It takes two arrays as input, one for search and one for replace.
The array elements have two different meanings: Opcode, or reference. An opcode
is simply a byte, the reference is a string which will be converted to the
right two byte long index for comparison.
|
| //Replace all Display.getDisplay(this).getCurrent() with _getCurrent()
| SmartBytecode search=new SmartBytecode();
| search.addOpcode(Opcode.ALOAD_0);
| search.addOpcode(Opcode.INVOKESTATIC);
| search.addReference("getDisplay");
| search.addOpcode(Opcode.INVOKEVIRTUAL);
| search.addReference("getCurrent");
|
| SmartBytecode replace=new SmartBytecode();
| replace.addOpcode(Opcode.INVOKESTATIC);
|
replace.addReference("_getCurrent,javax.microedition.lcdui.Displayable");
| replaceAll(cHost, search, replace,"_getCurrent");
|
|
The search is mathced both on the value, but also on the location. If a byte is
found which matches a opcode, it will still be rejected if it is not in a
dedicated opcode position, same with reference values.
Replacing is done by the replacing code, with correct indexes to the reference
names, and NOPs are filled in where needed.
Also, very importantly, I allow putting "holes" in the arrays, to allow for
proper search and replace when some bytes might change value, like which local
variable is used to hold a parameter value for example. The 'holes' will be
ignored during comparison, and will not overwrite upon replacing. This allows
for search and replace on complex patterns, with good flexibility.
Not sure if this is everyones cup of tea, but it solved all my complex search
and replace needs... :)
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3867662#3867662
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3867662
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user