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.java 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later,
  9. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist;
  17. import javassist.bytecode.BadBytecode;
  18. import javassist.bytecode.CodeAttribute;
  19. import javassist.bytecode.CodeIterator;
  20. import javassist.bytecode.ConstPool;
  21. import javassist.bytecode.MethodInfo;
  22. import javassist.convert.TransformAccessArrayField;
  23. import javassist.convert.TransformAfter;
  24. import javassist.convert.TransformBefore;
  25. import javassist.convert.TransformCall;
  26. import javassist.convert.TransformCallToStatic;
  27. import javassist.convert.TransformFieldAccess;
  28. import javassist.convert.TransformNew;
  29. import javassist.convert.TransformNewClass;
  30. import javassist.convert.TransformReadField;
  31. import javassist.convert.TransformWriteField;
  32. import javassist.convert.Transformer;
  33. /**
  34. * Simple translator of method bodies
  35. * (also see the <code>javassist.expr</code> package).
  36. *
  37. * <p>Instances of this class specifies how to instrument of the
  38. * bytecodes representing a method body. They are passed to
  39. * <code>CtClass.instrument()</code> or
  40. * <code>CtMethod.instrument()</code> as a parameter.
  41. *
  42. * <p>Example:
  43. * <pre>
  44. * ClassPool cp = ClassPool.getDefault();
  45. * CtClass point = cp.get("Point");
  46. * CtClass singleton = cp.get("Singleton");
  47. * CtClass client = cp.get("Client");
  48. * CodeConverter conv = new CodeConverter();
  49. * conv.replaceNew(point, singleton, "makePoint");
  50. * client.instrument(conv);
  51. * </pre>
  52. *
  53. * <p>This program substitutes "<code>Singleton.makePoint()</code>"
  54. * for all occurrences of "<code>new Point()</code>"
  55. * appearing in methods declared in a <code>Client</code> class.
  56. *
  57. * @see javassist.CtClass#instrument(CodeConverter)
  58. * @see javassist.CtMethod#instrument(CodeConverter)
  59. * @see javassist.expr.ExprEditor
  60. */
  61. public class CodeConverter {
  62. protected Transformer transformers = null;
  63. /**
  64. * Modify a method body so that instantiation of the specified class
  65. * is replaced with a call to the specified static method. For example,
  66. * <code>replaceNew(ctPoint, ctSingleton, "createPoint")</code>
  67. * (where <code>ctPoint</code> and <code>ctSingleton</code> are
  68. * compile-time classes for class <code>Point</code> and class
  69. * <code>Singleton</code>, respectively)
  70. * replaces all occurrences of:
  71. *
  72. * <pre>new Point(x, y)</pre>
  73. *
  74. * in the method body with:
  75. *
  76. * <pre>Singleton.createPoint(x, y)</pre>
  77. *
  78. * <p>This enables to intercept instantiation of <code>Point</code>
  79. * and change the samentics. For example, the following
  80. * <code>createPoint()</code> implements the singleton pattern:
  81. *
  82. * <pre>public static Point createPoint(int x, int y) {
  83. * if (aPoint == null)
  84. * aPoint = new Point(x, y);
  85. * return aPoint;
  86. * }
  87. * </pre>
  88. *
  89. * <p>The static method call substituted for the original <code>new</code>
  90. * expression must be
  91. * able to receive the same set of parameters as the original
  92. * constructor. If there are multiple constructors with different
  93. * parameter types, then there must be multiple static methods
  94. * with the same name but different parameter types.
  95. *
  96. * <p>The return type of the substituted static method must be
  97. * the exactly same as the type of the instantiated class specified by
  98. * <code>newClass</code>.
  99. *
  100. * @param newClass the instantiated class.
  101. * @param calledClass the class in which the static method is
  102. * declared.
  103. * @param calledMethod the name of the static method.
  104. */
  105. public void replaceNew(CtClass newClass,
  106. CtClass calledClass, String calledMethod) {
  107. transformers = new TransformNew(transformers, newClass.getName(),
  108. calledClass.getName(), calledMethod);
  109. }
  110. /**
  111. * Modify a method body so that instantiation of the class
  112. * specified by <code>oldClass</code>
  113. * is replaced with instantiation of another class <code>newClass</code>.
  114. * For example,
  115. * <code>replaceNew(ctPoint, ctPoint2)</code>
  116. * (where <code>ctPoint</code> and <code>ctPoint2</code> are
  117. * compile-time classes for class <code>Point</code> and class
  118. * <code>Point2</code>, respectively)
  119. * replaces all occurrences of:
  120. *
  121. * <pre>new Point(x, y)</pre>
  122. *
  123. * in the method body with:
  124. *
  125. * <pre>new Point2(x, y)</pre>
  126. *
  127. * <p>Note that <code>Point2</code> must be type-compatible with <code>Point</code>.
  128. * It must have the same set of methods, fields, and constructors as the
  129. * replaced class.
  130. */
  131. public void replaceNew(CtClass oldClass, CtClass newClass) {
  132. transformers = new TransformNewClass(transformers, oldClass.getName(),
  133. newClass.getName());
  134. }
  135. /**
  136. * Modify a method body so that field read/write expressions access
  137. * a different field from the original one.
  138. *
  139. * <p>Note that this method changes only the filed name and the class
  140. * declaring the field; the type of the target object does not change.
  141. * Therefore, the substituted field must be declared in the same class
  142. * or a superclass of the original class.
  143. *
  144. * <p>Also, <code>clazz</code> and <code>newClass</code> must specify
  145. * the class directly declaring the field. They must not specify
  146. * a subclass of that class.
  147. *
  148. * @param field the originally accessed field.
  149. * @param newClass the class declaring the substituted field.
  150. * @param newFieldname the name of the substituted field.
  151. */
  152. public void redirectFieldAccess(CtField field,
  153. CtClass newClass, String newFieldname) {
  154. transformers = new TransformFieldAccess(transformers, field,
  155. newClass.getName(),
  156. newFieldname);
  157. }
  158. /**
  159. * Modify a method body so that an expression reading the specified
  160. * field is replaced with a call to the specified <i>static</i> method.
  161. * This static method receives the target object of the original
  162. * read expression as a parameter. It must return a value of
  163. * the same type as the field.
  164. *
  165. * <p>For example, the program below
  166. *
  167. * <pre>Point p = new Point();
  168. * int newX = p.x + 3;</pre>
  169. *
  170. * <p>can be translated into:
  171. *
  172. * <pre>Point p = new Point();
  173. * int newX = Accessor.readX(p) + 3;</pre>
  174. *
  175. * <p>where
  176. *
  177. * <pre>public class Accessor {
  178. * public static int readX(Object target) { ... }
  179. * }</pre>
  180. *
  181. * <p>The type of the parameter of <code>readX()</code> must
  182. * be <code>java.lang.Object</code> independently of the actual
  183. * type of <code>target</code>. The return type must be the same
  184. * as the field type.
  185. *
  186. * @param field the field.
  187. * @param calledClass the class in which the static method is
  188. * declared.
  189. * @param calledMethod the name of the static method.
  190. */
  191. public void replaceFieldRead(CtField field,
  192. CtClass calledClass, String calledMethod) {
  193. transformers = new TransformReadField(transformers, field,
  194. calledClass.getName(),
  195. calledMethod);
  196. }
  197. /**
  198. * Modify a method body so that an expression writing the specified
  199. * field is replaced with a call to the specified static method.
  200. * This static method receives two parameters: the target object of
  201. * the original
  202. * write expression and the assigned value. The return type of the
  203. * static method is <code>void</code>.
  204. *
  205. * <p>For example, the program below
  206. *
  207. * <pre>Point p = new Point();
  208. * p.x = 3;</pre>
  209. *
  210. * <p>can be translated into:
  211. *
  212. * <pre>Point p = new Point();
  213. * Accessor.writeX(3);</pre>
  214. *
  215. * <p>where
  216. *
  217. * <pre>public class Accessor {
  218. * public static void writeX(Object target, int value) { ... }
  219. * }</pre>
  220. *
  221. * <p>The type of the first parameter of <code>writeX()</code> must
  222. * be <code>java.lang.Object</code> independently of the actual
  223. * type of <code>target</code>. The type of the second parameter
  224. * is the same as the field type.
  225. *
  226. * @param field the field.
  227. * @param calledClass the class in which the static method is
  228. * declared.
  229. * @param calledMethod the name of the static method.
  230. */
  231. public void replaceFieldWrite(CtField field,
  232. CtClass calledClass, String calledMethod) {
  233. transformers = new TransformWriteField(transformers, field,
  234. calledClass.getName(),
  235. calledMethod);
  236. }
  237. /**
  238. * Modify a method body, so that ALL accesses to an array are replaced with
  239. * calls to static methods within another class. In the case of reading an
  240. * element from the array, this is replaced with a call to a static method with
  241. * the array and the index as arguments, the return value is the value read from
  242. * the array. If writing to an array, this is replaced with a call to a static
  243. * method with the array, index and new value as parameters, the return value of
  244. * the static method is <code>void</code>.
  245. *
  246. * <p>The <code>calledClass</code> parameter is the class containing the static methods to be used
  247. * for array replacement. The <code>names</code> parameter points to an implementation of
  248. * <code>ArrayAccessReplacementMethodNames</code> which specifies the names of the method to be
  249. * used for access for each type of array. For example reading from an <code>int[]</code> will
  250. * require a different method than if writing to an <code>int[]</code>, and writing to a <code>long[]</code>
  251. * will require a different method than if writing to a <code>byte[]</code>. If the implementation
  252. * of <code>ArrayAccessReplacementMethodNames</code> does not contain the name for access for a
  253. * type of array, that access is not replaced.
  254. *
  255. * <p>A default implementation of <code>ArrayAccessReplacementMethodNames</code> called
  256. * <code>DefaultArrayAccessReplacementMethodNames</code> has been provided and is what is used in the
  257. * following example. This also assumes that <code>'foo.ArrayAdvisor'</code> is the name of the
  258. * <code>CtClass</code> passed in.
  259. *
  260. * <p>If we have the following class:
  261. * <pre>class POJO{
  262. * int[] ints = new int[]{1, 2, 3, 4, 5};
  263. * long[] longs = new int[]{10, 20, 30};
  264. * Object objects = new Object[]{true, false};
  265. * Integer[] integers = new Integer[]{new Integer(10)};
  266. * }
  267. * </pre>
  268. * and this is accessed as:
  269. * <pre>POJO p = new POJO();
  270. *
  271. * //Write to int array
  272. * p.ints[2] = 7;
  273. *
  274. * //Read from int array
  275. * int i = p.ints[2];
  276. *
  277. * //Write to long array
  278. * p.longs[2] = 1000L;
  279. *
  280. * //Read from long array
  281. * long l = p.longs[2];
  282. *
  283. * //Write to Object array
  284. * p.objects[2] = "Hello";
  285. *
  286. * //Read from Object array
  287. * Object o = p.objects[2];
  288. *
  289. * //Write to Integer array
  290. * Integer integer = new Integer(5);
  291. * p.integers[0] = integer;
  292. *
  293. * //Read from Object array
  294. * integer = p.integers[0];
  295. * </pre>
  296. *
  297. * Following instrumentation we will have
  298. * <pre>POJO p = new POJO();
  299. *
  300. * //Write to int array
  301. * ArrayAdvisor.arrayWriteInt(p.ints, 2, 7);
  302. *
  303. * //Read from int array
  304. * int i = ArrayAdvisor.arrayReadInt(p.ints, 2);
  305. *
  306. * //Write to long array
  307. * ArrayAdvisor.arrayWriteLong(p.longs, 2, 1000L);
  308. *
  309. * //Read from long array
  310. * long l = ArrayAdvisor.arrayReadLong(p.longs, 2);
  311. *
  312. * //Write to Object array
  313. * ArrayAdvisor.arrayWriteObject(p.objects, 2, "Hello");
  314. *
  315. * //Read from Object array
  316. * Object o = ArrayAdvisor.arrayReadObject(p.objects, 2);
  317. *
  318. * //Write to Integer array
  319. * Integer integer = new Integer(5);
  320. * ArrayAdvisor.arrayWriteObject(p.integers, 0, integer);
  321. *
  322. * //Read from Object array
  323. * integer = ArrayAdvisor.arrayWriteObject(p.integers, 0);
  324. * </pre>
  325. *
  326. * @see DefaultArrayAccessReplacementMethodNames
  327. *
  328. * @param calledClass the class containing the static methods.
  329. * @param names contains the names of the methods to replace
  330. * the different kinds of array access with.
  331. */
  332. public void replaceArrayAccess(CtClass calledClass, ArrayAccessReplacementMethodNames names)
  333. throws NotFoundException
  334. {
  335. transformers = new TransformAccessArrayField(transformers, calledClass.getName(), names);
  336. }
  337. /**
  338. * Modify method invocations in a method body so that a different
  339. * method will be invoked.
  340. *
  341. * <p>Note that the target object, the parameters, or
  342. * the type of invocation
  343. * (static method call, interface call, or private method call)
  344. * are not modified. Only the method name is changed. The substituted
  345. * method must have the same signature that the original one has.
  346. * If the original method is a static method, the substituted method
  347. * must be static.
  348. *
  349. * @param origMethod original method
  350. * @param substMethod substituted method
  351. */
  352. public void redirectMethodCall(CtMethod origMethod,
  353. CtMethod substMethod)
  354. throws CannotCompileException
  355. {
  356. String d1 = origMethod.getMethodInfo2().getDescriptor();
  357. String d2 = substMethod.getMethodInfo2().getDescriptor();
  358. if (!d1.equals(d2))
  359. throw new CannotCompileException("signature mismatch: "
  360. + substMethod.getLongName());
  361. int mod1 = origMethod.getModifiers();
  362. int mod2 = substMethod.getModifiers();
  363. if (Modifier.isStatic(mod1) != Modifier.isStatic(mod2)
  364. || (Modifier.isPrivate(mod1) && !Modifier.isPrivate(mod2))
  365. || origMethod.getDeclaringClass().isInterface()
  366. != substMethod.getDeclaringClass().isInterface())
  367. throw new CannotCompileException("invoke-type mismatch "
  368. + substMethod.getLongName());
  369. transformers = new TransformCall(transformers, origMethod,
  370. substMethod);
  371. }
  372. /**
  373. * Correct invocations to a method that has been renamed.
  374. * If a method is renamed, calls to that method must be also
  375. * modified so that the method with the new name will be called.
  376. *
  377. * <p>The method must be declared in the same class before and
  378. * after it is renamed.
  379. *
  380. * <p>Note that the target object, the parameters, or
  381. * the type of invocation
  382. * (static method call, interface call, or private method call)
  383. * are not modified. Only the method name is changed.
  384. *
  385. * @param oldMethodName the old name of the method.
  386. * @param newMethod the method with the new name.
  387. * @see javassist.CtMethod#setName(String)
  388. */
  389. public void redirectMethodCall(String oldMethodName,
  390. CtMethod newMethod)
  391. throws CannotCompileException
  392. {
  393. transformers
  394. = new TransformCall(transformers, oldMethodName, newMethod);
  395. }
  396. /**
  397. * Redirect non-static method invocations in a method body to a static
  398. * method. The return type must be same with the originally invoked method.
  399. * As parameters, the static method receives
  400. * the target object and all the parameters to the originally invoked
  401. * method. For example, if the originally invoked method is
  402. * <code>move()</code>:
  403. *
  404. * <pre>class Point {
  405. * Point move(int x, int y) { ... }
  406. * }</pre>
  407. *
  408. * <p>Then the static method must be something like this:
  409. *
  410. * <pre>class Verbose {
  411. * static Point print(Point target, int x, int y) { ... }
  412. * }</pre>
  413. *
  414. * <p>The <code>CodeConverter</code> would translate bytecode
  415. * equivalent to:
  416. *
  417. * <pre>Point p2 = p.move(x + y, 0);</pre>
  418. *
  419. * <p>into the bytecode equivalent to:
  420. *
  421. * <pre>Point p2 = Verbose.print(p, x + y, 0);</pre>
  422. *
  423. * @param origMethod original method
  424. * @param staticMethod static method
  425. */
  426. public void redirectMethodCallToStatic(CtMethod origMethod,
  427. CtMethod staticMethod) {
  428. transformers = new TransformCallToStatic(transformers, origMethod,
  429. staticMethod);
  430. }
  431. /**
  432. * Insert a call to another method before an existing method call.
  433. * That "before" method must be static. The return type must be
  434. * <code>void</code>. As parameters, the before method receives
  435. * the target object and all the parameters to the originally invoked
  436. * method. For example, if the originally invoked method is
  437. * <code>move()</code>:
  438. *
  439. * <pre>class Point {
  440. * Point move(int x, int y) { ... }
  441. * }</pre>
  442. *
  443. * <p>Then the before method must be something like this:
  444. *
  445. * <pre>class Verbose {
  446. * static void print(Point target, int x, int y) { ... }
  447. * }</pre>
  448. *
  449. * <p>The <code>CodeConverter</code> would translate bytecode
  450. * equivalent to:
  451. *
  452. * <pre>Point p2 = p.move(x + y, 0);</pre>
  453. *
  454. * <p>into the bytecode equivalent to:
  455. *
  456. * <pre>int tmp1 = x + y;
  457. * int tmp2 = 0;
  458. * Verbose.print(p, tmp1, tmp2);
  459. * Point p2 = p.move(tmp1, tmp2);</pre>
  460. *
  461. * @param origMethod the method originally invoked.
  462. * @param beforeMethod the method invoked before
  463. * <code>origMethod</code>.
  464. */
  465. public void insertBeforeMethod(CtMethod origMethod,
  466. CtMethod beforeMethod)
  467. throws CannotCompileException
  468. {
  469. try {
  470. transformers = new TransformBefore(transformers, origMethod,
  471. beforeMethod);
  472. }
  473. catch (NotFoundException e) {
  474. throw new CannotCompileException(e);
  475. }
  476. }
  477. /**
  478. * Inserts a call to another method after an existing method call.
  479. * That "after" method must be static. The return type must be
  480. * <code>void</code>. As parameters, the after method receives
  481. * the target object and all the parameters to the originally invoked
  482. * method. For example, if the originally invoked method is
  483. * <code>move()</code>:
  484. *
  485. * <pre>class Point {
  486. * Point move(int x, int y) { ... }
  487. * }</pre>
  488. *
  489. * <p>Then the after method must be something like this:
  490. *
  491. * <pre>class Verbose {
  492. * static void print(Point target, int x, int y) { ... }
  493. * }</pre>
  494. *
  495. * <p>The <code>CodeConverter</code> would translate bytecode
  496. * equivalent to:
  497. *
  498. * <pre>Point p2 = p.move(x + y, 0);</pre>
  499. *
  500. * <p>into the bytecode equivalent to:
  501. *
  502. * <pre>
  503. * int tmp1 = x + y;
  504. * int tmp2 = 0;
  505. * Point p2 = p.move(tmp1, tmp2);
  506. * Verbose.print(p, tmp1, tmp2);</pre>
  507. *
  508. * @param origMethod the method originally invoked.
  509. * @param afterMethod the method invoked after
  510. * <code>origMethod</code>.
  511. */
  512. public void insertAfterMethod(CtMethod origMethod,
  513. CtMethod afterMethod)
  514. throws CannotCompileException
  515. {
  516. try {
  517. transformers = new TransformAfter(transformers, origMethod,
  518. afterMethod);
  519. }
  520. catch (NotFoundException e) {
  521. throw new CannotCompileException(e);
  522. }
  523. }
  524. /**
  525. * Performs code conversion.
  526. */
  527. protected void doit(CtClass clazz, MethodInfo minfo, ConstPool cp)
  528. throws CannotCompileException
  529. {
  530. Transformer t;
  531. CodeAttribute codeAttr = minfo.getCodeAttribute();
  532. if (codeAttr == null || transformers == null)
  533. return;
  534. for (t = transformers; t != null; t = t.getNext())
  535. t.initialize(cp, clazz, minfo);
  536. CodeIterator iterator = codeAttr.iterator();
  537. while (iterator.hasNext()) {
  538. try {
  539. int pos = iterator.next();
  540. for (t = transformers; t != null; t = t.getNext())
  541. pos = t.transform(clazz, pos, iterator, cp);
  542. }
  543. catch (BadBytecode e) {
  544. throw new CannotCompileException(e);
  545. }
  546. }
  547. int locals = 0;
  548. int stack = 0;
  549. for (t = transformers; t != null; t = t.getNext()) {
  550. int s = t.extraLocals();
  551. if (s > locals)
  552. locals = s;
  553. s = t.extraStack();
  554. if (s > stack)
  555. stack = s;
  556. }
  557. for (t = transformers; t != null; t = t.getNext())
  558. t.clean();
  559. if (locals > 0)
  560. codeAttr.setMaxLocals(codeAttr.getMaxLocals() + locals);
  561. if (stack > 0)
  562. codeAttr.setMaxStack(codeAttr.getMaxStack() + stack);
  563. try {
  564. minfo.rebuildStackMapIf6(clazz.getClassPool(),
  565. clazz.getClassFile2());
  566. }
  567. catch (BadBytecode b) {
  568. throw new CannotCompileException(b.getMessage(), b);
  569. }
  570. }
  571. /**
  572. * Interface containing the method names to be used
  573. * as array access replacements.
  574. *
  575. * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
  576. * @version $Revision: 1.16 $
  577. */
  578. public interface ArrayAccessReplacementMethodNames
  579. {
  580. /**
  581. * Returns the name of a static method with the signature
  582. * <code>(Ljava/lang/Object;I)B</code> to replace reading from a byte[].
  583. */
  584. String byteOrBooleanRead();
  585. /**
  586. * Returns the name of a static method with the signature
  587. * <code>(Ljava/lang/Object;IB)V</code> to replace writing to a byte[].
  588. */
  589. String byteOrBooleanWrite();
  590. /**
  591. * @return the name of a static method with the signature
  592. * <code>(Ljava/lang/Object;I)C</code> to replace reading from a char[].
  593. */
  594. String charRead();
  595. /**
  596. * Returns the name of a static method with the signature
  597. * <code>(Ljava/lang/Object;IC)V</code> to replace writing to a byte[].
  598. */
  599. String charWrite();
  600. /**
  601. * Returns the name of a static method with the signature
  602. * <code>(Ljava/lang/Object;I)D</code> to replace reading from a double[].
  603. */
  604. String doubleRead();
  605. /**
  606. * Returns the name of a static method with the signature
  607. * <code>(Ljava/lang/Object;ID)V</code> to replace writing to a double[].
  608. */
  609. String doubleWrite();
  610. /**
  611. * Returns the name of a static method with the signature
  612. * <code>(Ljava/lang/Object;I)F</code> to replace reading from a float[].
  613. */
  614. String floatRead();
  615. /**
  616. * Returns the name of a static method with the signature
  617. * <code>(Ljava/lang/Object;IF)V</code> to replace writing to a float[].
  618. */
  619. String floatWrite();
  620. /**
  621. * Returns the name of a static method with the signature
  622. * <code>(Ljava/lang/Object;I)I</code> to replace reading from a int[].
  623. */
  624. String intRead();
  625. /**
  626. * Returns the name of a static method with the signature
  627. * <code>(Ljava/lang/Object;II)V</code> to replace writing to a int[].
  628. */
  629. String intWrite();
  630. /**
  631. * Returns the name of a static method with the signature
  632. * <code>(Ljava/lang/Object;I)J</code> to replace reading from a long[].
  633. */
  634. String longRead();
  635. /**
  636. * Returns the name of a static method with the signature
  637. * <code>(Ljava/lang/Object;IJ)V</code> to replace writing to a long[].
  638. */
  639. String longWrite();
  640. /**
  641. * Returns the name of a static method with the signature
  642. * <code>(Ljava/lang/Object;I)Ljava/lang/Object;</code>
  643. * to replace reading from a Object[] (or any subclass of object).
  644. */
  645. String objectRead();
  646. /**
  647. * Returns the name of a static method with the signature
  648. * <code>(Ljava/lang/Object;ILjava/lang/Object;)V</code>
  649. * to replace writing to a Object[] (or any subclass of object).
  650. */
  651. String objectWrite();
  652. /**
  653. * Returns the name of a static method with the signature
  654. * <code>(Ljava/lang/Object;I)S</code> to replace reading from a short[].
  655. */
  656. String shortRead();
  657. /**
  658. * Returns the name of a static method with the signature
  659. * <code>(Ljava/lang/Object;IS)V</code> to replace writing to a short[].
  660. */
  661. String shortWrite();
  662. }
  663. /**
  664. * Default implementation of the <code>ArrayAccessReplacementMethodNames</code>
  665. * interface giving default values for method names to be used for replacing
  666. * accesses to array elements.
  667. *
  668. * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
  669. * @version $Revision: 1.16 $
  670. */
  671. public static class DefaultArrayAccessReplacementMethodNames
  672. implements ArrayAccessReplacementMethodNames
  673. {
  674. /**
  675. * Returns "arrayReadByteOrBoolean" as the name of the static method with the signature
  676. * (Ljava/lang/Object;I)B to replace reading from a byte[].
  677. */
  678. @Override
  679. public String byteOrBooleanRead()
  680. {
  681. return "arrayReadByteOrBoolean";
  682. }
  683. /**
  684. * Returns "arrayWriteByteOrBoolean" as the name of the static method with the signature
  685. * (Ljava/lang/Object;IB)V to replace writing to a byte[].
  686. */
  687. @Override
  688. public String byteOrBooleanWrite()
  689. {
  690. return "arrayWriteByteOrBoolean";
  691. }
  692. /**
  693. * Returns "arrayReadChar" as the name of the static method with the signature
  694. * (Ljava/lang/Object;I)C to replace reading from a char[].
  695. */
  696. @Override
  697. public String charRead()
  698. {
  699. return "arrayReadChar";
  700. }
  701. /**
  702. * Returns "arrayWriteChar" as the name of the static method with the signature
  703. * (Ljava/lang/Object;IC)V to replace writing to a byte[].
  704. */
  705. @Override
  706. public String charWrite()
  707. {
  708. return "arrayWriteChar";
  709. }
  710. /**
  711. * Returns "arrayReadDouble" as the name of the static method with the signature
  712. * (Ljava/lang/Object;I)D to replace reading from a double[].
  713. */
  714. @Override
  715. public String doubleRead()
  716. {
  717. return "arrayReadDouble";
  718. }
  719. /**
  720. * Returns "arrayWriteDouble" as the name of the static method with the signature
  721. * (Ljava/lang/Object;ID)V to replace writing to a double[].
  722. */
  723. @Override
  724. public String doubleWrite()
  725. {
  726. return "arrayWriteDouble";
  727. }
  728. /**
  729. * Returns "arrayReadFloat" as the name of the static method with the signature
  730. * (Ljava/lang/Object;I)F to replace reading from a float[].
  731. */
  732. @Override
  733. public String floatRead()
  734. {
  735. return "arrayReadFloat";
  736. }
  737. /**
  738. * Returns "arrayWriteFloat" as the name of the static method with the signature
  739. * (Ljava/lang/Object;IF)V to replace writing to a float[].
  740. */
  741. @Override
  742. public String floatWrite()
  743. {
  744. return "arrayWriteFloat";
  745. }
  746. /**
  747. * Returns "arrayReadInt" as the name of the static method with the signature
  748. * (Ljava/lang/Object;I)I to replace reading from a int[].
  749. */
  750. @Override
  751. public String intRead()
  752. {
  753. return "arrayReadInt";
  754. }
  755. /**
  756. * Returns "arrayWriteInt" as the name of the static method with the signature
  757. * (Ljava/lang/Object;II)V to replace writing to a int[].
  758. */
  759. @Override
  760. public String intWrite()
  761. {
  762. return "arrayWriteInt";
  763. }
  764. /**
  765. * Returns "arrayReadLong" as the name of the static method with the signature
  766. * (Ljava/lang/Object;I)J to replace reading from a long[].
  767. */
  768. @Override
  769. public String longRead()
  770. {
  771. return "arrayReadLong";
  772. }
  773. /**
  774. * Returns "arrayWriteLong" as the name of the static method with the signature
  775. * (Ljava/lang/Object;IJ)V to replace writing to a long[].
  776. */
  777. @Override
  778. public String longWrite()
  779. {
  780. return "arrayWriteLong";
  781. }
  782. /**
  783. * Returns "arrayReadObject" as the name of the static method with the signature
  784. * (Ljava/lang/Object;I)Ljava/lang/Object; to replace reading from a Object[] (or any subclass of object).
  785. */
  786. @Override
  787. public String objectRead()
  788. {
  789. return "arrayReadObject";
  790. }
  791. /**
  792. * Returns "arrayWriteObject" as the name of the static method with the signature
  793. * (Ljava/lang/Object;ILjava/lang/Object;)V to replace writing to a Object[] (or any subclass of object).
  794. */
  795. @Override
  796. public String objectWrite()
  797. {
  798. return "arrayWriteObject";
  799. }
  800. /**
  801. * Returns "arrayReadShort" as the name of the static method with the signature
  802. * (Ljava/lang/Object;I)S to replace reading from a short[].
  803. */
  804. @Override
  805. public String shortRead()
  806. {
  807. return "arrayReadShort";
  808. }
  809. /**
  810. * Returns "arrayWriteShort" as the name of the static method with the signature
  811. * (Ljava/lang/Object;IS)V to replace writing to a short[].
  812. */
  813. @Override
  814. public String shortWrite()
  815. {
  816. return "arrayWriteShort";
  817. }
  818. }
  819. }