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.

CtNewMethod.html 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. <!DOCTYPE HTML>
  2. <!-- NewPage -->
  3. <html lang="en">
  4. <head>
  5. <!-- Generated by javadoc (11) on Sat May 08 11:16:00 JST 2021 -->
  6. <title>CtNewMethod (Javassist API)</title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  8. <meta name="dc.created" content="2021-05-08">
  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-3.3.1.js"></script>
  18. <script type="text/javascript" src="../jquery/jquery-migrate-3.0.1.js"></script>
  19. <script type="text/javascript" src="../jquery/jquery-ui.js"></script>
  20. </head>
  21. <body>
  22. <script type="text/javascript"><!--
  23. try {
  24. if (location.href.indexOf('is-external=true') == -1) {
  25. parent.document.title="CtNewMethod (Javassist API)";
  26. }
  27. }
  28. catch(err) {
  29. }
  30. //-->
  31. var data = {"i0":9,"i1":9,"i2":9,"i3":9,"i4":9,"i5":9,"i6":9,"i7":9,"i8":9,"i9":9,"i10":9};
  32. var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],8:["t4","Concrete Methods"]};
  33. var altColor = "altColor";
  34. var rowColor = "rowColor";
  35. var tableTab = "tableTab";
  36. var activeTableTab = "activeTableTab";
  37. var pathtoroot = "../";
  38. var useModuleDirectories = true;
  39. loadScripts(document, 'script');</script>
  40. <noscript>
  41. <div>JavaScript is disabled on your browser.</div>
  42. </noscript>
  43. <header role="banner">
  44. <nav role="navigation">
  45. <div class="fixedNav">
  46. <!-- ========= START OF TOP NAVBAR ======= -->
  47. <div class="topNav"><a id="navbar.top">
  48. <!-- -->
  49. </a>
  50. <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
  51. <a id="navbar.top.firstrow">
  52. <!-- -->
  53. </a>
  54. <ul class="navList" title="Navigation">
  55. <li><a href="../index.html">Overview</a></li>
  56. <li><a href="package-summary.html">Package</a></li>
  57. <li class="navBarCell1Rev">Class</li>
  58. <li><a href="class-use/CtNewMethod.html">Use</a></li>
  59. <li><a href="package-tree.html">Tree</a></li>
  60. <li><a href="../deprecated-list.html">Deprecated</a></li>
  61. <li><a href="../index-all.html">Index</a></li>
  62. </ul>
  63. </div>
  64. <div class="subNav">
  65. <ul class="navList" id="allclasses_navbar_top">
  66. <li><a href="../allclasses.html">All&nbsp;Classes</a></li>
  67. </ul>
  68. <ul class="navListSearch">
  69. <li><label for="search">SEARCH:</label>
  70. <input type="text" id="search" value="search" disabled="disabled">
  71. <input type="reset" id="reset" value="reset" disabled="disabled">
  72. </li>
  73. </ul>
  74. <div>
  75. <script type="text/javascript"><!--
  76. allClassesLink = document.getElementById("allclasses_navbar_top");
  77. if(window==top) {
  78. allClassesLink.style.display = "block";
  79. }
  80. else {
  81. allClassesLink.style.display = "none";
  82. }
  83. //-->
  84. </script>
  85. <noscript>
  86. <div>JavaScript is disabled on your browser.</div>
  87. </noscript>
  88. </div>
  89. <div>
  90. <ul class="subNavList">
  91. <li>Summary:&nbsp;</li>
  92. <li>Nested&nbsp;|&nbsp;</li>
  93. <li>Field&nbsp;|&nbsp;</li>
  94. <li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
  95. <li><a href="#method.summary">Method</a></li>
  96. </ul>
  97. <ul class="subNavList">
  98. <li>Detail:&nbsp;</li>
  99. <li>Field&nbsp;|&nbsp;</li>
  100. <li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
  101. <li><a href="#method.detail">Method</a></li>
  102. </ul>
  103. </div>
  104. <a id="skip.navbar.top">
  105. <!-- -->
  106. </a></div>
  107. <!-- ========= END OF TOP NAVBAR ========= -->
  108. </div>
  109. <div class="navPadding">&nbsp;</div>
  110. <script type="text/javascript"><!--
  111. $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
  112. //-->
  113. </script>
  114. </nav>
  115. </header>
  116. <!-- ======== START OF CLASS DATA ======== -->
  117. <main role="main">
  118. <div class="header">
  119. <div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="package-summary.html">javassist</a></div>
  120. <h2 title="Class CtNewMethod" class="title">Class CtNewMethod</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.CtNewMethod</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">CtNewMethod</span>
  136. extends java.lang.Object</pre>
  137. <div class="block">A collection of static methods for creating a <code>CtMethod</code>.
  138. An instance of this class does not make any sense.</div>
  139. <dl>
  140. <dt><span class="seeLabel">See Also:</span></dt>
  141. <dd><a href="CtClass.html#addMethod(javassist.CtMethod)"><code>CtClass.addMethod(CtMethod)</code></a></dd>
  142. </dl>
  143. </li>
  144. </ul>
  145. </div>
  146. <div class="summary">
  147. <ul class="blockList">
  148. <li class="blockList">
  149. <!-- ======== CONSTRUCTOR SUMMARY ======== -->
  150. <section role="region">
  151. <ul class="blockList">
  152. <li class="blockList"><a id="constructor.summary">
  153. <!-- -->
  154. </a>
  155. <h3>Constructor Summary</h3>
  156. <table class="memberSummary">
  157. <caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
  158. <tr>
  159. <th class="colFirst" scope="col">Constructor</th>
  160. <th class="colLast" scope="col">Description</th>
  161. </tr>
  162. <tr class="altColor">
  163. <th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E()">CtNewMethod</a></span>()</code></th>
  164. <td class="colLast">&nbsp;</td>
  165. </tr>
  166. </table>
  167. </li>
  168. </ul>
  169. </section>
  170. <!-- ========== METHOD SUMMARY =========== -->
  171. <section role="region">
  172. <ul class="blockList">
  173. <li class="blockList"><a id="method.summary">
  174. <!-- -->
  175. </a>
  176. <h3>Method Summary</h3>
  177. <table class="memberSummary">
  178. <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static 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>
  179. <tr>
  180. <th class="colFirst" scope="col">Modifier and Type</th>
  181. <th class="colSecond" scope="col">Method</th>
  182. <th class="colLast" scope="col">Description</th>
  183. </tr>
  184. <tr id="i0" class="altColor">
  185. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  186. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#abstractMethod(javassist.CtClass,java.lang.String,javassist.CtClass%5B%5D,javassist.CtClass%5B%5D,javassist.CtClass)">abstractMethod</a></span>&#8203;(<a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  187. java.lang.String&nbsp;mname,
  188. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameters,
  189. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptions,
  190. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)</code></th>
  191. <td class="colLast">
  192. <div class="block">Creates a public abstract method.</div>
  193. </td>
  194. </tr>
  195. <tr id="i1" class="rowColor">
  196. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  197. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#copy(javassist.CtMethod,java.lang.String,javassist.CtClass,javassist.ClassMap)">copy</a></span>&#8203;(<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;src,
  198. java.lang.String&nbsp;name,
  199. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring,
  200. <a href="ClassMap.html" title="class in javassist">ClassMap</a>&nbsp;map)</code></th>
  201. <td class="colLast">
  202. <div class="block">Creates a copy of a method with a new name.</div>
  203. </td>
  204. </tr>
  205. <tr id="i2" class="altColor">
  206. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  207. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#copy(javassist.CtMethod,javassist.CtClass,javassist.ClassMap)">copy</a></span>&#8203;(<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;src,
  208. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring,
  209. <a href="ClassMap.html" title="class in javassist">ClassMap</a>&nbsp;map)</code></th>
  210. <td class="colLast">
  211. <div class="block">Creates a copy of a method.</div>
  212. </td>
  213. </tr>
  214. <tr id="i3" class="rowColor">
  215. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  216. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#delegator(javassist.CtMethod,javassist.CtClass)">delegator</a></span>&#8203;(<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;delegate,
  217. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)</code></th>
  218. <td class="colLast">
  219. <div class="block">Creates a method forwarding to a delegate in
  220. a super class.</div>
  221. </td>
  222. </tr>
  223. <tr id="i4" class="altColor">
  224. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  225. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getter(java.lang.String,javassist.CtField)">getter</a></span>&#8203;(java.lang.String&nbsp;methodName,
  226. <a href="CtField.html" title="class in javassist">CtField</a>&nbsp;field)</code></th>
  227. <td class="colLast">
  228. <div class="block">Creates a public getter method.</div>
  229. </td>
  230. </tr>
  231. <tr id="i5" class="rowColor">
  232. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  233. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#make(int,javassist.CtClass,java.lang.String,javassist.CtClass%5B%5D,javassist.CtClass%5B%5D,java.lang.String,javassist.CtClass)">make</a></span>&#8203;(int&nbsp;modifiers,
  234. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  235. java.lang.String&nbsp;mname,
  236. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameters,
  237. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptions,
  238. java.lang.String&nbsp;body,
  239. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)</code></th>
  240. <td class="colLast">
  241. <div class="block">Creates a method.</div>
  242. </td>
  243. </tr>
  244. <tr id="i6" class="altColor">
  245. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  246. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#make(java.lang.String,javassist.CtClass)">make</a></span>&#8203;(java.lang.String&nbsp;src,
  247. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)</code></th>
  248. <td class="colLast">
  249. <div class="block">Compiles the given source code and creates a method.</div>
  250. </td>
  251. </tr>
  252. <tr id="i7" class="rowColor">
  253. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  254. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#make(java.lang.String,javassist.CtClass,java.lang.String,java.lang.String)">make</a></span>&#8203;(java.lang.String&nbsp;src,
  255. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring,
  256. java.lang.String&nbsp;delegateObj,
  257. java.lang.String&nbsp;delegateMethod)</code></th>
  258. <td class="colLast">
  259. <div class="block">Compiles the given source code and creates a method.</div>
  260. </td>
  261. </tr>
  262. <tr id="i8" class="altColor">
  263. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  264. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#make(javassist.CtClass,java.lang.String,javassist.CtClass%5B%5D,javassist.CtClass%5B%5D,java.lang.String,javassist.CtClass)">make</a></span>&#8203;(<a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  265. java.lang.String&nbsp;mname,
  266. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameters,
  267. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptions,
  268. java.lang.String&nbsp;body,
  269. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)</code></th>
  270. <td class="colLast">
  271. <div class="block">Creates a public (non-static) method.</div>
  272. </td>
  273. </tr>
  274. <tr id="i9" class="rowColor">
  275. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  276. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#setter(java.lang.String,javassist.CtField)">setter</a></span>&#8203;(java.lang.String&nbsp;methodName,
  277. <a href="CtField.html" title="class in javassist">CtField</a>&nbsp;field)</code></th>
  278. <td class="colLast">
  279. <div class="block">Creates a public setter method.</div>
  280. </td>
  281. </tr>
  282. <tr id="i10" class="altColor">
  283. <td class="colFirst"><code>static <a href="CtMethod.html" title="class in javassist">CtMethod</a></code></td>
  284. <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#wrapped(javassist.CtClass,java.lang.String,javassist.CtClass%5B%5D,javassist.CtClass%5B%5D,javassist.CtMethod,javassist.CtMethod.ConstParameter,javassist.CtClass)">wrapped</a></span>&#8203;(<a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  285. java.lang.String&nbsp;mname,
  286. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameterTypes,
  287. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptionTypes,
  288. <a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;body,
  289. <a href="CtMethod.ConstParameter.html" title="class in javassist">CtMethod.ConstParameter</a>&nbsp;constParam,
  290. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)</code></th>
  291. <td class="colLast">
  292. <div class="block">Creates a wrapped method.</div>
  293. </td>
  294. </tr>
  295. </table>
  296. <ul class="blockList">
  297. <li class="blockList"><a id="methods.inherited.from.class.java.lang.Object">
  298. <!-- -->
  299. </a>
  300. <h3>Methods inherited from class&nbsp;java.lang.Object</h3>
  301. <code>equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
  302. </ul>
  303. </li>
  304. </ul>
  305. </section>
  306. </li>
  307. </ul>
  308. </div>
  309. <div class="details">
  310. <ul class="blockList">
  311. <li class="blockList">
  312. <!-- ========= CONSTRUCTOR DETAIL ======== -->
  313. <section role="region">
  314. <ul class="blockList">
  315. <li class="blockList"><a id="constructor.detail">
  316. <!-- -->
  317. </a>
  318. <h3>Constructor Detail</h3>
  319. <a id="&lt;init&gt;()">
  320. <!-- -->
  321. </a>
  322. <ul class="blockListLast">
  323. <li class="blockList">
  324. <h4>CtNewMethod</h4>
  325. <pre>public&nbsp;CtNewMethod()</pre>
  326. </li>
  327. </ul>
  328. </li>
  329. </ul>
  330. </section>
  331. <!-- ============ METHOD DETAIL ========== -->
  332. <section role="region">
  333. <ul class="blockList">
  334. <li class="blockList"><a id="method.detail">
  335. <!-- -->
  336. </a>
  337. <h3>Method Detail</h3>
  338. <a id="make(java.lang.String,javassist.CtClass)">
  339. <!-- -->
  340. </a>
  341. <ul class="blockList">
  342. <li class="blockList">
  343. <h4>make</h4>
  344. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;make&#8203;(java.lang.String&nbsp;src,
  345. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)
  346. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  347. <div class="block">Compiles the given source code and creates a method.
  348. The source code must include not only the method body
  349. but the whole declaration, for example,
  350. <pre>"public Object id(Object obj) { return obj; }"</pre></div>
  351. <dl>
  352. <dt><span class="paramLabel">Parameters:</span></dt>
  353. <dd><code>src</code> - the source text.</dd>
  354. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  355. <dt><span class="throwsLabel">Throws:</span></dt>
  356. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  357. </dl>
  358. </li>
  359. </ul>
  360. <a id="make(java.lang.String,javassist.CtClass,java.lang.String,java.lang.String)">
  361. <!-- -->
  362. </a>
  363. <ul class="blockList">
  364. <li class="blockList">
  365. <h4>make</h4>
  366. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;make&#8203;(java.lang.String&nbsp;src,
  367. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring,
  368. java.lang.String&nbsp;delegateObj,
  369. java.lang.String&nbsp;delegateMethod)
  370. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  371. <div class="block">Compiles the given source code and creates a method.
  372. The source code must include not only the method body
  373. but the whole declaration, for example,
  374. <pre>"public Object id(Object obj) { return obj; }"</pre>
  375. <p>If the source code includes <code>$proceed()</code>, then
  376. it is compiled into a method call on the specified object.</div>
  377. <dl>
  378. <dt><span class="paramLabel">Parameters:</span></dt>
  379. <dd><code>src</code> - the source text.</dd>
  380. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  381. <dd><code>delegateObj</code> - the source text specifying the object
  382. that is called on by <code>$proceed()</code>.</dd>
  383. <dd><code>delegateMethod</code> - the name of the method
  384. that is called by <code>$proceed()</code>.</dd>
  385. <dt><span class="throwsLabel">Throws:</span></dt>
  386. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  387. </dl>
  388. </li>
  389. </ul>
  390. <a id="make(javassist.CtClass,java.lang.String,javassist.CtClass[],javassist.CtClass[],java.lang.String,javassist.CtClass)">
  391. <!-- -->
  392. </a>
  393. <ul class="blockList">
  394. <li class="blockList">
  395. <h4>make</h4>
  396. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;make&#8203;(<a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  397. java.lang.String&nbsp;mname,
  398. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameters,
  399. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptions,
  400. java.lang.String&nbsp;body,
  401. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)
  402. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  403. <div class="block">Creates a public (non-static) method. The created method cannot
  404. be changed to a static method later.</div>
  405. <dl>
  406. <dt><span class="paramLabel">Parameters:</span></dt>
  407. <dd><code>returnType</code> - the type of the returned value.</dd>
  408. <dd><code>mname</code> - the method name.</dd>
  409. <dd><code>parameters</code> - a list of the parameter types.</dd>
  410. <dd><code>exceptions</code> - a list of the exception types.</dd>
  411. <dd><code>body</code> - the source text of the method body.
  412. It must be a block surrounded by <code>{}</code>.
  413. If it is <code>null</code>, the created method
  414. does nothing except returning zero or null.</dd>
  415. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  416. <dt><span class="throwsLabel">Throws:</span></dt>
  417. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  418. <dt><span class="seeLabel">See Also:</span></dt>
  419. <dd><a href="#make(int,javassist.CtClass,java.lang.String,javassist.CtClass%5B%5D,javassist.CtClass%5B%5D,java.lang.String,javassist.CtClass)"><code>make(int, CtClass, String, CtClass[], CtClass[], String, CtClass)</code></a></dd>
  420. </dl>
  421. </li>
  422. </ul>
  423. <a id="make(int,javassist.CtClass,java.lang.String,javassist.CtClass[],javassist.CtClass[],java.lang.String,javassist.CtClass)">
  424. <!-- -->
  425. </a>
  426. <ul class="blockList">
  427. <li class="blockList">
  428. <h4>make</h4>
  429. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;make&#8203;(int&nbsp;modifiers,
  430. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  431. java.lang.String&nbsp;mname,
  432. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameters,
  433. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptions,
  434. java.lang.String&nbsp;body,
  435. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)
  436. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  437. <div class="block">Creates a method. <code>modifiers</code> can contain
  438. <code>Modifier.STATIC</code>.</div>
  439. <dl>
  440. <dt><span class="paramLabel">Parameters:</span></dt>
  441. <dd><code>modifiers</code> - access modifiers.</dd>
  442. <dd><code>returnType</code> - the type of the returned value.</dd>
  443. <dd><code>mname</code> - the method name.</dd>
  444. <dd><code>parameters</code> - a list of the parameter types.</dd>
  445. <dd><code>exceptions</code> - a list of the exception types.</dd>
  446. <dd><code>body</code> - the source text of the method body.
  447. It must be a block surrounded by <code>{}</code>.
  448. If it is <code>null</code>, the created method
  449. does nothing except returning zero or null.</dd>
  450. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  451. <dt><span class="throwsLabel">Throws:</span></dt>
  452. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  453. <dt><span class="seeLabel">See Also:</span></dt>
  454. <dd><a href="Modifier.html" title="class in javassist"><code>Modifier</code></a></dd>
  455. </dl>
  456. </li>
  457. </ul>
  458. <a id="copy(javassist.CtMethod,javassist.CtClass,javassist.ClassMap)">
  459. <!-- -->
  460. </a>
  461. <ul class="blockList">
  462. <li class="blockList">
  463. <h4>copy</h4>
  464. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;copy&#8203;(<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;src,
  465. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring,
  466. <a href="ClassMap.html" title="class in javassist">ClassMap</a>&nbsp;map)
  467. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  468. <div class="block">Creates a copy of a method. This method is provided for creating
  469. a new method based on an existing method.
  470. This is a convenience method for calling
  471. <a href="CtMethod.html#%3Cinit%3E(javassist.CtMethod,javassist.CtClass,javassist.ClassMap)"><code>this constructor</code></a>.
  472. See the description of the constructor for particular behavior of the copying.</div>
  473. <dl>
  474. <dt><span class="paramLabel">Parameters:</span></dt>
  475. <dd><code>src</code> - the source method.</dd>
  476. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  477. <dd><code>map</code> - the hash table associating original class names
  478. with substituted names.
  479. It can be <code>null</code>.</dd>
  480. <dt><span class="throwsLabel">Throws:</span></dt>
  481. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  482. <dt><span class="seeLabel">See Also:</span></dt>
  483. <dd><a href="CtMethod.html#%3Cinit%3E(javassist.CtMethod,javassist.CtClass,javassist.ClassMap)"><code>CtMethod(CtMethod,CtClass,ClassMap)</code></a></dd>
  484. </dl>
  485. </li>
  486. </ul>
  487. <a id="copy(javassist.CtMethod,java.lang.String,javassist.CtClass,javassist.ClassMap)">
  488. <!-- -->
  489. </a>
  490. <ul class="blockList">
  491. <li class="blockList">
  492. <h4>copy</h4>
  493. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;copy&#8203;(<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;src,
  494. java.lang.String&nbsp;name,
  495. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring,
  496. <a href="ClassMap.html" title="class in javassist">ClassMap</a>&nbsp;map)
  497. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  498. <div class="block">Creates a copy of a method with a new name.
  499. This method is provided for creating
  500. a new method based on an existing method.
  501. This is a convenience method for calling
  502. <a href="CtMethod.html#%3Cinit%3E(javassist.CtMethod,javassist.CtClass,javassist.ClassMap)"><code>this constructor</code></a>.
  503. See the description of the constructor for particular behavior of the copying.</div>
  504. <dl>
  505. <dt><span class="paramLabel">Parameters:</span></dt>
  506. <dd><code>src</code> - the source method.</dd>
  507. <dd><code>name</code> - the name of the created method.</dd>
  508. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  509. <dd><code>map</code> - the hash table associating original class names
  510. with substituted names.
  511. It can be <code>null</code>.</dd>
  512. <dt><span class="throwsLabel">Throws:</span></dt>
  513. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  514. <dt><span class="seeLabel">See Also:</span></dt>
  515. <dd><a href="CtMethod.html#%3Cinit%3E(javassist.CtMethod,javassist.CtClass,javassist.ClassMap)"><code>CtMethod(CtMethod,CtClass,ClassMap)</code></a></dd>
  516. </dl>
  517. </li>
  518. </ul>
  519. <a id="abstractMethod(javassist.CtClass,java.lang.String,javassist.CtClass[],javassist.CtClass[],javassist.CtClass)">
  520. <!-- -->
  521. </a>
  522. <ul class="blockList">
  523. <li class="blockList">
  524. <h4>abstractMethod</h4>
  525. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;abstractMethod&#8203;(<a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  526. java.lang.String&nbsp;mname,
  527. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameters,
  528. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptions,
  529. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)
  530. throws <a href="NotFoundException.html" title="class in javassist">NotFoundException</a></pre>
  531. <div class="block">Creates a public abstract method.</div>
  532. <dl>
  533. <dt><span class="paramLabel">Parameters:</span></dt>
  534. <dd><code>returnType</code> - the type of the returned value</dd>
  535. <dd><code>mname</code> - the method name</dd>
  536. <dd><code>parameters</code> - a list of the parameter types</dd>
  537. <dd><code>exceptions</code> - a list of the exception types</dd>
  538. <dd><code>declaring</code> - the class to which the created method is added.</dd>
  539. <dt><span class="throwsLabel">Throws:</span></dt>
  540. <dd><code><a href="NotFoundException.html" title="class in javassist">NotFoundException</a></code></dd>
  541. <dt><span class="seeLabel">See Also:</span></dt>
  542. <dd><a href="CtMethod.html#%3Cinit%3E(javassist.CtClass,java.lang.String,javassist.CtClass%5B%5D,javassist.CtClass)"><code>CtMethod(CtClass,String,CtClass[],CtClass)</code></a></dd>
  543. </dl>
  544. </li>
  545. </ul>
  546. <a id="getter(java.lang.String,javassist.CtField)">
  547. <!-- -->
  548. </a>
  549. <ul class="blockList">
  550. <li class="blockList">
  551. <h4>getter</h4>
  552. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;getter&#8203;(java.lang.String&nbsp;methodName,
  553. <a href="CtField.html" title="class in javassist">CtField</a>&nbsp;field)
  554. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  555. <div class="block">Creates a public getter method. The getter method returns the value
  556. of the specified field in the class to which this method is added.
  557. The created method is initially not static even if the field is
  558. static. Change the modifiers if the method should be static.</div>
  559. <dl>
  560. <dt><span class="paramLabel">Parameters:</span></dt>
  561. <dd><code>methodName</code> - the name of the getter</dd>
  562. <dd><code>field</code> - the field accessed.</dd>
  563. <dt><span class="throwsLabel">Throws:</span></dt>
  564. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  565. </dl>
  566. </li>
  567. </ul>
  568. <a id="setter(java.lang.String,javassist.CtField)">
  569. <!-- -->
  570. </a>
  571. <ul class="blockList">
  572. <li class="blockList">
  573. <h4>setter</h4>
  574. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;setter&#8203;(java.lang.String&nbsp;methodName,
  575. <a href="CtField.html" title="class in javassist">CtField</a>&nbsp;field)
  576. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  577. <div class="block">Creates a public setter method. The setter method assigns the
  578. value of the first parameter to the specified field
  579. in the class to which this method is added.
  580. The created method is not static even if the field is
  581. static. You may not change it to be static
  582. by <code>setModifiers()</code> in <code>CtBehavior</code>.</div>
  583. <dl>
  584. <dt><span class="paramLabel">Parameters:</span></dt>
  585. <dd><code>methodName</code> - the name of the setter</dd>
  586. <dd><code>field</code> - the field accessed.</dd>
  587. <dt><span class="throwsLabel">Throws:</span></dt>
  588. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  589. </dl>
  590. </li>
  591. </ul>
  592. <a id="delegator(javassist.CtMethod,javassist.CtClass)">
  593. <!-- -->
  594. </a>
  595. <ul class="blockList">
  596. <li class="blockList">
  597. <h4>delegator</h4>
  598. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;delegator&#8203;(<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;delegate,
  599. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)
  600. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  601. <div class="block">Creates a method forwarding to a delegate in
  602. a super class. The created method calls a method specified
  603. by <code>delegate</code> with all the parameters passed to the
  604. created method. If the delegate method returns a value,
  605. the created method returns that value to the caller.
  606. The delegate method must be declared in a super class.
  607. <p>The following method is an example of the created method.
  608. <pre>
  609. int f(int p, int q) {
  610. return super.f(p, q);
  611. }</pre>
  612. <p>The name of the created method can be changed by
  613. <code>setName()</code>.</div>
  614. <dl>
  615. <dt><span class="paramLabel">Parameters:</span></dt>
  616. <dd><code>delegate</code> - the method that the created method forwards to.</dd>
  617. <dd><code>declaring</code> - the class to which the created method is
  618. added.</dd>
  619. <dt><span class="throwsLabel">Throws:</span></dt>
  620. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  621. </dl>
  622. </li>
  623. </ul>
  624. <a id="wrapped(javassist.CtClass,java.lang.String,javassist.CtClass[],javassist.CtClass[],javassist.CtMethod,javassist.CtMethod.ConstParameter,javassist.CtClass)">
  625. <!-- -->
  626. </a>
  627. <ul class="blockListLast">
  628. <li class="blockList">
  629. <h4>wrapped</h4>
  630. <pre class="methodSignature">public static&nbsp;<a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;wrapped&#8203;(<a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;returnType,
  631. java.lang.String&nbsp;mname,
  632. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;parameterTypes,
  633. <a href="CtClass.html" title="class in javassist">CtClass</a>[]&nbsp;exceptionTypes,
  634. <a href="CtMethod.html" title="class in javassist">CtMethod</a>&nbsp;body,
  635. <a href="CtMethod.ConstParameter.html" title="class in javassist">CtMethod.ConstParameter</a>&nbsp;constParam,
  636. <a href="CtClass.html" title="class in javassist">CtClass</a>&nbsp;declaring)
  637. throws <a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
  638. <div class="block">Creates a wrapped method. The wrapped method receives parameters
  639. in the form of an array of <code>Object</code>.
  640. <p>The body of the created method is a copy of the body of the method
  641. specified by <code>body</code>. However, it is wrapped in
  642. parameter-conversion code.
  643. <p>The method specified by <code>body</code> must have this singature:
  644. <pre>Object method(Object[] params, &lt;type&gt; cvalue)</pre>
  645. <p>The type of the <code>cvalue</code> depends on
  646. <code>constParam</code>.
  647. If <code>constParam</code> is <code>null</code>, the signature
  648. must be:
  649. <pre>Object method(Object[] params)</pre>
  650. <p>The method body copied from <code>body</code> is wrapped in
  651. parameter-conversion code, which converts parameters specified by
  652. <code>parameterTypes</code> into an array of <code>Object</code>.
  653. The returned value is also converted from the <code>Object</code>
  654. type to the type specified by <code>returnType</code>. Thus,
  655. the resulting method body is as follows:
  656. <pre>
  657. Object[] params = new Object[] { p0, p1, ... };
  658. &lt;<i>type</i>&gt; cvalue = &lt;<i>constant-value</i>&gt;;
  659. <i>... copied method body ...</i>
  660. Object result = &lt;<i>returned value</i>&gt;
  661. return (<i>&lt;returnType&gt;</i>)result;
  662. </pre>
  663. <p>The variables <code>p0</code>, <code>p2</code>, ... represent
  664. formal parameters of the created method.
  665. The value of <code>cvalue</code> is specified by
  666. <code>constParam</code>.
  667. <p>If the type of a parameter or a returned value is a primitive
  668. type, then the value is converted into a wrapper object such as
  669. <code>java.lang.Integer</code>. If the type of the returned value
  670. is <code>void</code>, the returned value is discarded.
  671. <p><i>Example:</i>
  672. <pre>
  673. ClassPool pool = ... ;
  674. CtClass vec = pool.makeClass("intVector");
  675. vec.setSuperclass(pool.get("java.util.Vector"));
  676. CtMethod addMethod = pool.getMethod("Sample", "add0");
  677. CtClass[] argTypes = { CtClass.intType };
  678. CtMethod m = CtNewMethod.wrapped(CtClass.voidType, "add", argTypes,
  679. null, addMethod, null, vec);
  680. vec.addMethod(m);</pre>
  681. <p>where the class <code>Sample</code> is as follows:
  682. <pre>public class Sample extends java.util.Vector {
  683. public Object add0(Object[] args) {
  684. super.addElement(args[0]);
  685. return null;
  686. }
  687. }</pre>
  688. <p>This program produces a class <code>intVector</code>:
  689. <pre>public class intVector extends java.util.Vector {
  690. public void add(int p0) {
  691. Object[] args = new Object[] { p0 };
  692. // begin of the copied body
  693. super.addElement(args[0]);
  694. Object result = null;
  695. // end
  696. }
  697. }</pre>
  698. <p>Note that the type of the parameter to <code>add()</code> depends
  699. only on the value of <code>argTypes</code> passed to
  700. <code>CtNewMethod.wrapped()</code>. Thus, it is easy to
  701. modify this program to produce a
  702. <code>StringVector</code> class, which is a vector containing
  703. only <code>String</code> objects, and other vector classes.</div>
  704. <dl>
  705. <dt><span class="paramLabel">Parameters:</span></dt>
  706. <dd><code>returnType</code> - the type of the returned value.</dd>
  707. <dd><code>mname</code> - the method name.</dd>
  708. <dd><code>parameterTypes</code> - a list of the parameter types.</dd>
  709. <dd><code>exceptionTypes</code> - a list of the exception types.</dd>
  710. <dd><code>body</code> - the method body
  711. (must not be a static method).</dd>
  712. <dd><code>constParam</code> - the constant parameter
  713. (maybe <code>null</code>).</dd>
  714. <dd><code>declaring</code> - the class to which the created method is
  715. added.</dd>
  716. <dt><span class="throwsLabel">Throws:</span></dt>
  717. <dd><code><a href="CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
  718. </dl>
  719. </li>
  720. </ul>
  721. </li>
  722. </ul>
  723. </section>
  724. </li>
  725. </ul>
  726. </div>
  727. </div>
  728. </main>
  729. <!-- ========= END OF CLASS DATA ========= -->
  730. <footer role="contentinfo">
  731. <nav role="navigation">
  732. <!-- ======= START OF BOTTOM NAVBAR ====== -->
  733. <div class="bottomNav"><a id="navbar.bottom">
  734. <!-- -->
  735. </a>
  736. <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
  737. <a id="navbar.bottom.firstrow">
  738. <!-- -->
  739. </a>
  740. <ul class="navList" title="Navigation">
  741. <li><a href="../index.html">Overview</a></li>
  742. <li><a href="package-summary.html">Package</a></li>
  743. <li class="navBarCell1Rev">Class</li>
  744. <li><a href="class-use/CtNewMethod.html">Use</a></li>
  745. <li><a href="package-tree.html">Tree</a></li>
  746. <li><a href="../deprecated-list.html">Deprecated</a></li>
  747. <li><a href="../index-all.html">Index</a></li>
  748. </ul>
  749. </div>
  750. <div class="subNav">
  751. <ul class="navList" id="allclasses_navbar_bottom">
  752. <li><a href="../allclasses.html">All&nbsp;Classes</a></li>
  753. </ul>
  754. <div>
  755. <script type="text/javascript"><!--
  756. allClassesLink = document.getElementById("allclasses_navbar_bottom");
  757. if(window==top) {
  758. allClassesLink.style.display = "block";
  759. }
  760. else {
  761. allClassesLink.style.display = "none";
  762. }
  763. //-->
  764. </script>
  765. <noscript>
  766. <div>JavaScript is disabled on your browser.</div>
  767. </noscript>
  768. </div>
  769. <div>
  770. <ul class="subNavList">
  771. <li>Summary:&nbsp;</li>
  772. <li>Nested&nbsp;|&nbsp;</li>
  773. <li>Field&nbsp;|&nbsp;</li>
  774. <li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
  775. <li><a href="#method.summary">Method</a></li>
  776. </ul>
  777. <ul class="subNavList">
  778. <li>Detail:&nbsp;</li>
  779. <li>Field&nbsp;|&nbsp;</li>
  780. <li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
  781. <li><a href="#method.detail">Method</a></li>
  782. </ul>
  783. </div>
  784. <a id="skip.navbar.bottom">
  785. <!-- -->
  786. </a></div>
  787. <!-- ======== END OF BOTTOM NAVBAR ======= -->
  788. </nav>
  789. <p class="legalCopy"><small><i>Javassist, a Java-bytecode translator toolkit.<br>
  790. Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i></small></p>
  791. </footer>
  792. </body>
  793. </html>