123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902 |
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <!-- NewPage -->
- <html lang="en">
- <head>
- <!-- Generated by javadoc (10.0.1) on Thu Jun 21 01:52:55 JST 2018 -->
- <title>CodeConverter (Javassist API)</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="date" content="2018-06-21">
- <link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
- <link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
- <script type="text/javascript" src="../script.js"></script>
- <script type="text/javascript" src="../jquery/jszip/dist/jszip.min.js"></script>
- <script type="text/javascript" src="../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
- <!--[if IE]>
- <script type="text/javascript" src="../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
- <![endif]-->
- <script type="text/javascript" src="../jquery/jquery-1.10.2.js"></script>
- <script type="text/javascript" src="../jquery/jquery-ui.js"></script>
- </head>
- <body>
- <script type="text/javascript"><!--
- try {
- if (location.href.indexOf('is-external=true') == -1) {
- parent.document.title="CodeConverter (Javassist API)";
- }
- }
- catch(err) {
- }
- //-->
- var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10};
- var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
- var altColor = "altColor";
- var rowColor = "rowColor";
- var tableTab = "tableTab";
- var activeTableTab = "activeTableTab";
- var pathtoroot = "../";loadScripts(document, 'script');</script>
- <noscript>
- <div>JavaScript is disabled on your browser.</div>
- </noscript>
- <div class="fixedNav">
- <!-- ========= START OF TOP NAVBAR ======= -->
- <div class="topNav"><a name="navbar.top">
- <!-- -->
- </a>
- <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
- <a name="navbar.top.firstrow">
- <!-- -->
- </a>
- <ul class="navList" title="Navigation">
- <li><a href="../overview-summary.html">Overview</a></li>
- <li><a href="package-summary.html">Package</a></li>
- <li class="navBarCell1Rev">Class</li>
- <li><a href="class-use/CodeConverter.html">Use</a></li>
- <li><a href="package-tree.html">Tree</a></li>
- <li><a href="../deprecated-list.html">Deprecated</a></li>
- <li><a href="../index-all.html">Index</a></li>
- </ul>
- </div>
- <div class="subNav">
- <ul class="navList">
- <li><a href="../javassist/ClassPool.html" title="class in javassist"><span class="typeNameLink">Prev Class</span></a></li>
- <li><a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist"><span class="typeNameLink">Next Class</span></a></li>
- </ul>
- <ul class="navList">
- <li><a href="../index.html?javassist/CodeConverter.html" target="_top">Frames</a></li>
- <li><a href="CodeConverter.html" target="_top">No Frames</a></li>
- </ul>
- <ul class="navList" id="allclasses_navbar_top">
- <li><a href="../allclasses-noframe.html">All Classes</a></li>
- </ul>
- <ul class="navListSearch">
- <li><label for="search">SEARCH:</label>
- <input type="text" id="search" value="search" disabled="disabled">
- <input type="reset" id="reset" value="reset" disabled="disabled">
- </li>
- </ul>
- <div>
- <script type="text/javascript"><!--
- allClassesLink = document.getElementById("allclasses_navbar_top");
- if(window==top) {
- allClassesLink.style.display = "block";
- }
- else {
- allClassesLink.style.display = "none";
- }
- //-->
- </script>
- <noscript>
- <div>JavaScript is disabled on your browser.</div>
- </noscript>
- </div>
- <div>
- <ul class="subNavList">
- <li>Summary: </li>
- <li><a href="#nested.class.summary">Nested</a> | </li>
- <li>Field | </li>
- <li><a href="#constructor.summary">Constr</a> | </li>
- <li><a href="#method.summary">Method</a></li>
- </ul>
- <ul class="subNavList">
- <li>Detail: </li>
- <li>Field | </li>
- <li><a href="#constructor.detail">Constr</a> | </li>
- <li><a href="#method.detail">Method</a></li>
- </ul>
- </div>
- <a name="skip.navbar.top">
- <!-- -->
- </a></div>
- <!-- ========= END OF TOP NAVBAR ========= -->
- </div>
- <div class="navPadding"> </div>
- <script type="text/javascript"><!--
- $('.navPadding').css('padding-top', $('.fixedNav').css("height"));
- //-->
- </script>
- <!-- ======== START OF CLASS DATA ======== -->
- <div class="header">
- <div class="subTitle"><span class="packageLabelInType">Package</span> <a href="../javassist/package-summary.html">javassist</a></div>
- <h2 title="Class CodeConverter" class="title">Class CodeConverter</h2>
- </div>
- <div class="contentContainer">
- <ul class="inheritance">
- <li>java.lang.Object</li>
- <li>
- <ul class="inheritance">
- <li>javassist.CodeConverter</li>
- </ul>
- </li>
- </ul>
- <div class="description">
- <ul class="blockList">
- <li class="blockList">
- <hr>
- <pre>public class <span class="typeNameLabel">CodeConverter</span>
- extends java.lang.Object</pre>
- <div class="block">Simple translator of method bodies
- (also see the <code>javassist.expr</code> package).
-
- <p>Instances of this class specifies how to instrument of the
- bytecodes representing a method body. They are passed to
- <code>CtClass.instrument()</code> or
- <code>CtMethod.instrument()</code> as a parameter.
-
- <p>Example:
- <pre>
- ClassPool cp = ClassPool.getDefault();
- CtClass point = cp.get("Point");
- CtClass singleton = cp.get("Singleton");
- CtClass client = cp.get("Client");
- CodeConverter conv = new CodeConverter();
- conv.replaceNew(point, singleton, "makePoint");
- client.instrument(conv);
- </pre>
-
- <p>This program substitutes "<code>Singleton.makePoint()</code>"
- for all occurrences of "<code>new Point()</code>"
- appearing in methods declared in a <code>Client</code> class.</div>
- <dl>
- <dt><span class="seeLabel">See Also:</span></dt>
- <dd><a href="../javassist/CtClass.html#instrument-javassist.CodeConverter-"><code>CtClass.instrument(CodeConverter)</code></a>,
- <a href="../javassist/CtBehavior.html#instrument-javassist.CodeConverter-"><code>CtBehavior.instrument(CodeConverter)</code></a>,
- <a href="../javassist/expr/ExprEditor.html" title="class in javassist.expr"><code>ExprEditor</code></a></dd>
- </dl>
- </li>
- </ul>
- </div>
- <div class="summary">
- <ul class="blockList">
- <li class="blockList">
- <!-- ======== NESTED CLASS SUMMARY ======== -->
- <ul class="blockList">
- <li class="blockList"><a name="nested.class.summary">
- <!-- -->
- </a>
- <h3>Nested Class Summary</h3>
- <table class="memberSummary" summary="Nested Class Summary table, listing nested classes, and an explanation">
- <caption><span>Nested Classes</span><span class="tabEnd"> </span></caption>
- <tr>
- <th class="colFirst" scope="col">Modifier and Type</th>
- <th class="colSecond" scope="col">Class</th>
- <th class="colLast" scope="col">Description</th>
- </tr>
- <tr class="altColor">
- <td class="colFirst"><code>static interface </code></td>
- <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>
- <td class="colLast">
- <div class="block">Interface containing the method names to be used
- as array access replacements.</div>
- </td>
- </tr>
- <tr class="rowColor">
- <td class="colFirst"><code>static class </code></td>
- <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>
- <td class="colLast">
- <div class="block">Default implementation of the <code>ArrayAccessReplacementMethodNames</code>
- interface giving default values for method names to be used for replacing
- accesses to array elements.</div>
- </td>
- </tr>
- </table>
- </li>
- </ul>
- <!-- ======== CONSTRUCTOR SUMMARY ======== -->
- <ul class="blockList">
- <li class="blockList"><a name="constructor.summary">
- <!-- -->
- </a>
- <h3>Constructor Summary</h3>
- <table class="memberSummary" summary="Constructor Summary table, listing constructors, and an explanation">
- <caption><span>Constructors</span><span class="tabEnd"> </span></caption>
- <tr>
- <th class="colFirst" scope="col">Constructor</th>
- <th class="colLast" scope="col">Description</th>
- </tr>
- <tr class="altColor">
- <th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#CodeConverter--">CodeConverter</a></span>()</code></th>
- <td class="colLast"> </td>
- </tr>
- </table>
- </li>
- </ul>
- <!-- ========== METHOD SUMMARY =========== -->
- <ul class="blockList">
- <li class="blockList"><a name="method.summary">
- <!-- -->
- </a>
- <h3>Method Summary</h3>
- <table class="memberSummary" summary="Method Summary table, listing methods, and an explanation">
- <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd"> </span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd"> </span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd"> </span></span></caption>
- <tr>
- <th class="colFirst" scope="col">Modifier and Type</th>
- <th class="colSecond" scope="col">Method</th>
- <th class="colLast" scope="col">Description</th>
- </tr>
- <tr id="i0" class="altColor">
- <td class="colFirst"><code>void</code></td>
- <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#insertAfterMethod-javassist.CtMethod-javassist.CtMethod-">insertAfterMethod</a></span>​(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> origMethod,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> afterMethod)</code></th>
- <td class="colLast">
- <div class="block">Inserts a call to another method after an existing method call.</div>
- </td>
- </tr>
- <tr id="i1" class="rowColor">
- <td class="colFirst"><code>void</code></td>
- <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#insertBeforeMethod-javassist.CtMethod-javassist.CtMethod-">insertBeforeMethod</a></span>​(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> origMethod,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> beforeMethod)</code></th>
- <td class="colLast">
- <div class="block">Insert a call to another method before an existing method call.</div>
- </td>
- </tr>
- <tr id="i2" class="altColor">
- <td class="colFirst"><code>void</code></td>
- <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>​(<a href="../javassist/CtField.html" title="class in javassist">CtField</a> field,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> newClass,
- java.lang.String newFieldname)</code></th>
- <td class="colLast">
- <div class="block">Modify a method body so that field read/write expressions access
- a different field from the original one.</div>
- </td>
- </tr>
- <tr id="i3" class="rowColor">
- <td class="colFirst"><code>void</code></td>
- <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#redirectMethodCall-java.lang.String-javassist.CtMethod-">redirectMethodCall</a></span>​(java.lang.String oldMethodName,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> newMethod)</code></th>
- <td class="colLast">
- <div class="block">Correct invocations to a method that has been renamed.</div>
- </td>
- </tr>
- <tr id="i4" class="altColor">
- <td class="colFirst"><code>void</code></td>
- <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#redirectMethodCall-javassist.CtMethod-javassist.CtMethod-">redirectMethodCall</a></span>​(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> origMethod,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> substMethod)</code></th>
- <td class="colLast">
- <div class="block">Modify method invocations in a method body so that a different
- method will be invoked.</div>
- </td>
- </tr>
- <tr id="i5" class="rowColor">
- <td class="colFirst"><code>void</code></td>
- <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceArrayAccess-javassist.CtClass-javassist.CodeConverter.ArrayAccessReplacementMethodNames-">replaceArrayAccess</a></span>​(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- <a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist">CodeConverter.ArrayAccessReplacementMethodNames</a> names)</code></th>
- <td class="colLast">
- <div class="block">Modify a method body, so that ALL accesses to an array are replaced with
- calls to static methods within another class.</div>
- </td>
- </tr>
- <tr id="i6" class="altColor">
- <td class="colFirst"><code>void</code></td>
- <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>​(<a href="../javassist/CtField.html" title="class in javassist">CtField</a> field,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- java.lang.String calledMethod)</code></th>
- <td class="colLast">
- <div class="block">Modify a method body so that an expression reading the specified
- field is replaced with a call to the specified <i>static</i> method.</div>
- </td>
- </tr>
- <tr id="i7" class="rowColor">
- <td class="colFirst"><code>void</code></td>
- <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>​(<a href="../javassist/CtField.html" title="class in javassist">CtField</a> field,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- java.lang.String calledMethod)</code></th>
- <td class="colLast">
- <div class="block">Modify a method body so that an expression writing the specified
- field is replaced with a call to the specified static method.</div>
- </td>
- </tr>
- <tr id="i8" class="altColor">
- <td class="colFirst"><code>void</code></td>
- <th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="../javassist/CodeConverter.html#replaceNew-javassist.CtClass-javassist.CtClass-">replaceNew</a></span>​(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> oldClass,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> newClass)</code></th>
- <td class="colLast">
- <div class="block">Modify a method body so that instantiation of the class
- specified by <code>oldClass</code>
- is replaced with instantiation of another class <code>newClass</code>.</div>
- </td>
- </tr>
- <tr id="i9" class="rowColor">
- <td class="colFirst"><code>void</code></td>
- <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>​(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> newClass,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- java.lang.String calledMethod)</code></th>
- <td class="colLast">
- <div class="block">Modify a method body so that instantiation of the specified class
- is replaced with a call to the specified static method.</div>
- </td>
- </tr>
- </table>
- <ul class="blockList">
- <li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
- <!-- -->
- </a>
- <h3>Methods inherited from class java.lang.Object</h3>
- <code>equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
- </ul>
- </li>
- </ul>
- </li>
- </ul>
- </div>
- <div class="details">
- <ul class="blockList">
- <li class="blockList">
- <!-- ========= CONSTRUCTOR DETAIL ======== -->
- <ul class="blockList">
- <li class="blockList"><a name="constructor.detail">
- <!-- -->
- </a>
- <h3>Constructor Detail</h3>
- <a name="CodeConverter--">
- <!-- -->
- </a>
- <ul class="blockListLast">
- <li class="blockList">
- <h4>CodeConverter</h4>
- <pre>public CodeConverter()</pre>
- </li>
- </ul>
- </li>
- </ul>
- <!-- ============ METHOD DETAIL ========== -->
- <ul class="blockList">
- <li class="blockList"><a name="method.detail">
- <!-- -->
- </a>
- <h3>Method Detail</h3>
- <a name="replaceNew-javassist.CtClass-javassist.CtClass-java.lang.String-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>replaceNew</h4>
- <pre>public void replaceNew​(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> newClass,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- java.lang.String calledMethod)</pre>
- <div class="block">Modify a method body so that instantiation of the specified class
- is replaced with a call to the specified static method. For example,
- <code>replaceNew(ctPoint, ctSingleton, "createPoint")</code>
- (where <code>ctPoint</code> and <code>ctSingleton</code> are
- compile-time classes for class <code>Point</code> and class
- <code>Singleton</code>, respectively)
- replaces all occurrences of:
-
- <pre>new Point(x, y)</pre>
-
- in the method body with:
-
- <pre>Singleton.createPoint(x, y)</pre>
-
- <p>This enables to intercept instantiation of <code>Point</code>
- and change the samentics. For example, the following
- <code>createPoint()</code> implements the singleton pattern:
-
- <pre>public static Point createPoint(int x, int y) {
- if (aPoint == null)
- aPoint = new Point(x, y);
- return aPoint;
- }
- </pre>
-
- <p>The static method call substituted for the original <code>new</code>
- expression must be
- able to receive the same set of parameters as the original
- constructor. If there are multiple constructors with different
- parameter types, then there must be multiple static methods
- with the same name but different parameter types.
-
- <p>The return type of the substituted static method must be
- the exactly same as the type of the instantiated class specified by
- <code>newClass</code>.</div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>newClass</code> - the instantiated class.</dd>
- <dd><code>calledClass</code> - the class in which the static method is
- declared.</dd>
- <dd><code>calledMethod</code> - the name of the static method.</dd>
- </dl>
- </li>
- </ul>
- <a name="replaceNew-javassist.CtClass-javassist.CtClass-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>replaceNew</h4>
- <pre>public void replaceNew​(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> oldClass,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> newClass)</pre>
- <div class="block">Modify a method body so that instantiation of the class
- specified by <code>oldClass</code>
- is replaced with instantiation of another class <code>newClass</code>.
- For example,
- <code>replaceNew(ctPoint, ctPoint2)</code>
- (where <code>ctPoint</code> and <code>ctPoint2</code> are
- compile-time classes for class <code>Point</code> and class
- <code>Point2</code>, respectively)
- replaces all occurrences of:
-
- <pre>new Point(x, y)</pre>
-
- in the method body with:
-
- <pre>new Point2(x, y)</pre>
-
- <p>Note that <code>Point2</code> must be type-compatible with <code>Point</code>.
- It must have the same set of methods, fields, and constructors as the
- replaced class.</div>
- </li>
- </ul>
- <a name="redirectFieldAccess-javassist.CtField-javassist.CtClass-java.lang.String-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>redirectFieldAccess</h4>
- <pre>public void redirectFieldAccess​(<a href="../javassist/CtField.html" title="class in javassist">CtField</a> field,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> newClass,
- java.lang.String newFieldname)</pre>
- <div class="block">Modify a method body so that field read/write expressions access
- a different field from the original one.
-
- <p>Note that this method changes only the filed name and the class
- declaring the field; the type of the target object does not change.
- Therefore, the substituted field must be declared in the same class
- or a superclass of the original class.
-
- <p>Also, <code>clazz</code> and <code>newClass</code> must specify
- the class directly declaring the field. They must not specify
- a subclass of that class.</div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>field</code> - the originally accessed field.</dd>
- <dd><code>newClass</code> - the class declaring the substituted field.</dd>
- <dd><code>newFieldname</code> - the name of the substituted field.</dd>
- </dl>
- </li>
- </ul>
- <a name="replaceFieldRead-javassist.CtField-javassist.CtClass-java.lang.String-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>replaceFieldRead</h4>
- <pre>public void replaceFieldRead​(<a href="../javassist/CtField.html" title="class in javassist">CtField</a> field,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- java.lang.String calledMethod)</pre>
- <div class="block">Modify a method body so that an expression reading the specified
- field is replaced with a call to the specified <i>static</i> method.
- This static method receives the target object of the original
- read expression as a parameter. It must return a value of
- the same type as the field.
-
- <p>For example, the program below
-
- <pre>Point p = new Point();
- int newX = p.x + 3;</pre>
-
- <p>can be translated into:
-
- <pre>Point p = new Point();
- int newX = Accessor.readX(p) + 3;</pre>
-
- <p>where
-
- <pre>public class Accessor {
- public static int readX(Object target) { ... }
- }</pre>
-
- <p>The type of the parameter of <code>readX()</code> must
- be <code>java.lang.Object</code> independently of the actual
- type of <code>target</code>. The return type must be the same
- as the field type.</div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>field</code> - the field.</dd>
- <dd><code>calledClass</code> - the class in which the static method is
- declared.</dd>
- <dd><code>calledMethod</code> - the name of the static method.</dd>
- </dl>
- </li>
- </ul>
- <a name="replaceFieldWrite-javassist.CtField-javassist.CtClass-java.lang.String-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>replaceFieldWrite</h4>
- <pre>public void replaceFieldWrite​(<a href="../javassist/CtField.html" title="class in javassist">CtField</a> field,
- <a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- java.lang.String calledMethod)</pre>
- <div class="block">Modify a method body so that an expression writing the specified
- field is replaced with a call to the specified static method.
- This static method receives two parameters: the target object of
- the original
- write expression and the assigned value. The return type of the
- static method is <code>void</code>.
-
- <p>For example, the program below
-
- <pre>Point p = new Point();
- p.x = 3;</pre>
-
- <p>can be translated into:
-
- <pre>Point p = new Point();
- Accessor.writeX(3);</pre>
-
- <p>where
-
- <pre>public class Accessor {
- public static void writeX(Object target, int value) { ... }
- }</pre>
-
- <p>The type of the first parameter of <code>writeX()</code> must
- be <code>java.lang.Object</code> independently of the actual
- type of <code>target</code>. The type of the second parameter
- is the same as the field type.</div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>field</code> - the field.</dd>
- <dd><code>calledClass</code> - the class in which the static method is
- declared.</dd>
- <dd><code>calledMethod</code> - the name of the static method.</dd>
- </dl>
- </li>
- </ul>
- <a name="replaceArrayAccess-javassist.CtClass-javassist.CodeConverter.ArrayAccessReplacementMethodNames-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>replaceArrayAccess</h4>
- <pre>public void replaceArrayAccess​(<a href="../javassist/CtClass.html" title="class in javassist">CtClass</a> calledClass,
- <a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist">CodeConverter.ArrayAccessReplacementMethodNames</a> names)
- throws <a href="../javassist/NotFoundException.html" title="class in javassist">NotFoundException</a></pre>
- <div class="block">Modify a method body, so that ALL accesses to an array are replaced with
- calls to static methods within another class. In the case of reading an
- element from the array, this is replaced with a call to a static method with
- the array and the index as arguments, the return value is the value read from
- the array. If writing to an array, this is replaced with a call to a static
- method with the array, index and new value as parameters, the return value of
- the static method is <code>void</code>.
-
- <p>The <code>calledClass</code> parameter is the class containing the static methods to be used
- for array replacement. The <code>names</code> parameter points to an implementation of
- <code>ArrayAccessReplacementMethodNames</code> which specifies the names of the method to be
- used for access for each type of array. For example reading from an <code>int[]</code> will
- require a different method than if writing to an <code>int[]</code>, and writing to a <code>long[]</code>
- will require a different method than if writing to a <code>byte[]</code>. If the implementation
- of <code>ArrayAccessReplacementMethodNames</code> does not contain the name for access for a
- type of array, that access is not replaced.
-
- <p>A default implementation of <code>ArrayAccessReplacementMethodNames</code> called
- <code>DefaultArrayAccessReplacementMethodNames</code> has been provided and is what is used in the
- following example. This also assumes that <code>'foo.ArrayAdvisor'</code> is the name of the
- <code>CtClass</code> passed in.
-
- <p>If we have the following class:
- <pre>class POJO{
- int[] ints = new int[]{1, 2, 3, 4, 5};
- long[] longs = new int[]{10, 20, 30};
- Object objects = new Object[]{true, false};
- Integer[] integers = new Integer[]{new Integer(10)};
- }
- </pre>
- and this is accessed as:
- <pre>POJO p = new POJO();
-
- //Write to int array
- p.ints[2] = 7;
-
- //Read from int array
- int i = p.ints[2];
-
- //Write to long array
- p.longs[2] = 1000L;
-
- //Read from long array
- long l = p.longs[2];
-
- //Write to Object array
- p.objects[2] = "Hello";
-
- //Read from Object array
- Object o = p.objects[2];
-
- //Write to Integer array
- Integer integer = new Integer(5);
- p.integers[0] = integer;
-
- //Read from Object array
- integer = p.integers[0];
- </pre>
-
- Following instrumentation we will have
- <pre>POJO p = new POJO();
-
- //Write to int array
- ArrayAdvisor.arrayWriteInt(p.ints, 2, 7);
-
- //Read from int array
- int i = ArrayAdvisor.arrayReadInt(p.ints, 2);
-
- //Write to long array
- ArrayAdvisor.arrayWriteLong(p.longs, 2, 1000L);
-
- //Read from long array
- long l = ArrayAdvisor.arrayReadLong(p.longs, 2);
-
- //Write to Object array
- ArrayAdvisor.arrayWriteObject(p.objects, 2, "Hello");
-
- //Read from Object array
- Object o = ArrayAdvisor.arrayReadObject(p.objects, 2);
-
- //Write to Integer array
- Integer integer = new Integer(5);
- ArrayAdvisor.arrayWriteObject(p.integers, 0, integer);
-
- //Read from Object array
- integer = ArrayAdvisor.arrayWriteObject(p.integers, 0);
- </pre></div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>calledClass</code> - the class containing the static methods.</dd>
- <dd><code>names</code> - contains the names of the methods to replace
- the different kinds of array access with.</dd>
- <dt><span class="throwsLabel">Throws:</span></dt>
- <dd><code><a href="../javassist/NotFoundException.html" title="class in javassist">NotFoundException</a></code></dd>
- <dt><span class="seeLabel">See Also:</span></dt>
- <dd><a href="../javassist/CodeConverter.DefaultArrayAccessReplacementMethodNames.html" title="class in javassist"><code>CodeConverter.DefaultArrayAccessReplacementMethodNames</code></a></dd>
- </dl>
- </li>
- </ul>
- <a name="redirectMethodCall-javassist.CtMethod-javassist.CtMethod-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>redirectMethodCall</h4>
- <pre>public void redirectMethodCall​(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> origMethod,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> substMethod)
- throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
- <div class="block">Modify method invocations in a method body so that a different
- method will be invoked.
-
- <p>Note that the target object, the parameters, or
- the type of invocation
- (static method call, interface call, or private method call)
- are not modified. Only the method name is changed. The substituted
- method must have the same signature that the original one has.
- If the original method is a static method, the substituted method
- must be static.</div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>origMethod</code> - original method</dd>
- <dd><code>substMethod</code> - substituted method</dd>
- <dt><span class="throwsLabel">Throws:</span></dt>
- <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
- </dl>
- </li>
- </ul>
- <a name="redirectMethodCall-java.lang.String-javassist.CtMethod-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>redirectMethodCall</h4>
- <pre>public void redirectMethodCall​(java.lang.String oldMethodName,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> newMethod)
- throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
- <div class="block">Correct invocations to a method that has been renamed.
- If a method is renamed, calls to that method must be also
- modified so that the method with the new name will be called.
-
- <p>The method must be declared in the same class before and
- after it is renamed.
-
- <p>Note that the target object, the parameters, or
- the type of invocation
- (static method call, interface call, or private method call)
- are not modified. Only the method name is changed.</div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>oldMethodName</code> - the old name of the method.</dd>
- <dd><code>newMethod</code> - the method with the new name.</dd>
- <dt><span class="throwsLabel">Throws:</span></dt>
- <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
- <dt><span class="seeLabel">See Also:</span></dt>
- <dd><a href="../javassist/CtMethod.html#setName-java.lang.String-"><code>CtMethod.setName(String)</code></a></dd>
- </dl>
- </li>
- </ul>
- <a name="insertBeforeMethod-javassist.CtMethod-javassist.CtMethod-">
- <!-- -->
- </a>
- <ul class="blockList">
- <li class="blockList">
- <h4>insertBeforeMethod</h4>
- <pre>public void insertBeforeMethod​(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> origMethod,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> beforeMethod)
- throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
- <div class="block">Insert a call to another method before an existing method call.
- That "before" method must be static. The return type must be
- <code>void</code>. As parameters, the before method receives
- the target object and all the parameters to the originally invoked
- method. For example, if the originally invoked method is
- <code>move()</code>:
-
- <pre>class Point {
- Point move(int x, int y) { ... }
- }</pre>
-
- <p>Then the before method must be something like this:
-
- <pre>class Verbose {
- static void print(Point target, int x, int y) { ... }
- }</pre>
-
- <p>The <code>CodeConverter</code> would translate bytecode
- equivalent to:
-
- <pre>Point p2 = p.move(x + y, 0);</pre>
-
- <p>into the bytecode equivalent to:
-
- <pre>int tmp1 = x + y;
- int tmp2 = 0;
- Verbose.print(p, tmp1, tmp2);
- Point p2 = p.move(tmp1, tmp2);</pre></div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>origMethod</code> - the method originally invoked.</dd>
- <dd><code>beforeMethod</code> - the method invoked before
- <code>origMethod</code>.</dd>
- <dt><span class="throwsLabel">Throws:</span></dt>
- <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
- </dl>
- </li>
- </ul>
- <a name="insertAfterMethod-javassist.CtMethod-javassist.CtMethod-">
- <!-- -->
- </a>
- <ul class="blockListLast">
- <li class="blockList">
- <h4>insertAfterMethod</h4>
- <pre>public void insertAfterMethod​(<a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> origMethod,
- <a href="../javassist/CtMethod.html" title="class in javassist">CtMethod</a> afterMethod)
- throws <a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></pre>
- <div class="block">Inserts a call to another method after an existing method call.
- That "after" method must be static. The return type must be
- <code>void</code>. As parameters, the after method receives
- the target object and all the parameters to the originally invoked
- method. For example, if the originally invoked method is
- <code>move()</code>:
-
- <pre>class Point {
- Point move(int x, int y) { ... }
- }</pre>
-
- <p>Then the after method must be something like this:
-
- <pre>class Verbose {
- static void print(Point target, int x, int y) { ... }
- }</pre>
-
- <p>The <code>CodeConverter</code> would translate bytecode
- equivalent to:
-
- <pre>Point p2 = p.move(x + y, 0);</pre>
-
- <p>into the bytecode equivalent to:
-
- <pre>
- int tmp1 = x + y;
- int tmp2 = 0;
- Point p2 = p.move(tmp1, tmp2);
- Verbose.print(p, tmp1, tmp2);</pre></div>
- <dl>
- <dt><span class="paramLabel">Parameters:</span></dt>
- <dd><code>origMethod</code> - the method originally invoked.</dd>
- <dd><code>afterMethod</code> - the method invoked after
- <code>origMethod</code>.</dd>
- <dt><span class="throwsLabel">Throws:</span></dt>
- <dd><code><a href="../javassist/CannotCompileException.html" title="class in javassist">CannotCompileException</a></code></dd>
- </dl>
- </li>
- </ul>
- </li>
- </ul>
- </li>
- </ul>
- </div>
- </div>
- <!-- ========= END OF CLASS DATA ========= -->
- <!-- ======= START OF BOTTOM NAVBAR ====== -->
- <div class="bottomNav"><a name="navbar.bottom">
- <!-- -->
- </a>
- <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
- <a name="navbar.bottom.firstrow">
- <!-- -->
- </a>
- <ul class="navList" title="Navigation">
- <li><a href="../overview-summary.html">Overview</a></li>
- <li><a href="package-summary.html">Package</a></li>
- <li class="navBarCell1Rev">Class</li>
- <li><a href="class-use/CodeConverter.html">Use</a></li>
- <li><a href="package-tree.html">Tree</a></li>
- <li><a href="../deprecated-list.html">Deprecated</a></li>
- <li><a href="../index-all.html">Index</a></li>
- </ul>
- </div>
- <div class="subNav">
- <ul class="navList">
- <li><a href="../javassist/ClassPool.html" title="class in javassist"><span class="typeNameLink">Prev Class</span></a></li>
- <li><a href="../javassist/CodeConverter.ArrayAccessReplacementMethodNames.html" title="interface in javassist"><span class="typeNameLink">Next Class</span></a></li>
- </ul>
- <ul class="navList">
- <li><a href="../index.html?javassist/CodeConverter.html" target="_top">Frames</a></li>
- <li><a href="CodeConverter.html" target="_top">No Frames</a></li>
- </ul>
- <ul class="navList" id="allclasses_navbar_bottom">
- <li><a href="../allclasses-noframe.html">All Classes</a></li>
- </ul>
- <div>
- <script type="text/javascript"><!--
- allClassesLink = document.getElementById("allclasses_navbar_bottom");
- if(window==top) {
- allClassesLink.style.display = "block";
- }
- else {
- allClassesLink.style.display = "none";
- }
- //-->
- </script>
- <noscript>
- <div>JavaScript is disabled on your browser.</div>
- </noscript>
- </div>
- <div>
- <ul class="subNavList">
- <li>Summary: </li>
- <li><a href="#nested.class.summary">Nested</a> | </li>
- <li>Field | </li>
- <li><a href="#constructor.summary">Constr</a> | </li>
- <li><a href="#method.summary">Method</a></li>
- </ul>
- <ul class="subNavList">
- <li>Detail: </li>
- <li>Field | </li>
- <li><a href="#constructor.detail">Constr</a> | </li>
- <li><a href="#method.detail">Method</a></li>
- </ul>
- </div>
- <a name="skip.navbar.bottom">
- <!-- -->
- </a></div>
- <!-- ======== END OF BOTTOM NAVBAR ======= -->
- <p class="legalCopy"><small><i>Javassist, a Java-bytecode translator toolkit.<br>
- Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.</i></small></p>
- </body>
- </html>
|