You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CodeConverter.html 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <!-- NewPage -->
  3. <html lang="en">
  4. <head>
  5. <!-- Generated by javadoc (10.0.1) on Thu Jun 21 01:52:55 JST 2018 -->
  6. <title>CodeConverter (Javassist API)</title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  8. <meta name="date" content="2018-06-21">
  9. <link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
  10. <link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
  11. <script type="text/javascript" src="../script.js"></script>
  12. <script type="text/javascript" src="../jquery/jszip/dist/jszip.min.js"></script>
  13. <script type="text/javascript" src="../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
  14. <!--[if IE]>
  15. <script type="text/javascript" src="../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
  16. <![endif]-->
  17. <script type="text/javascript" src="../jquery/jquery-1.10.2.js"></script>
  18. <script type="text/javascript" src="../jquery/jquery-ui.js"></script>
  19. </head>
  20. <body>
  21. <script type="text/javascript"><!--
  22. try {
  23. if (location.href.indexOf('is-external=true') == -1) {
  24. parent.document.title="CodeConverter (Javassist API)";
  25. }
  26. }
  27. catch(err) {
  28. }
  29. //-->
  30. var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10};
  31. var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
  32. var altColor = "altColor";
  33. var rowColor = "rowColor";
  34. var tableTab = "tableTab";
  35. var activeTableTab = "activeTableTab";
  36. var pathtoroot = "../";loadScripts(document, 'script');</script>
  37. <noscript>
  38. <div>JavaScript is disabled on your browser.</div>
  39. </noscript>
  40. <div class="fixedNav">
  41. <!-- ========= START OF TOP NAVBAR ======= -->
  42. <div class="topNav"><a name="navbar.top">
  43. <!-- -->
  44. </a>
  45. <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
  46. <a name="navbar.top.firstrow">
  47. <!-- -->
  48. </a>
  49. <ul class="navList" title="Navigation">
  50. <li><a href="../overview-summary.html">Overview</a></li>
  51. <li><a href="package-summary.html">Package</a></li>
  52. <li class="navBarCell1Rev">Class</li>
  53. <li><a href="class-use/CodeConverter.html">Use</a></li>
  54. <li><a href="package-tree.html">Tree</a></li>
  55. <li><a href="../deprecated-list.html">Deprecated</a></li>
  56. <li><a href="../index-all.html">Index</a></li>
  57. </ul>
  58. </div>
  59. <div class="subNav">
  60. <ul class="navList">
  61. <li><a href="../javassist/ClassPool.html" title="class in javassist"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
  62. <li><a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
  63. </ul>
  64. <ul class="navList">
  65. <li><a href="../index.html?javassist/CodeConverter.html" target="_top">Frames</a></li>
  66. <li><a href="CodeConverter.html" target="_top">No&nbsp;Frames</a></li>
  67. </ul>
  68. <ul class="navList" id="allclasses_navbar_top">
  69. <li><a href="../allclasses-noframe.html">All&nbsp;Classes</a></li>
  70. </ul>
  71. <ul class="navListSearch">
  72. <li><label for="search">SEARCH:</label>
  73. <input type="text" id="search" value="search" disabled="disabled">
  74. <input type="reset" id="reset" value="reset" disabled="disabled">
  75. </li>
  76. </ul>
  77. <div>
  78. <script type="text/javascript"><!--
  79. allClassesLink = document.getElementById("allclasses_navbar_top");
  80. if(window==top) {
  81. allClassesLink.style.display = "block";
  82. }
  83. else {
  84. allClassesLink.style.display = "none";
  85. }
  86. //-->
  87. </script>
  88. <noscript>
  89. <div>JavaScript is disabled on your browser.</div>
  90. </noscript>
  91. </div>
  92. <div>
  93. <ul class="subNavList">
  94. <li>Summary:&nbsp;</li>
  95. <li><a href="#nested.class.summary">Nested</a>&nbsp;|&nbsp;</li>
  96. <li>Field&nbsp;|&nbsp;</li>
  97. <li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
  98. <li><a href="#method.summary">Method</a></li>
  99. </ul>
  100. <ul class="subNavList">
  101. <li>Detail:&nbsp;</li>
  102. <li>Field&nbsp;|&nbsp;</li>
  103. <li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
  104. <li><a href="#method.detail">Method</a></li>
  105. </ul>
  106. </div>
  107. <a name="skip.navbar.top">
  108. <!-- -->
  109. </a></div>
  110. <!-- ========= END OF TOP NAVBAR ========= -->
  111. </div>
  112. <div class="navPadding">&nbsp;</div>
  113. <script type="text/javascript"><!--
  114. $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
  115. //-->
  116. </script>
  117. <!-- ======== START OF CLASS DATA ======== -->
  118. <div class="header">
  119. <div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="../javassist/package-summary.html">javassist</a></div>
  120. <h2 title="Class CodeConverter" class="title">Class CodeConverter</h2>
  121. </div>
  122. <div class="contentContainer">
  123. <ul class="inheritance">
  124. <li>java.lang.Object</li>
  125. <li>
  126. <ul class="inheritance">
  127. <li>javassist.CodeConverter</li>
  128. </ul>
  129. </li>
  130. </ul>
  131. <div class="description">
  132. <ul class="blockList">
  133. <li class="blockList">
  134. <hr>
  135. <pre>public class <span class="typeNameLabel">CodeConverter</span>
  136. extends java.lang.Object</pre>
  137. <div class="block">Simple translator of method bodies
  138. (also see the <code>javassist.expr</code> package).
  139. <p>Instances of this class specifies how to instrument of the
  140. bytecodes representing a method body. They are passed to
  141. <code>CtClass.instrument()</code> or
  142. <code>CtMethod.instrument()</code> as a parameter.
  143. <p>Example:
  144. <pre>
  145. ClassPool cp = ClassPool.getDefault();
  146. CtClass point = cp.get("Point");
  147. CtClass singleton = cp.get("Singleton");
  148. CtClass client = cp.get("Client");
  149. CodeConverter conv = new CodeConverter();
  150. conv.replaceNew(point, singleton, "makePoint");
  151. client.instrument(conv);
  152. </pre>
  153. <p>This program substitutes "<code>Singleton.makePoint()</code>"
  154. for all occurrences of "<code>new Point()</code>"
  155. appearing in methods declared in a <code>Client</code> class.</div>
  156. <dl>
  157. <dt><span class="seeLabel">See Also:</span></dt>
  158. <dd><a href="../javassist/CtClass.html#instrument-javassist.CodeConverter-"><code>CtClass.instrument(CodeConverter)</code></a>,
  159. <a href="../javassist/CtBehavior.html#instrument-javassist.CodeConverter-"><code>CtBehavior.instrument(CodeConverter)</code></a>,
  160. <a href="../javassist/expr/ExprEditor.html" title="class in javassist.expr"><code>ExprEditor</code></a></dd>
  161. </dl>
  162. </li>
  163. </ul>
  164. </div>
  165. <div class="summary">
  166. <ul class="blockList">
  167. <li class="blockList">
  168. <!-- ======== NESTED CLASS SUMMARY ======== -->
  169. <ul class="blockList">
  170. <li class="blockList"><a name="nested.class.summary">
  171. <!-- -->
  172. </a>
  173. <h3>Nested Class Summary</h3>
  174. <table class="memberSummary" summary="Nested Class Summary table, listing nested classes, and an explanation">
  175. <caption><span>Nested Classes</span><span class="tabEnd">&nbsp;</span></caption>
  176. <tr>
  177. <th class="colFirst" scope="col">Modifier and Type</th>
  178. <th class="colSecond" scope="col">Class</th>
  179. <th class="colLast" scope="col">Description</th>
  180. </tr>
  181. <tr class="altColor">
  182. <td class="colFirst"><code>static interface&nbsp;</code></td>
  183. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist">CodeConverter.ArrayAccessReplacementMethodNames</a></span></code></th>
  184. <td class="colLast">
  185. <div class="block">Interface containing the method names to be used
  186. as array access replacements.</div>
  187. </td>
  188. </tr>
  189. <tr class="rowColor">
  190. <td class="colFirst"><code>static class&nbsp;</code></td>
  191. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.DefaultArrayAccessReplacementMethodNames.html" title="class in javassist">CodeConverter.DefaultArrayAccessReplacementMethodNames</a></span></code></th>
  192. <td class="colLast">
  193. <div class="block">Default implementation of the <code>ArrayAccessReplacementMethodNames</code>
  194. interface giving default values for method names to be used for replacing
  195. accesses to array elements.</div>
  196. </td>
  197. </tr>
  198. </table>
  199. </li>
  200. </ul>
  201. <!-- ======== CONSTRUCTOR SUMMARY ======== -->
  202. <ul class="blockList">
  203. <li class="blockList"><a name="constructor.summary">
  204. <!-- -->
  205. </a>
  206. <h3>Constructor Summary</h3>
  207. <table class="memberSummary" summary="Constructor Summary table, listing constructors, and an explanation">
  208. <caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
  209. <tr>
  210. <th class="colFirst" scope="col">Constructor</th>
  211. <th class="colLast" scope="col">Description</th>
  212. </tr>
  213. <tr class="altColor">
  214. <th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#CodeConverter--">CodeConverter</a></span>()</code></th>
  215. <td class="colLast">&nbsp;</td>
  216. </tr>
  217. </table>
  218. </li>
  219. </ul>
  220. <!-- ========== METHOD SUMMARY =========== -->
  221. <ul class="blockList">
  222. <li class="blockList"><a name="method.summary">
  223. <!-- -->
  224. </a>
  225. <h3>Method Summary</h3>
  226. <table class="memberSummary" summary="Method Summary table, listing methods, and an explanation">
  227. <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
  228. <tr>
  229. <th class="colFirst" scope="col">Modifier and Type</th>
  230. <th class="colSecond" scope="col">Method</th>
  231. <th class="colLast" scope="col">Description</th>
  232. </tr>
  233. <tr id="i0" class="altColor">
  234. <td class="colFirst"><code>void</code></td>
  235. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#insertAfterMethod-javassist.CtMethod-javassist.CtMethod-">insertAfterMethod</a></span>&#8203;(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;origMethod,
  236. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;afterMethod)</code></th>
  237. <td class="colLast">
  238. <div class="block">Inserts a call to another method after an existing method call.</div>
  239. </td>
  240. </tr>
  241. <tr id="i1" class="rowColor">
  242. <td class="colFirst"><code>void</code></td>
  243. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#insertBeforeMethod-javassist.CtMethod-javassist.CtMethod-">insertBeforeMethod</a></span>&#8203;(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;origMethod,
  244. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;beforeMethod)</code></th>
  245. <td class="colLast">
  246. <div class="block">Insert a call to another method before an existing method call.</div>
  247. </td>
  248. </tr>
  249. <tr id="i2" class="altColor">
  250. <td class="colFirst"><code>void</code></td>
  251. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#redirectFieldAccess-javassist.CtField-javassist.CtClass-java.lang.String-">redirectFieldAccess</a></span>&#8203;(<a href="../javassist/CtField.html" title="class in javassist">CtField</a>&nbsp;field,
  252. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;newClass,
  253. java.lang.String&nbsp;newFieldname)</code></th>
  254. <td class="colLast">
  255. <div class="block">Modify a method body so that field read/write expressions access
  256. a different field from the original one.</div>
  257. </td>
  258. </tr>
  259. <tr id="i3" class="rowColor">
  260. <td class="colFirst"><code>void</code></td>
  261. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#redirectMethodCall-java.lang.String-javassist.CtMethod-">redirectMethodCall</a></span>&#8203;(java.lang.String&nbsp;oldMethodName,
  262. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;newMethod)</code></th>
  263. <td class="colLast">
  264. <div class="block">Correct invocations to a method that has been renamed.</div>
  265. </td>
  266. </tr>
  267. <tr id="i4" class="altColor">
  268. <td class="colFirst"><code>void</code></td>
  269. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#redirectMethodCall-javassist.CtMethod-javassist.CtMethod-">redirectMethodCall</a></span>&#8203;(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;origMethod,
  270. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;substMethod)</code></th>
  271. <td class="colLast">
  272. <div class="block">Modify method invocations in a method body so that a different
  273. method will be invoked.</div>
  274. </td>
  275. </tr>
  276. <tr id="i5" class="rowColor">
  277. <td class="colFirst"><code>void</code></td>
  278. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceArrayAccess-javassist.CtClass-javassist.CodeConverter.ArrayAccessReplacementMethodNames-">replaceArrayAccess</a></span>&#8203;(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  279. <a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist">CodeConverter.ArrayAccessReplacementMethodNames</a>&nbsp;names)</code></th>
  280. <td class="colLast">
  281. <div class="block">Modify a method body, so that ALL accesses to an array are replaced with
  282. calls to static methods within another class.</div>
  283. </td>
  284. </tr>
  285. <tr id="i6" class="altColor">
  286. <td class="colFirst"><code>void</code></td>
  287. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceFieldRead-javassist.CtField-javassist.CtClass-java.lang.String-">replaceFieldRead</a></span>&#8203;(<a href="../javassist/CtField.html" title="class in javassist">CtField</a>&nbsp;field,
  288. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  289. java.lang.String&nbsp;calledMethod)</code></th>
  290. <td class="colLast">
  291. <div class="block">Modify a method body so that an expression reading the specified
  292. field is replaced with a call to the specified <i>static</i> method.</div>
  293. </td>
  294. </tr>
  295. <tr id="i7" class="rowColor">
  296. <td class="colFirst"><code>void</code></td>
  297. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceFieldWrite-javassist.CtField-javassist.CtClass-java.lang.String-">replaceFieldWrite</a></span>&#8203;(<a href="../javassist/CtField.html" title="class in javassist">CtField</a>&nbsp;field,
  298. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  299. java.lang.String&nbsp;calledMethod)</code></th>
  300. <td class="colLast">
  301. <div class="block">Modify a method body so that an expression writing the specified
  302. field is replaced with a call to the specified static method.</div>
  303. </td>
  304. </tr>
  305. <tr id="i8" class="altColor">
  306. <td class="colFirst"><code>void</code></td>
  307. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceNew-javassist.CtClass-javassist.CtClass-">replaceNew</a></span>&#8203;(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;oldClass,
  308. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;newClass)</code></th>
  309. <td class="colLast">
  310. <div class="block">Modify a method body so that instantiation of the class
  311. specified by <code>oldClass</code>
  312. is replaced with instantiation of another class <code>newClass</code>.</div>
  313. </td>
  314. </tr>
  315. <tr id="i9" class="rowColor">
  316. <td class="colFirst"><code>void</code></td>
  317. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceNew-javassist.CtClass-javassist.CtClass-java.lang.String-">replaceNew</a></span>&#8203;(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;newClass,
  318. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  319. java.lang.String&nbsp;calledMethod)</code></th>
  320. <td class="colLast">
  321. <div class="block">Modify a method body so that instantiation of the specified class
  322. is replaced with a call to the specified static method.</div>
  323. </td>
  324. </tr>
  325. </table>
  326. <ul class="blockList">
  327. <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
  328. <!-- -->
  329. </a>
  330. <h3>Methods inherited from class&nbsp;java.lang.Object</h3>
  331. <code>equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
  332. </ul>
  333. </li>
  334. </ul>
  335. </li>
  336. </ul>
  337. </div>
  338. <div class="details">
  339. <ul class="blockList">
  340. <li class="blockList">
  341. <!-- ========= CONSTRUCTOR DETAIL ======== -->
  342. <ul class="blockList">
  343. <li class="blockList"><a name="constructor.detail">
  344. <!-- -->
  345. </a>
  346. <h3>Constructor Detail</h3>
  347. <a name="CodeConverter--">
  348. <!-- -->
  349. </a>
  350. <ul class="blockListLast">
  351. <li class="blockList">
  352. <h4>CodeConverter</h4>
  353. <pre>public&nbsp;CodeConverter()</pre>
  354. </li>
  355. </ul>
  356. </li>
  357. </ul>
  358. <!-- ============ METHOD DETAIL ========== -->
  359. <ul class="blockList">
  360. <li class="blockList"><a name="method.detail">
  361. <!-- -->
  362. </a>
  363. <h3>Method Detail</h3>
  364. <a name="replaceNew-javassist.CtClass-javassist.CtClass-java.lang.String-">
  365. <!-- -->
  366. </a>
  367. <ul class="blockList">
  368. <li class="blockList">
  369. <h4>replaceNew</h4>
  370. <pre>public&nbsp;void&nbsp;replaceNew&#8203;(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;newClass,
  371. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  372. java.lang.String&nbsp;calledMethod)</pre>
  373. <div class="block">Modify a method body so that instantiation of the specified class
  374. is replaced with a call to the specified static method. For example,
  375. <code>replaceNew(ctPoint, ctSingleton, "createPoint")</code>
  376. (where <code>ctPoint</code> and <code>ctSingleton</code> are
  377. compile-time classes for class <code>Point</code> and class
  378. <code>Singleton</code>, respectively)
  379. replaces all occurrences of:
  380. <pre>new Point(x, y)</pre>
  381. in the method body with:
  382. <pre>Singleton.createPoint(x, y)</pre>
  383. <p>This enables to intercept instantiation of <code>Point</code>
  384. and change the samentics. For example, the following
  385. <code>createPoint()</code> implements the singleton pattern:
  386. <pre>public static Point createPoint(int x, int y) {
  387. if (aPoint == null)
  388. aPoint = new Point(x, y);
  389. return aPoint;
  390. }
  391. </pre>
  392. <p>The static method call substituted for the original <code>new</code>
  393. expression must be
  394. able to receive the same set of parameters as the original
  395. constructor. If there are multiple constructors with different
  396. parameter types, then there must be multiple static methods
  397. with the same name but different parameter types.
  398. <p>The return type of the substituted static method must be
  399. the exactly same as the type of the instantiated class specified by
  400. <code>newClass</code>.</div>
  401. <dl>
  402. <dt><span class="paramLabel">Parameters:</span></dt>
  403. <dd><code>newClass</code> - the instantiated class.</dd>
  404. <dd><code>calledClass</code> - the class in which the static method is
  405. declared.</dd>
  406. <dd><code>calledMethod</code> - the name of the static method.</dd>
  407. </dl>
  408. </li>
  409. </ul>
  410. <a name="replaceNew-javassist.CtClass-javassist.CtClass-">
  411. <!-- -->
  412. </a>
  413. <ul class="blockList">
  414. <li class="blockList">
  415. <h4>replaceNew</h4>
  416. <pre>public&nbsp;void&nbsp;replaceNew&#8203;(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;oldClass,
  417. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;newClass)</pre>
  418. <div class="block">Modify a method body so that instantiation of the class
  419. specified by <code>oldClass</code>
  420. is replaced with instantiation of another class <code>newClass</code>.
  421. For example,
  422. <code>replaceNew(ctPoint, ctPoint2)</code>
  423. (where <code>ctPoint</code> and <code>ctPoint2</code> are
  424. compile-time classes for class <code>Point</code> and class
  425. <code>Point2</code>, respectively)
  426. replaces all occurrences of:
  427. <pre>new Point(x, y)</pre>
  428. in the method body with:
  429. <pre>new Point2(x, y)</pre>
  430. <p>Note that <code>Point2</code> must be type-compatible with <code>Point</code>.
  431. It must have the same set of methods, fields, and constructors as the
  432. replaced class.</div>
  433. </li>
  434. </ul>
  435. <a name="redirectFieldAccess-javassist.CtField-javassist.CtClass-java.lang.String-">
  436. <!-- -->
  437. </a>
  438. <ul class="blockList">
  439. <li class="blockList">
  440. <h4>redirectFieldAccess</h4>
  441. <pre>public&nbsp;void&nbsp;redirectFieldAccess&#8203;(<a href="../javassist/CtField.html" title="class in javassist">CtField</a>&nbsp;field,
  442. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;newClass,
  443. java.lang.String&nbsp;newFieldname)</pre>
  444. <div class="block">Modify a method body so that field read/write expressions access
  445. a different field from the original one.
  446. <p>Note that this method changes only the filed name and the class
  447. declaring the field; the type of the target object does not change.
  448. Therefore, the substituted field must be declared in the same class
  449. or a superclass of the original class.
  450. <p>Also, <code>clazz</code> and <code>newClass</code> must specify
  451. the class directly declaring the field. They must not specify
  452. a subclass of that class.</div>
  453. <dl>
  454. <dt><span class="paramLabel">Parameters:</span></dt>
  455. <dd><code>field</code> - the originally accessed field.</dd>
  456. <dd><code>newClass</code> - the class declaring the substituted field.</dd>
  457. <dd><code>newFieldname</code> - the name of the substituted field.</dd>
  458. </dl>
  459. </li>
  460. </ul>
  461. <a name="replaceFieldRead-javassist.CtField-javassist.CtClass-java.lang.String-">
  462. <!-- -->
  463. </a>
  464. <ul class="blockList">
  465. <li class="blockList">
  466. <h4>replaceFieldRead</h4>
  467. <pre>public&nbsp;void&nbsp;replaceFieldRead&#8203;(<a href="../javassist/CtField.html" title="class in javassist">CtField</a>&nbsp;field,
  468. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  469. java.lang.String&nbsp;calledMethod)</pre>
  470. <div class="block">Modify a method body so that an expression reading the specified
  471. field is replaced with a call to the specified <i>static</i> method.
  472. This static method receives the target object of the original
  473. read expression as a parameter. It must return a value of
  474. the same type as the field.
  475. <p>For example, the program below
  476. <pre>Point p = new Point();
  477. int newX = p.x + 3;</pre>
  478. <p>can be translated into:
  479. <pre>Point p = new Point();
  480. int newX = Accessor.readX(p) + 3;</pre>
  481. <p>where
  482. <pre>public class Accessor {
  483. public static int readX(Object target) { ... }
  484. }</pre>
  485. <p>The type of the parameter of <code>readX()</code> must
  486. be <code>java.lang.Object</code> independently of the actual
  487. type of <code>target</code>. The return type must be the same
  488. as the field type.</div>
  489. <dl>
  490. <dt><span class="paramLabel">Parameters:</span></dt>
  491. <dd><code>field</code> - the field.</dd>
  492. <dd><code>calledClass</code> - the class in which the static method is
  493. declared.</dd>
  494. <dd><code>calledMethod</code> - the name of the static method.</dd>
  495. </dl>
  496. </li>
  497. </ul>
  498. <a name="replaceFieldWrite-javassist.CtField-javassist.CtClass-java.lang.String-">
  499. <!-- -->
  500. </a>
  501. <ul class="blockList">
  502. <li class="blockList">
  503. <h4>replaceFieldWrite</h4>
  504. <pre>public&nbsp;void&nbsp;replaceFieldWrite&#8203;(<a href="../javassist/CtField.html" title="class in javassist">CtField</a>&nbsp;field,
  505. <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  506. java.lang.String&nbsp;calledMethod)</pre>
  507. <div class="block">Modify a method body so that an expression writing the specified
  508. field is replaced with a call to the specified static method.
  509. This static method receives two parameters: the target object of
  510. the original
  511. write expression and the assigned value. The return type of the
  512. static method is <code>void</code>.
  513. <p>For example, the program below
  514. <pre>Point p = new Point();
  515. p.x = 3;</pre>
  516. <p>can be translated into:
  517. <pre>Point p = new Point();
  518. Accessor.writeX(3);</pre>
  519. <p>where
  520. <pre>public class Accessor {
  521. public static void writeX(Object target, int value) { ... }
  522. }</pre>
  523. <p>The type of the first parameter of <code>writeX()</code> must
  524. be <code>java.lang.Object</code> independently of the actual
  525. type of <code>target</code>. The type of the second parameter
  526. is the same as the field type.</div>
  527. <dl>
  528. <dt><span class="paramLabel">Parameters:</span></dt>
  529. <dd><code>field</code> - the field.</dd>
  530. <dd><code>calledClass</code> - the class in which the static method is
  531. declared.</dd>
  532. <dd><code>calledMethod</code> - the name of the static method.</dd>
  533. </dl>
  534. </li>
  535. </ul>
  536. <a name="replaceArrayAccess-javassist.CtClass-javassist.CodeConverter.ArrayAccessReplacementMethodNames-">
  537. <!-- -->
  538. </a>
  539. <ul class="blockList">
  540. <li class="blockList">
  541. <h4>replaceArrayAccess</h4>
  542. <pre>public&nbsp;void&nbsp;replaceArrayAccess&#8203;(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a>&nbsp;calledClass,
  543. <a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist">CodeConverter.ArrayAccessReplacementMethodNames</a>&nbsp;names)
  544. throws <a href="../javassist/NotFoundException.html" title="class in javassist">NotFoundException</a></pre>
  545. <div class="block">Modify a method body, so that ALL accesses to an array are replaced with
  546. calls to static methods within another class. In the case of reading an
  547. element from the array, this is replaced with a call to a static method with
  548. the array and the index as arguments, the return value is the value read from
  549. the array. If writing to an array, this is replaced with a call to a static
  550. method with the array, index and new value as parameters, the return value of
  551. the static method is <code>void</code>.
  552. <p>The <code>calledClass</code> parameter is the class containing the static methods to be used
  553. for array replacement. The <code>names</code> parameter points to an implementation of
  554. <code>ArrayAccessReplacementMethodNames</code> which specifies the names of the method to be
  555. used for access for each type of array. For example reading from an <code>int[]</code> will
  556. require a different method than if writing to an <code>int[]</code>, and writing to a <code>long[]</code>
  557. will require a different method than if writing to a <code>byte[]</code>. If the implementation
  558. of <code>ArrayAccessReplacementMethodNames</code> does not contain the name for access for a
  559. type of array, that access is not replaced.
  560. <p>A default implementation of <code>ArrayAccessReplacementMethodNames</code> called
  561. <code>DefaultArrayAccessReplacementMethodNames</code> has been provided and is what is used in the
  562. following example. This also assumes that <code>'foo.ArrayAdvisor'</code> is the name of the
  563. <code>CtClass</code> passed in.
  564. <p>If we have the following class:
  565. <pre>class POJO{
  566. int[] ints = new int[]{1, 2, 3, 4, 5};
  567. long[] longs = new int[]{10, 20, 30};
  568. Object objects = new Object[]{true, false};
  569. Integer[] integers = new Integer[]{new Integer(10)};
  570. }
  571. </pre>
  572. and this is accessed as:
  573. <pre>POJO p = new POJO();
  574. //Write to int array
  575. p.ints[2] = 7;
  576. //Read from int array
  577. int i = p.ints[2];
  578. //Write to long array
  579. p.longs[2] = 1000L;
  580. //Read from long array
  581. long l = p.longs[2];
  582. //Write to Object array
  583. p.objects[2] = "Hello";
  584. //Read from Object array
  585. Object o = p.objects[2];
  586. //Write to Integer array
  587. Integer integer = new Integer(5);
  588. p.integers[0] = integer;
  589. //Read from Object array
  590. integer = p.integers[0];
  591. </pre>
  592. Following instrumentation we will have
  593. <pre>POJO p = new POJO();
  594. //Write to int array
  595. ArrayAdvisor.arrayWriteInt(p.ints, 2, 7);
  596. //Read from int array
  597. int i = ArrayAdvisor.arrayReadInt(p.ints, 2);
  598. //Write to long array
  599. ArrayAdvisor.arrayWriteLong(p.longs, 2, 1000L);
  600. //Read from long array
  601. long l = ArrayAdvisor.arrayReadLong(p.longs, 2);
  602. //Write to Object array
  603. ArrayAdvisor.arrayWriteObject(p.objects, 2, "Hello");
  604. //Read from Object array
  605. Object o = ArrayAdvisor.arrayReadObject(p.objects, 2);
  606. //Write to Integer array
  607. Integer integer = new Integer(5);
  608. ArrayAdvisor.arrayWriteObject(p.integers, 0, integer);
  609. //Read from Object array
  610. integer = ArrayAdvisor.arrayWriteObject(p.integers, 0);
  611. </pre></div>
  612. <dl>
  613. <dt><span class="paramLabel">Parameters:</span></dt>
  614. <dd><code>calledClass</code> - the class containing the static methods.</dd>
  615. <dd><code>names</code> - contains the names of the methods to replace
  616. the different kinds of array access with.</dd>
  617. <dt><span class="throwsLabel">Throws:</span></dt>
  618. <dd><code><a href="../javassist/NotFoundException.html" title="class in javassist">NotFoundException</a></code></dd>
  619. <dt><span class="seeLabel">See Also:</span></dt>
  620. <dd><a href="../javassist/CodeConverter.DefaultArrayAccessReplacementMethodNames.html" title="class in javassist"><code>CodeConverter.DefaultArrayAccessReplacementMethodNames</code></a></dd>
  621. </dl>
  622. </li>
  623. </ul>
  624. <a name="redirectMethodCall-javassist.CtMethod-javassist.CtMethod-">
  625. <!-- -->
  626. </a>
  627. <ul class="blockList">
  628. <li class="blockList">
  629. <h4>redirectMethodCall</h4>
  630. <pre>public&nbsp;void&nbsp;redirectMethodCall&#8203;(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;origMethod,
  631. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;substMethod)
  632. throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  633. <div class="block">Modify method invocations in a method body so that a different
  634. method will be invoked.
  635. <p>Note that the target object, the parameters, or
  636. the type of invocation
  637. (static method call, interface call, or private method call)
  638. are not modified. Only the method name is changed. The substituted
  639. method must have the same signature that the original one has.
  640. If the original method is a static method, the substituted method
  641. must be static.</div>
  642. <dl>
  643. <dt><span class="paramLabel">Parameters:</span></dt>
  644. <dd><code>origMethod</code> - original method</dd>
  645. <dd><code>substMethod</code> - substituted method</dd>
  646. <dt><span class="throwsLabel">Throws:</span></dt>
  647. <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  648. </dl>
  649. </li>
  650. </ul>
  651. <a name="redirectMethodCall-java.lang.String-javassist.CtMethod-">
  652. <!-- -->
  653. </a>
  654. <ul class="blockList">
  655. <li class="blockList">
  656. <h4>redirectMethodCall</h4>
  657. <pre>public&nbsp;void&nbsp;redirectMethodCall&#8203;(java.lang.String&nbsp;oldMethodName,
  658. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;newMethod)
  659. throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  660. <div class="block">Correct invocations to a method that has been renamed.
  661. If a method is renamed, calls to that method must be also
  662. modified so that the method with the new name will be called.
  663. <p>The method must be declared in the same class before and
  664. after it is renamed.
  665. <p>Note that the target object, the parameters, or
  666. the type of invocation
  667. (static method call, interface call, or private method call)
  668. are not modified. Only the method name is changed.</div>
  669. <dl>
  670. <dt><span class="paramLabel">Parameters:</span></dt>
  671. <dd><code>oldMethodName</code> - the old name of the method.</dd>
  672. <dd><code>newMethod</code> - the method with the new name.</dd>
  673. <dt><span class="throwsLabel">Throws:</span></dt>
  674. <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  675. <dt><span class="seeLabel">See Also:</span></dt>
  676. <dd><a href="../javassist/CtMethod.html#setName-java.lang.String-"><code>CtMethod.setName(String)</code></a></dd>
  677. </dl>
  678. </li>
  679. </ul>
  680. <a name="insertBeforeMethod-javassist.CtMethod-javassist.CtMethod-">
  681. <!-- -->
  682. </a>
  683. <ul class="blockList">
  684. <li class="blockList">
  685. <h4>insertBeforeMethod</h4>
  686. <pre>public&nbsp;void&nbsp;insertBeforeMethod&#8203;(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;origMethod,
  687. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;beforeMethod)
  688. throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  689. <div class="block">Insert a call to another method before an existing method call.
  690. That "before" method must be static. The return type must be
  691. <code>void</code>. As parameters, the before method receives
  692. the target object and all the parameters to the originally invoked
  693. method. For example, if the originally invoked method is
  694. <code>move()</code>:
  695. <pre>class Point {
  696. Point move(int x, int y) { ... }
  697. }</pre>
  698. <p>Then the before method must be something like this:
  699. <pre>class Verbose {
  700. static void print(Point target, int x, int y) { ... }
  701. }</pre>
  702. <p>The <code>CodeConverter</code> would translate bytecode
  703. equivalent to:
  704. <pre>Point p2 = p.move(x + y, 0);</pre>
  705. <p>into the bytecode equivalent to:
  706. <pre>int tmp1 = x + y;
  707. int tmp2 = 0;
  708. Verbose.print(p, tmp1, tmp2);
  709. Point p2 = p.move(tmp1, tmp2);</pre></div>
  710. <dl>
  711. <dt><span class="paramLabel">Parameters:</span></dt>
  712. <dd><code>origMethod</code> - the method originally invoked.</dd>
  713. <dd><code>beforeMethod</code> - the method invoked before
  714. <code>origMethod</code>.</dd>
  715. <dt><span class="throwsLabel">Throws:</span></dt>
  716. <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  717. </dl>
  718. </li>
  719. </ul>
  720. <a name="insertAfterMethod-javassist.CtMethod-javassist.CtMethod-">
  721. <!-- -->
  722. </a>
  723. <ul class="blockListLast">
  724. <li class="blockList">
  725. <h4>insertAfterMethod</h4>
  726. <pre>public&nbsp;void&nbsp;insertAfterMethod&#8203;(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;origMethod,
  727. <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;afterMethod)
  728. throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  729. <div class="block">Inserts a call to another method after an existing method call.
  730. That "after" method must be static. The return type must be
  731. <code>void</code>. As parameters, the after method receives
  732. the target object and all the parameters to the originally invoked
  733. method. For example, if the originally invoked method is
  734. <code>move()</code>:
  735. <pre>class Point {
  736. Point move(int x, int y) { ... }
  737. }</pre>
  738. <p>Then the after method must be something like this:
  739. <pre>class Verbose {
  740. static void print(Point target, int x, int y) { ... }
  741. }</pre>
  742. <p>The <code>CodeConverter</code> would translate bytecode
  743. equivalent to:
  744. <pre>Point p2 = p.move(x + y, 0);</pre>
  745. <p>into the bytecode equivalent to:
  746. <pre>
  747. int tmp1 = x + y;
  748. int tmp2 = 0;
  749. Point p2 = p.move(tmp1, tmp2);
  750. Verbose.print(p, tmp1, tmp2);</pre></div>
  751. <dl>
  752. <dt><span class="paramLabel">Parameters:</span></dt>
  753. <dd><code>origMethod</code> - the method originally invoked.</dd>
  754. <dd><code>afterMethod</code> - the method invoked after
  755. <code>origMethod</code>.</dd>
  756. <dt><span class="throwsLabel">Throws:</span></dt>
  757. <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  758. </dl>
  759. </li>
  760. </ul>
  761. </li>
  762. </ul>
  763. </li>
  764. </ul>
  765. </div>
  766. </div>
  767. <!-- ========= END OF CLASS DATA ========= -->
  768. <!-- ======= START OF BOTTOM NAVBAR ====== -->
  769. <div class="bottomNav"><a name="navbar.bottom">
  770. <!-- -->
  771. </a>
  772. <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
  773. <a name="navbar.bottom.firstrow">
  774. <!-- -->
  775. </a>
  776. <ul class="navList" title="Navigation">
  777. <li><a href="../overview-summary.html">Overview</a></li>
  778. <li><a href="package-summary.html">Package</a></li>
  779. <li class="navBarCell1Rev">Class</li>
  780. <li><a href="class-use/CodeConverter.html">Use</a></li>
  781. <li><a href="package-tree.html">Tree</a></li>
  782. <li><a href="../deprecated-list.html">Deprecated</a></li>
  783. <li><a href="../index-all.html">Index</a></li>
  784. </ul>
  785. </div>
  786. <div class="subNav">
  787. <ul class="navList">
  788. <li><a href="../javassist/ClassPool.html" title="class in javassist"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
  789. <li><a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
  790. </ul>
  791. <ul class="navList">
  792. <li><a href="../index.html?javassist/CodeConverter.html" target="_top">Frames</a></li>
  793. <li><a href="CodeConverter.html" target="_top">No&nbsp;Frames</a></li>
  794. </ul>
  795. <ul class="navList" id="allclasses_navbar_bottom">
  796. <li><a href="../allclasses-noframe.html">All&nbsp;Classes</a></li>
  797. </ul>
  798. <div>
  799. <script type="text/javascript"><!--
  800. allClassesLink = document.getElementById("allclasses_navbar_bottom");
  801. if(window==top) {
  802. allClassesLink.style.display = "block";
  803. }
  804. else {
  805. allClassesLink.style.display = "none";
  806. }
  807. //-->
  808. </script>
  809. <noscript>
  810. <div>JavaScript is disabled on your browser.</div>
  811. </noscript>
  812. </div>
  813. <div>
  814. <ul class="subNavList">
  815. <li>Summary:&nbsp;</li>
  816. <li><a href="#nested.class.summary">Nested</a>&nbsp;|&nbsp;</li>
  817. <li>Field&nbsp;|&nbsp;</li>
  818. <li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
  819. <li><a href="#method.summary">Method</a></li>
  820. </ul>
  821. <ul class="subNavList">
  822. <li>Detail:&nbsp;</li>
  823. <li>Field&nbsp;|&nbsp;</li>
  824. <li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
  825. <li><a href="#method.detail">Method</a></li>
  826. </ul>
  827. </div>
  828. <a name="skip.navbar.bottom">
  829. <!-- -->
  830. </a></div>
  831. <!-- ======== END OF BOTTOM NAVBAR ======= -->
  832. <p class="legalCopy"><small><i>Javassist, a Java-bytecode translator toolkit.<br>
  833. Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i></small></p>
  834. </body>
  835. </html>