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.

CtClass.java 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2007 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. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. */
  15. package javassist;
  16. import java.io.BufferedOutputStream;
  17. import java.io.ByteArrayOutputStream;
  18. import java.io.DataOutputStream;
  19. import java.io.File;
  20. import java.io.FileOutputStream;
  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. import java.net.URL;
  24. import java.security.ProtectionDomain;
  25. import java.util.Collection;
  26. import javassist.bytecode.ClassFile;
  27. import javassist.bytecode.Descriptor;
  28. import javassist.bytecode.Opcode;
  29. import javassist.expr.ExprEditor;
  30. /* Note:
  31. *
  32. * This class is an abstract class and several methods just return null
  33. * or throw an exception. Those methods are overridden in subclasses
  34. * of this class. Read the source code of CtClassType if you are
  35. * interested in the implementation of Javassist.
  36. *
  37. * Subclasses of CtClass are CtClassType, CtPrimitiveType, and CtArray.
  38. */
  39. /**
  40. * An instance of <code>CtClass</code> represents a class.
  41. * It is obtained from <code>ClassPool</code>.
  42. *
  43. * @see ClassPool#get(String)
  44. */
  45. public abstract class CtClass {
  46. protected String qualifiedName;
  47. /**
  48. * The version number of this release.
  49. */
  50. public static final String version = "3.14.0.GA";
  51. /**
  52. * Prints the version number and the copyright notice.
  53. *
  54. * <p>The following command invokes this method:
  55. *
  56. * <ul><pre>java -jar javassist.jar</pre></ul>
  57. */
  58. public static void main(String[] args) {
  59. System.out.println("Javassist version " + CtClass.version);
  60. System.out.println("Copyright (C) 1999-2010 Shigeru Chiba."
  61. + " All Rights Reserved.");
  62. }
  63. static final String javaLangObject = "java.lang.Object";
  64. /**
  65. * The <code>CtClass</code> object representing
  66. * the <code>boolean</code> type.
  67. */
  68. public static CtClass booleanType;
  69. /**
  70. * The <code>CtClass</code> object representing
  71. * the <code>char</code> type.
  72. */
  73. public static CtClass charType;
  74. /**
  75. * The <code>CtClass</code> object representing
  76. * the <code>byte</code> type.
  77. */
  78. public static CtClass byteType;
  79. /**
  80. * The <code>CtClass</code> object representing
  81. * the <code>short</code> type.
  82. */
  83. public static CtClass shortType;
  84. /**
  85. * The <code>CtClass</code> object representing
  86. * the <code>int</code> type.
  87. */
  88. public static CtClass intType;
  89. /**
  90. * The <code>CtClass</code> object representing
  91. * the <code>long</code> type.
  92. */
  93. public static CtClass longType;
  94. /**
  95. * The <code>CtClass</code> object representing
  96. * the <code>float</code> type.
  97. */
  98. public static CtClass floatType;
  99. /**
  100. * The <code>CtClass</code> object representing
  101. * the <code>double</code> type.
  102. */
  103. public static CtClass doubleType;
  104. /**
  105. * The <code>CtClass</code> object representing
  106. * the <code>void</code> type.
  107. */
  108. public static CtClass voidType;
  109. static CtClass[] primitiveTypes;
  110. static {
  111. primitiveTypes = new CtClass[9];
  112. booleanType =
  113. new CtPrimitiveType("boolean", 'Z', "java.lang.Boolean",
  114. "booleanValue", "()Z", Opcode.IRETURN,
  115. Opcode.T_BOOLEAN, 1);
  116. primitiveTypes[0] = booleanType;
  117. charType = new CtPrimitiveType("char", 'C', "java.lang.Character",
  118. "charValue", "()C", Opcode.IRETURN,
  119. Opcode.T_CHAR, 1);
  120. primitiveTypes[1] = charType;
  121. byteType = new CtPrimitiveType("byte", 'B', "java.lang.Byte",
  122. "byteValue", "()B", Opcode.IRETURN,
  123. Opcode.T_BYTE, 1);
  124. primitiveTypes[2] = byteType;
  125. shortType = new CtPrimitiveType("short", 'S', "java.lang.Short",
  126. "shortValue", "()S", Opcode.IRETURN,
  127. Opcode.T_SHORT, 1);
  128. primitiveTypes[3] = shortType;
  129. intType = new CtPrimitiveType("int", 'I', "java.lang.Integer",
  130. "intValue", "()I", Opcode.IRETURN,
  131. Opcode.T_INT, 1);
  132. primitiveTypes[4] = intType;
  133. longType = new CtPrimitiveType("long", 'J', "java.lang.Long",
  134. "longValue", "()J", Opcode.LRETURN,
  135. Opcode.T_LONG, 2);
  136. primitiveTypes[5] = longType;
  137. floatType = new CtPrimitiveType("float", 'F', "java.lang.Float",
  138. "floatValue", "()F", Opcode.FRETURN,
  139. Opcode.T_FLOAT, 1);
  140. primitiveTypes[6] = floatType;
  141. doubleType = new CtPrimitiveType("double", 'D', "java.lang.Double",
  142. "doubleValue", "()D", Opcode.DRETURN,
  143. Opcode.T_DOUBLE, 2);
  144. primitiveTypes[7] = doubleType;
  145. voidType = new CtPrimitiveType("void", 'V', "java.lang.Void",
  146. null, null, Opcode.RETURN, 0, 0);
  147. primitiveTypes[8] = voidType;
  148. }
  149. protected CtClass(String name) {
  150. qualifiedName = name;
  151. }
  152. /**
  153. * Converts the object to a string.
  154. */
  155. public String toString() {
  156. StringBuffer buf = new StringBuffer(getClass().getName());
  157. buf.append("@");
  158. buf.append(Integer.toHexString(hashCode()));
  159. buf.append("[");
  160. extendToString(buf);
  161. buf.append("]");
  162. return buf.toString();
  163. }
  164. /**
  165. * Implemented in subclasses to add to the {@link #toString()} result.
  166. * Subclasses should put a space before each token added to the buffer.
  167. */
  168. protected void extendToString(StringBuffer buffer) {
  169. buffer.append(getName());
  170. }
  171. /**
  172. * Returns a <code>ClassPool</code> for this class.
  173. */
  174. public ClassPool getClassPool() { return null; }
  175. /**
  176. * Returns a class file for this class.
  177. *
  178. * <p>This method is not available if <code>isFrozen()</code>
  179. * is true.
  180. */
  181. public ClassFile getClassFile() {
  182. checkModify();
  183. return getClassFile2();
  184. }
  185. /**
  186. * Returns a class file for this class (read only).
  187. * Normal applications do not need calling this method. Use
  188. * <code>getClassFile()</code>.
  189. *
  190. * <p>The <code>ClassFile</code> object obtained by this method
  191. * is read only. Changes to this object might not be reflected
  192. * on a class file generated by <code>toBytecode()</code>,
  193. * <code>toClass()</code>, etc.
  194. *
  195. * <p>This method is available even if <code>isFrozen()</code>
  196. * is true. However, if the class is frozen, it might be also
  197. * pruned.
  198. *
  199. * @see CtClass#getClassFile()
  200. * @see CtClass#isFrozen()
  201. * @see CtClass#prune()
  202. */
  203. public ClassFile getClassFile2() { return null; }
  204. /**
  205. * Undocumented method. Do not use; internal-use only.
  206. */
  207. public javassist.compiler.AccessorMaker getAccessorMaker() {
  208. return null;
  209. }
  210. /**
  211. * Returns the uniform resource locator (URL) of the class file.
  212. */
  213. public URL getURL() throws NotFoundException {
  214. throw new NotFoundException(getName());
  215. }
  216. /**
  217. * Returns true if the definition of the class has been modified.
  218. */
  219. public boolean isModified() { return false; }
  220. /**
  221. * Returns true if the class has been loaded or written out
  222. * and thus it cannot be modified any more.
  223. *
  224. * @see #defrost()
  225. * @see #detach()
  226. */
  227. public boolean isFrozen() { return true; }
  228. /**
  229. * Makes the class frozen.
  230. *
  231. * @see #isFrozen()
  232. * @see #defrost()
  233. * @since 3.6
  234. */
  235. public void freeze() {}
  236. /* Note: this method is overridden by CtClassType
  237. */
  238. void checkModify() throws RuntimeException {
  239. if (isFrozen())
  240. throw new RuntimeException(getName() + " class is frozen");
  241. // isModified() must return true after this method is invoked.
  242. }
  243. /**
  244. * Defrosts the class so that the class can be modified again.
  245. *
  246. * <p>To avoid changes that will be never reflected,
  247. * the class is frozen to be unmodifiable if it is loaded or
  248. * written out. This method should be called only in a case
  249. * that the class will be reloaded or written out later again.
  250. *
  251. * <p>If <code>defrost()</code> will be called later, pruning
  252. * must be disallowed in advance.
  253. *
  254. * @see #isFrozen()
  255. * @see #stopPruning(boolean)
  256. * @see #detach()
  257. */
  258. public void defrost() {
  259. throw new RuntimeException("cannot defrost " + getName());
  260. }
  261. /**
  262. * Returns <code>true</code> if this object represents a primitive
  263. * Java type: boolean, byte, char, short, int, long, float, double,
  264. * or void.
  265. */
  266. public boolean isPrimitive() { return false; }
  267. /**
  268. * Returns <code>true</code> if this object represents an array type.
  269. */
  270. public boolean isArray() {
  271. return false;
  272. }
  273. /**
  274. * If this object represents an array, this method returns the component
  275. * type of the array. Otherwise, it returns <code>null</code>.
  276. */
  277. public CtClass getComponentType() throws NotFoundException {
  278. return null;
  279. }
  280. /**
  281. * Returns <code>true</code> if this class extends or implements
  282. * <code>clazz</code>. It also returns <code>true</code> if
  283. * this class is the same as <code>clazz</code>.
  284. */
  285. public boolean subtypeOf(CtClass clazz) throws NotFoundException {
  286. return this == clazz || getName().equals(clazz.getName());
  287. }
  288. /**
  289. * Obtains the fully-qualified name of the class.
  290. */
  291. public String getName() { return qualifiedName; }
  292. /**
  293. * Obtains the not-qualified class name.
  294. */
  295. public final String getSimpleName() {
  296. String qname = qualifiedName;
  297. int index = qname.lastIndexOf('.');
  298. if (index < 0)
  299. return qname;
  300. else
  301. return qname.substring(index + 1);
  302. }
  303. /**
  304. * Obtains the package name. It may be <code>null</code>.
  305. */
  306. public final String getPackageName() {
  307. String qname = qualifiedName;
  308. int index = qname.lastIndexOf('.');
  309. if (index < 0)
  310. return null;
  311. else
  312. return qname.substring(0, index);
  313. }
  314. /**
  315. * Sets the class name
  316. *
  317. * @param name fully-qualified name
  318. */
  319. public void setName(String name) {
  320. checkModify();
  321. if (name != null)
  322. qualifiedName = name;
  323. }
  324. /**
  325. * Substitutes <code>newName</code> for all occurrences of a class
  326. * name <code>oldName</code> in the class file.
  327. *
  328. * @param oldName replaced class name
  329. * @param newName substituted class name
  330. */
  331. public void replaceClassName(String oldName, String newName) {
  332. checkModify();
  333. }
  334. /**
  335. * Changes class names appearing in the class file according to the
  336. * given <code>map</code>.
  337. *
  338. * <p>All the class names appearing in the class file are tested
  339. * with <code>map</code> to determine whether each class name is
  340. * replaced or not. Thus this method can be used for collecting
  341. * all the class names in the class file. To do that, first define
  342. * a subclass of <code>ClassMap</code> so that <code>get()</code>
  343. * records all the given parameters. Then, make an instance of
  344. * that subclass as an empty hash-table. Finally, pass that instance
  345. * to this method. After this method finishes, that instance would
  346. * contain all the class names appearing in the class file.
  347. *
  348. * @param map the hashtable associating replaced class names
  349. * with substituted names.
  350. */
  351. public void replaceClassName(ClassMap map) {
  352. checkModify();
  353. }
  354. /**
  355. * Returns a collection of the names of all the classes
  356. * referenced in this class.
  357. * That collection includes the name of this class.
  358. *
  359. * <p>This method may return <code>null</code>.
  360. *
  361. * @return a <code>Collection&lt;String&gt;</code> object.
  362. */
  363. public synchronized Collection getRefClasses() {
  364. ClassFile cf = getClassFile2();
  365. if (cf != null) {
  366. ClassMap cm = new ClassMap() {
  367. public void put(String oldname, String newname) {
  368. put0(oldname, newname);
  369. }
  370. public Object get(Object jvmClassName) {
  371. String n = toJavaName((String)jvmClassName);
  372. put0(n, n);
  373. return null;
  374. }
  375. public void fix(String name) {}
  376. };
  377. cf.getRefClasses(cm);
  378. return cm.values();
  379. }
  380. else
  381. return null;
  382. }
  383. /**
  384. * Determines whether this object represents a class or an interface.
  385. * It returns <code>true</code> if this object represents an interface.
  386. */
  387. public boolean isInterface() {
  388. return false;
  389. }
  390. /**
  391. * Determines whether this object represents an annotation type.
  392. * It returns <code>true</code> if this object represents an annotation type.
  393. *
  394. * @since 3.2
  395. */
  396. public boolean isAnnotation() {
  397. return false;
  398. }
  399. /**
  400. * Determines whether this object represents an enum.
  401. * It returns <code>true</code> if this object represents an enum.
  402. *
  403. * @since 3.2
  404. */
  405. public boolean isEnum() {
  406. return false;
  407. }
  408. /**
  409. * Returns the modifiers for this class, encoded in an integer.
  410. * For decoding, use <code>javassist.Modifier</code>.
  411. *
  412. * <p>If the class is a static nested class (a.k.a. static inner class),
  413. * the returned modifiers include <code>Modifier.STATIC</code>.
  414. *
  415. * @see Modifier
  416. */
  417. public int getModifiers() {
  418. return 0;
  419. }
  420. /**
  421. * Returns true if the class has the specified annotation class.
  422. *
  423. * @param clz the annotation class.
  424. * @return <code>true</code> if the annotation is found, otherwise <code>false</code>.
  425. * @since 3.11
  426. */
  427. public boolean hasAnnotation(Class clz) {
  428. return false;
  429. }
  430. /**
  431. * Returns the annotation if the class has the specified annotation class.
  432. * For example, if an annotation <code>@Author</code> is associated
  433. * with this class, an <code>Author</code> object is returned.
  434. * The member values can be obtained by calling methods on
  435. * the <code>Author</code> object.
  436. *
  437. * @param clz the annotation class.
  438. * @return the annotation if found, otherwise <code>null</code>.
  439. * @since 3.11
  440. */
  441. public Object getAnnotation(Class clz) throws ClassNotFoundException {
  442. return null;
  443. }
  444. /**
  445. * Returns the annotations associated with this class.
  446. * For example, if an annotation <code>@Author</code> is associated
  447. * with this class, the returned array contains an <code>Author</code>
  448. * object. The member values can be obtained by calling methods on
  449. * the <code>Author</code> object.
  450. *
  451. * @return an array of annotation-type objects.
  452. * @see CtMember#getAnnotations()
  453. * @since 3.1
  454. */
  455. public Object[] getAnnotations() throws ClassNotFoundException {
  456. return new Object[0];
  457. }
  458. /**
  459. * Returns the annotations associated with this class.
  460. * This method is equivalent to <code>getAnnotations()</code>
  461. * except that, if any annotations are not on the classpath,
  462. * they are not included in the returned array.
  463. *
  464. * @return an array of annotation-type objects.
  465. * @see #getAnnotations()
  466. * @see CtMember#getAvailableAnnotations()
  467. * @since 3.3
  468. */
  469. public Object[] getAvailableAnnotations(){
  470. return new Object[0];
  471. }
  472. /**
  473. * Returns an array of nested classes declared in the class.
  474. * Nested classes are inner classes, anonymous classes, local classes,
  475. * and static nested classes.
  476. *
  477. * @since 3.2
  478. */
  479. public CtClass[] getNestedClasses() throws NotFoundException {
  480. return new CtClass[0];
  481. }
  482. /**
  483. * Sets the modifiers.
  484. *
  485. * <p>If the class is a nested class, this method also modifies
  486. * the class declaring that nested class (i.e. the enclosing
  487. * class is modified).
  488. *
  489. * @param mod modifiers encoded by
  490. * <code>javassist.Modifier</code>
  491. * @see Modifier
  492. */
  493. public void setModifiers(int mod) {
  494. checkModify();
  495. }
  496. /**
  497. * Determines whether the class directly or indirectly extends
  498. * the given class. If this class extends a class A and
  499. * the class A extends a class B, then subclassof(B) returns true.
  500. *
  501. * <p>This method returns true if the given class is identical to
  502. * the class represented by this object.
  503. */
  504. public boolean subclassOf(CtClass superclass) {
  505. return false;
  506. }
  507. /**
  508. * Obtains the class object representing the superclass of the
  509. * class.
  510. * It returns null if this object represents the
  511. * <code>java.lang.Object</code> class and thus it does not have
  512. * the super class.
  513. *
  514. * <p>If this object represents an interface, this method
  515. * always returns the <code>java.lang.Object</code> class.
  516. * To obtain the super interfaces
  517. * extended by that interface, call <code>getInterfaces()</code>.
  518. */
  519. public CtClass getSuperclass() throws NotFoundException {
  520. return null;
  521. }
  522. /**
  523. * Changes a super class unless this object represents an interface.
  524. * The new super class must be compatible with the old one; for example,
  525. * it should inherit from the old super class.
  526. *
  527. * <p>If this object represents an interface, this method is equivalent
  528. * to <code>addInterface()</code>; it appends <code>clazz</code> to
  529. * the list of the super interfaces extended by that interface.
  530. * Note that an interface can extend multiple super interfaces.
  531. *
  532. * @see #replaceClassName(String, String)
  533. * @see #replaceClassName(ClassMap)
  534. */
  535. public void setSuperclass(CtClass clazz) throws CannotCompileException {
  536. checkModify();
  537. }
  538. /**
  539. * Obtains the class objects representing the interfaces implemented
  540. * by the class or, if this object represents an interface, the interfaces
  541. * extended by that interface.
  542. */
  543. public CtClass[] getInterfaces() throws NotFoundException {
  544. return new CtClass[0];
  545. }
  546. /**
  547. * Sets implemented interfaces. If this object represents an interface,
  548. * this method sets the interfaces extended by that interface.
  549. *
  550. * @param list a list of the <code>CtClass</code> objects
  551. * representing interfaces, or
  552. * <code>null</code> if the class implements
  553. * no interfaces.
  554. */
  555. public void setInterfaces(CtClass[] list) {
  556. checkModify();
  557. }
  558. /**
  559. * Adds an interface.
  560. *
  561. * @param anInterface the added interface.
  562. */
  563. public void addInterface(CtClass anInterface) {
  564. checkModify();
  565. }
  566. /**
  567. * If this class is a member class or interface of another class,
  568. * then the class enclosing this class is returned.
  569. *
  570. * @return null if this class is a top-level class or an anonymous class.
  571. */
  572. public CtClass getDeclaringClass() throws NotFoundException {
  573. return null;
  574. }
  575. /**
  576. * Returns the immediately enclosing method of this class.
  577. * This method works only with JDK 1.5 or later.
  578. *
  579. * @return null if this class is not a local class or an anonymous
  580. * class.
  581. */
  582. public CtMethod getEnclosingMethod() throws NotFoundException {
  583. return null;
  584. }
  585. /**
  586. * Makes a new public nested class. If this method is called,
  587. * the <code>CtClass</code>, which encloses the nested class, is modified
  588. * since a class file includes a list of nested classes.
  589. *
  590. * <p>The current implementation only supports a static nested class.
  591. * <code>isStatic</code> must be true.
  592. *
  593. * @param name the simple name of the nested class.
  594. * @param isStatic true if the nested class is static.
  595. */
  596. public CtClass makeNestedClass(String name, boolean isStatic) {
  597. throw new RuntimeException(getName() + " is not a class");
  598. }
  599. /**
  600. * Returns an array containing <code>CtField</code> objects
  601. * representing all the non-private fields of the class.
  602. * That array includes non-private fields inherited from the
  603. * superclasses.
  604. */
  605. public CtField[] getFields() { return new CtField[0]; }
  606. /**
  607. * Returns the field with the specified name. The returned field
  608. * may be a private field declared in a super class or interface.
  609. */
  610. public CtField getField(String name) throws NotFoundException {
  611. return getField(name, null);
  612. }
  613. /**
  614. * Returns the field with the specified name and type. The returned field
  615. * may be a private field declared in a super class or interface.
  616. * Unlike Java, the JVM allows a class to have
  617. * multiple fields with the same name but different types.
  618. *
  619. * @param name the field name.
  620. * @param desc the type descriptor of the field. It is available by
  621. * {@link CtField#getSignature()}.
  622. * @see CtField#getSignature()
  623. */
  624. public CtField getField(String name, String desc) throws NotFoundException {
  625. throw new NotFoundException(name);
  626. }
  627. /**
  628. * @return null if the specified field is not found.
  629. */
  630. CtField getField2(String name, String desc) { return null; }
  631. /**
  632. * Gets all the fields declared in the class. The inherited fields
  633. * are not included.
  634. *
  635. * <p>Note: the result does not include inherited fields.
  636. */
  637. public CtField[] getDeclaredFields() { return new CtField[0]; }
  638. /**
  639. * Retrieves the field with the specified name among the fields
  640. * declared in the class.
  641. *
  642. * <p>Note: this method does not search the super classes.
  643. */
  644. public CtField getDeclaredField(String name) throws NotFoundException {
  645. throw new NotFoundException(name);
  646. }
  647. /**
  648. * Retrieves the field with the specified name and type among the fields
  649. * declared in the class. Unlike Java, the JVM allows a class to have
  650. * multiple fields with the same name but different types.
  651. *
  652. * <p>Note: this method does not search the super classes.
  653. *
  654. * @param name the field name.
  655. * @param desc the type descriptor of the field. It is available by
  656. * {@link CtField#getSignature()}.
  657. * @see CtField#getSignature()
  658. */
  659. public CtField getDeclaredField(String name, String desc) throws NotFoundException {
  660. throw new NotFoundException(name);
  661. }
  662. /**
  663. * Gets all the constructors and methods declared in the class.
  664. */
  665. public CtBehavior[] getDeclaredBehaviors() {
  666. return new CtBehavior[0];
  667. }
  668. /**
  669. * Returns an array containing <code>CtConstructor</code> objects
  670. * representing all the non-private constructors of the class.
  671. */
  672. public CtConstructor[] getConstructors() {
  673. return new CtConstructor[0];
  674. }
  675. /**
  676. * Returns the constructor with the given signature,
  677. * which is represented by a character string
  678. * called method descriptor.
  679. * For details of the method descriptor, see the JVM specification
  680. * or <code>javassist.bytecode.Descriptor</code>.
  681. *
  682. * @param desc method descriptor
  683. * @see javassist.bytecode.Descriptor
  684. */
  685. public CtConstructor getConstructor(String desc)
  686. throws NotFoundException
  687. {
  688. throw new NotFoundException("no such constructor");
  689. }
  690. /**
  691. * Gets all the constructors declared in the class.
  692. *
  693. * @see javassist.CtConstructor
  694. */
  695. public CtConstructor[] getDeclaredConstructors() {
  696. return new CtConstructor[0];
  697. }
  698. /**
  699. * Returns a constructor receiving the specified parameters.
  700. *
  701. * @param params parameter types.
  702. */
  703. public CtConstructor getDeclaredConstructor(CtClass[] params)
  704. throws NotFoundException
  705. {
  706. String desc = Descriptor.ofConstructor(params);
  707. return getConstructor(desc);
  708. }
  709. /**
  710. * Gets the class initializer (static constructor)
  711. * declared in the class.
  712. * This method returns <code>null</code> if
  713. * no class initializer is not declared.
  714. *
  715. * @see #makeClassInitializer()
  716. * @see javassist.CtConstructor
  717. */
  718. public CtConstructor getClassInitializer() {
  719. return null;
  720. }
  721. /**
  722. * Returns an array containing <code>CtMethod</code> objects
  723. * representing all the non-private methods of the class.
  724. * That array includes non-private methods inherited from the
  725. * superclasses.
  726. */
  727. public CtMethod[] getMethods() {
  728. return new CtMethod[0];
  729. }
  730. /**
  731. * Returns the method with the given name and signature.
  732. * The returned method may be declared in a super class.
  733. * The method signature is represented by a character string
  734. * called method descriptor,
  735. * which is defined in the JVM specification.
  736. *
  737. * @param name method name
  738. * @param desc method descriptor
  739. * @see CtBehavior#getSignature()
  740. * @see javassist.bytecode.Descriptor
  741. */
  742. public CtMethod getMethod(String name, String desc)
  743. throws NotFoundException
  744. {
  745. throw new NotFoundException(name);
  746. }
  747. /**
  748. * Gets all methods declared in the class. The inherited methods
  749. * are not included.
  750. *
  751. * @see javassist.CtMethod
  752. */
  753. public CtMethod[] getDeclaredMethods() {
  754. return new CtMethod[0];
  755. }
  756. /**
  757. * Retrieves the method with the specified name and parameter types
  758. * among the methods declared in the class.
  759. *
  760. * <p>Note: this method does not search the superclasses.
  761. *
  762. * @param name method name
  763. * @param params parameter types
  764. * @see javassist.CtMethod
  765. */
  766. public CtMethod getDeclaredMethod(String name, CtClass[] params)
  767. throws NotFoundException
  768. {
  769. throw new NotFoundException(name);
  770. }
  771. /**
  772. * Retrieves the method with the specified name among the methods
  773. * declared in the class. If there are multiple methods with
  774. * the specified name, then this method returns one of them.
  775. *
  776. * <p>Note: this method does not search the superclasses.
  777. *
  778. * @see javassist.CtMethod
  779. */
  780. public CtMethod getDeclaredMethod(String name) throws NotFoundException {
  781. throw new NotFoundException(name);
  782. }
  783. /**
  784. * Makes an empty class initializer (static constructor).
  785. * If the class already includes a class initializer,
  786. * this method returns it.
  787. *
  788. * @see #getClassInitializer()
  789. */
  790. public CtConstructor makeClassInitializer()
  791. throws CannotCompileException
  792. {
  793. throw new CannotCompileException("not a class");
  794. }
  795. /**
  796. * Adds a constructor. To add a class initializer (static constructor),
  797. * call <code>makeClassInitializer()</code>.
  798. *
  799. * @see #makeClassInitializer()
  800. */
  801. public void addConstructor(CtConstructor c)
  802. throws CannotCompileException
  803. {
  804. checkModify();
  805. }
  806. /**
  807. * Removes a constructor declared in this class.
  808. *
  809. * @param c removed constructor.
  810. * @throws NotFoundException if the constructor is not found.
  811. */
  812. public void removeConstructor(CtConstructor c) throws NotFoundException {
  813. checkModify();
  814. }
  815. /**
  816. * Adds a method.
  817. */
  818. public void addMethod(CtMethod m) throws CannotCompileException {
  819. checkModify();
  820. }
  821. /**
  822. * Removes a method declared in this class.
  823. *
  824. * @param m removed method.
  825. * @throws NotFoundException if the method is not found.
  826. */
  827. public void removeMethod(CtMethod m) throws NotFoundException {
  828. checkModify();
  829. }
  830. /**
  831. * Adds a field.
  832. *
  833. * <p>The <code>CtField</code> belonging to another
  834. * <code>CtClass</code> cannot be directly added to this class.
  835. * Only a field created for this class can be added.
  836. *
  837. * @see javassist.CtField#CtField(CtField,CtClass)
  838. */
  839. public void addField(CtField f) throws CannotCompileException {
  840. addField(f, (CtField.Initializer)null);
  841. }
  842. /**
  843. * Adds a field with an initial value.
  844. *
  845. * <p>The <code>CtField</code> belonging to another
  846. * <code>CtClass</code> cannot be directly added to this class.
  847. * Only a field created for this class can be added.
  848. *
  849. * <p>The initial value is given as an expression written in Java.
  850. * Any regular Java expression can be used for specifying the initial
  851. * value. The followings are examples.
  852. *
  853. * <ul><pre>
  854. * cc.addField(f, "0") // the initial value is 0.
  855. * cc.addField(f, "i + 1") // i + 1.
  856. * cc.addField(f, "new Point()"); // a Point object.
  857. * </pre></ul>
  858. *
  859. * <p>Here, the type of variable <code>cc</code> is <code>CtClass</code>.
  860. * The type of <code>f</code> is <code>CtField</code>.
  861. *
  862. * <p>Note: do not change the modifier of the field
  863. * (in particular, do not add or remove <code>static</code>
  864. * to/from the modifier)
  865. * after it is added to the class by <code>addField()</code>.
  866. *
  867. * @param init an expression for the initial value.
  868. *
  869. * @see javassist.CtField.Initializer#byExpr(String)
  870. * @see javassist.CtField#CtField(CtField,CtClass)
  871. */
  872. public void addField(CtField f, String init)
  873. throws CannotCompileException
  874. {
  875. checkModify();
  876. }
  877. /**
  878. * Adds a field with an initial value.
  879. *
  880. * <p>The <code>CtField</code> belonging to another
  881. * <code>CtClass</code> cannot be directly added to this class.
  882. * Only a field created for this class can be added.
  883. *
  884. * <p>For example,
  885. *
  886. * <ul><pre>
  887. * CtClass cc = ...;
  888. * addField(new CtField(CtClass.intType, "i", cc),
  889. * CtField.Initializer.constant(1));
  890. * </pre></ul>
  891. *
  892. * <p>This code adds an <code>int</code> field named "i". The
  893. * initial value of this field is 1.
  894. *
  895. * @param init specifies the initial value of the field.
  896. *
  897. * @see javassist.CtField#CtField(CtField,CtClass)
  898. */
  899. public void addField(CtField f, CtField.Initializer init)
  900. throws CannotCompileException
  901. {
  902. checkModify();
  903. }
  904. /**
  905. * Removes a field declared in this class.
  906. *
  907. * @param f removed field.
  908. * @throws NotFoundException if the field is not found.
  909. */
  910. public void removeField(CtField f) throws NotFoundException {
  911. checkModify();
  912. }
  913. /**
  914. * Obtains an attribute with the given name.
  915. * If that attribute is not found in the class file, this
  916. * method returns null.
  917. *
  918. * <p>This is a convenient method mainly for obtaining
  919. * a user-defined attribute. For dealing with attributes, see the
  920. * <code>javassist.bytecode</code> package. For example, the following
  921. * expression returns all the attributes of a class file.
  922. *
  923. * <ul><pre>
  924. * getClassFile().getAttributes()
  925. * </pre></ul>
  926. *
  927. * @param name attribute name
  928. * @see javassist.bytecode.AttributeInfo
  929. */
  930. public byte[] getAttribute(String name) {
  931. return null;
  932. }
  933. /**
  934. * Adds a named attribute.
  935. * An arbitrary data (smaller than 64Kb) can be saved in the class
  936. * file. Some attribute name are reserved by the JVM.
  937. * The attributes with the non-reserved names are ignored when a
  938. * class file is loaded into the JVM.
  939. * If there is already an attribute with
  940. * the same name, this method substitutes the new one for it.
  941. *
  942. * <p>This is a convenient method mainly for adding
  943. * a user-defined attribute. For dealing with attributes, see the
  944. * <code>javassist.bytecode</code> package. For example, the following
  945. * expression adds an attribute <code>info</code> to a class file.
  946. *
  947. * <ul><pre>
  948. * getClassFile().addAttribute(info)
  949. * </pre></ul>
  950. *
  951. * @param name attribute name
  952. * @param data attribute value
  953. * @see javassist.bytecode.AttributeInfo
  954. */
  955. public void setAttribute(String name, byte[] data) {
  956. checkModify();
  957. }
  958. /**
  959. * Applies the given converter to all methods and constructors
  960. * declared in the class. This method calls <code>instrument()</code>
  961. * on every <code>CtMethod</code> and <code>CtConstructor</code> object
  962. * in the class.
  963. *
  964. * @param converter specifies how to modify.
  965. */
  966. public void instrument(CodeConverter converter)
  967. throws CannotCompileException
  968. {
  969. checkModify();
  970. }
  971. /**
  972. * Modifies the bodies of all methods and constructors
  973. * declared in the class. This method calls <code>instrument()</code>
  974. * on every <code>CtMethod</code> and <code>CtConstructor</code> object
  975. * in the class.
  976. *
  977. * @param editor specifies how to modify.
  978. */
  979. public void instrument(ExprEditor editor)
  980. throws CannotCompileException
  981. {
  982. checkModify();
  983. }
  984. /**
  985. * Converts this class to a <code>java.lang.Class</code> object.
  986. * Once this method is called, further modifications are not
  987. * allowed any more.
  988. * To load the class, this method uses the context class loader
  989. * of the current thread. If the program is running on some application
  990. * server, the context class loader might be inappropriate to load the
  991. * class.
  992. *
  993. * <p>This method is provided for convenience. If you need more
  994. * complex functionality, you should write your own class loader.
  995. *
  996. * <p>Note: this method calls <code>toClass()</code>
  997. * in <code>ClassPool</code>.
  998. *
  999. * <p><b>Warining:</b> A Class object returned by this method may not
  1000. * work with a security manager or a signed jar file because a
  1001. * protection domain is not specified.
  1002. *
  1003. * @see #toClass(java.lang.ClassLoader,ProtectionDomain)
  1004. * @see ClassPool#toClass(CtClass)
  1005. */
  1006. public Class toClass() throws CannotCompileException {
  1007. return getClassPool().toClass(this);
  1008. }
  1009. /**
  1010. * Converts this class to a <code>java.lang.Class</code> object.
  1011. * Once this method is called, further modifications are not allowed
  1012. * any more.
  1013. *
  1014. * <p>The class file represented by this <code>CtClass</code> is
  1015. * loaded by the given class loader to construct a
  1016. * <code>java.lang.Class</code> object. Since a private method
  1017. * on the class loader is invoked through the reflection API,
  1018. * the caller must have permissions to do that.
  1019. *
  1020. * <p>An easy way to obtain <code>ProtectionDomain</code> object is
  1021. * to call <code>getProtectionDomain()</code>
  1022. * in <code>java.lang.Class</code>. It returns the domain that
  1023. * the class belongs to.
  1024. *
  1025. * <p>This method is provided for convenience. If you need more
  1026. * complex functionality, you should write your own class loader.
  1027. *
  1028. * <p>Note: this method calls <code>toClass()</code>
  1029. * in <code>ClassPool</code>.
  1030. *
  1031. * @param loader the class loader used to load this class.
  1032. * If it is null, the class loader returned by
  1033. * {@link ClassPool#getClassLoader()} is used.
  1034. * @param domain the protection domain that the class belongs to.
  1035. * If it is null, the default domain created
  1036. * by <code>java.lang.ClassLoader</code> is used.
  1037. * @see ClassPool#toClass(CtClass,java.lang.ClassLoader)
  1038. * @since 3.3
  1039. */
  1040. public Class toClass(ClassLoader loader, ProtectionDomain domain)
  1041. throws CannotCompileException
  1042. {
  1043. ClassPool cp = getClassPool();
  1044. if (loader == null)
  1045. loader = cp.getClassLoader();
  1046. return cp.toClass(this, loader, domain);
  1047. }
  1048. /**
  1049. * Converts this class to a <code>java.lang.Class</code> object.
  1050. *
  1051. * <p><b>Warining:</b> A Class object returned by this method may not
  1052. * work with a security manager or a signed jar file because a
  1053. * protection domain is not specified.
  1054. *
  1055. * @deprecated Replaced by {@link #toClass(ClassLoader,ProtectionDomain)}
  1056. */
  1057. public final Class toClass(ClassLoader loader)
  1058. throws CannotCompileException
  1059. {
  1060. return getClassPool().toClass(this, loader);
  1061. }
  1062. /**
  1063. * Removes this <code>CtClass</code> object from the
  1064. * <code>ClassPool</code>.
  1065. * After this method is called, any method cannot be called on the
  1066. * removed <code>CtClass</code> object.
  1067. *
  1068. * <p>If <code>get()</code> in <code>ClassPool</code> is called
  1069. * with the name of the removed method,
  1070. * the <code>ClassPool</code> will read the class file again
  1071. * and constructs another <code>CtClass</code> object representing
  1072. * the same class.
  1073. */
  1074. public void detach() {
  1075. ClassPool cp = getClassPool();
  1076. CtClass obj = cp.removeCached(getName());
  1077. if (obj != this)
  1078. cp.cacheCtClass(getName(), obj, false);
  1079. }
  1080. /**
  1081. * Disallows (or allows) automatically pruning this <code>CtClass</code>
  1082. * object.
  1083. *
  1084. * <p>
  1085. * Javassist can automatically prune a <code>CtClass</code> object
  1086. * when <code>toBytecode()</code> (or <code>toClass()</code>,
  1087. * <code>writeFile()</code>) is called.
  1088. * Since a <code>ClassPool</code> holds all instances of <code>CtClass</code>
  1089. * even after <code>toBytecode()</code> (or <code>toClass()</code>,
  1090. * <code>writeFile()</code>) is called, pruning may significantly
  1091. * save memory consumption.
  1092. *
  1093. * <p>If <code>ClassPool.doPruning</code> is true, the automatic pruning
  1094. * is on by default. Otherwise, it is off. The default value of
  1095. * <code>ClassPool.doPruning</code> is false.
  1096. *
  1097. * @param stop disallow pruning if true. Otherwise, allow.
  1098. * @return the previous status of pruning. true if pruning is already stopped.
  1099. *
  1100. * @see #detach()
  1101. * @see #prune()
  1102. * @see ClassPool#doPruning
  1103. */
  1104. public boolean stopPruning(boolean stop) { return true; }
  1105. /**
  1106. * Discards unnecessary attributes, in particular,
  1107. * <code>CodeAttribute</code>s (method bodies) of the class,
  1108. * to minimize the memory footprint.
  1109. * After calling this method, the class is read only.
  1110. * It cannot be modified any more.
  1111. * Furthermore, <code>toBytecode()</code>,
  1112. * <code>writeFile()</code>, <code>toClass()</code>,
  1113. * or <code>instrument()</code> cannot be called.
  1114. * However, the method names and signatures in the class etc.
  1115. * are still accessible.
  1116. *
  1117. * <p><code>toBytecode()</code>, <code>writeFile()</code>, and
  1118. * <code>toClass()</code> internally call this method if
  1119. * automatic pruning is on.
  1120. *
  1121. * <p>According to some experiments, pruning does not really reduce
  1122. * memory consumption. Only about 20%. Since pruning takes time,
  1123. * it might not pay off. So the automatic pruning is off by default.
  1124. *
  1125. * @see #stopPruning(boolean)
  1126. * @see #detach()
  1127. * @see ClassPool#doPruning
  1128. *
  1129. * @see #toBytecode()
  1130. * @see #toClass()
  1131. * @see #writeFile()
  1132. * @see #instrument(CodeConverter)
  1133. * @see #instrument(ExprEditor)
  1134. */
  1135. public void prune() {}
  1136. /* Called by get() in ClassPool.
  1137. * CtClassType overrides this method.
  1138. */
  1139. void incGetCounter() {}
  1140. /**
  1141. * If this method is called, the class file will be
  1142. * rebuilt when it is finally generated by
  1143. * <code>toBytecode()</code> and <code>writeFile()</code>.
  1144. * For a performance reason, the symbol table of the
  1145. * class file may contain unused entries, for example,
  1146. * after a method or a filed is deleted.
  1147. * This method
  1148. * removes those unused entries. This removal will
  1149. * minimize the size of the class file.
  1150. *
  1151. * @since 3.8.1
  1152. */
  1153. public void rebuildClassFile() {}
  1154. /**
  1155. * Converts this class to a class file.
  1156. * Once this method is called, further modifications are not
  1157. * possible any more.
  1158. *
  1159. * @return the contents of the class file.
  1160. */
  1161. public byte[] toBytecode() throws IOException, CannotCompileException {
  1162. ByteArrayOutputStream barray = new ByteArrayOutputStream();
  1163. DataOutputStream out = new DataOutputStream(barray);
  1164. try {
  1165. toBytecode(out);
  1166. }
  1167. finally {
  1168. out.close();
  1169. }
  1170. return barray.toByteArray();
  1171. }
  1172. /**
  1173. * Writes a class file represented by this <code>CtClass</code>
  1174. * object in the current directory.
  1175. * Once this method is called, further modifications are not
  1176. * possible any more.
  1177. *
  1178. * @see #debugWriteFile()
  1179. */
  1180. public void writeFile()
  1181. throws NotFoundException, IOException, CannotCompileException
  1182. {
  1183. writeFile(".");
  1184. }
  1185. /**
  1186. * Writes a class file represented by this <code>CtClass</code>
  1187. * object on a local disk.
  1188. * Once this method is called, further modifications are not
  1189. * possible any more.
  1190. *
  1191. * @param directoryName it must end without a directory separator.
  1192. * @see #debugWriteFile(String)
  1193. */
  1194. public void writeFile(String directoryName)
  1195. throws CannotCompileException, IOException
  1196. {
  1197. String classname = getName();
  1198. String filename = directoryName + File.separatorChar
  1199. + classname.replace('.', File.separatorChar) + ".class";
  1200. int pos = filename.lastIndexOf(File.separatorChar);
  1201. if (pos > 0) {
  1202. String dir = filename.substring(0, pos);
  1203. if (!dir.equals("."))
  1204. new File(dir).mkdirs();
  1205. }
  1206. DataOutputStream out
  1207. = new DataOutputStream(new BufferedOutputStream(
  1208. new DelayedFileOutputStream(filename)));
  1209. try {
  1210. toBytecode(out);
  1211. }
  1212. finally {
  1213. out.close();
  1214. }
  1215. }
  1216. /**
  1217. * Writes a class file as <code>writeFile()</code> does although this
  1218. * method does not prune or freeze the class after writing the class
  1219. * file. Note that, once <code>writeFile()</code> or <code>toBytecode()</code>
  1220. * is called, it cannot be called again since the class is pruned and frozen.
  1221. * This method would be useful for debugging.
  1222. */
  1223. public void debugWriteFile() {
  1224. debugWriteFile(".");
  1225. }
  1226. /**
  1227. * Writes a class file as <code>writeFile()</code> does although this
  1228. * method does not prune or freeze the class after writing the class
  1229. * file. Note that, once <code>writeFile()</code> or <code>toBytecode()</code>
  1230. * is called, it cannot be called again since the class is pruned and frozen.
  1231. * This method would be useful for debugging.
  1232. *
  1233. * @param directoryName it must end without a directory separator.
  1234. */
  1235. public void debugWriteFile(String directoryName) {
  1236. try {
  1237. boolean p = stopPruning(true);
  1238. writeFile(directoryName);
  1239. defrost();
  1240. stopPruning(p);
  1241. }
  1242. catch (Exception e) {
  1243. throw new RuntimeException(e);
  1244. }
  1245. }
  1246. static class DelayedFileOutputStream extends OutputStream {
  1247. private FileOutputStream file;
  1248. private String filename;
  1249. DelayedFileOutputStream(String name) {
  1250. file = null;
  1251. filename = name;
  1252. }
  1253. private void init() throws IOException {
  1254. if (file == null)
  1255. file = new FileOutputStream(filename);
  1256. }
  1257. public void write(int b) throws IOException {
  1258. init();
  1259. file.write(b);
  1260. }
  1261. public void write(byte[] b) throws IOException {
  1262. init();
  1263. file.write(b);
  1264. }
  1265. public void write(byte[] b, int off, int len) throws IOException {
  1266. init();
  1267. file.write(b, off, len);
  1268. }
  1269. public void flush() throws IOException {
  1270. init();
  1271. file.flush();
  1272. }
  1273. public void close() throws IOException {
  1274. init();
  1275. file.close();
  1276. }
  1277. }
  1278. /**
  1279. * Converts this class to a class file.
  1280. * Once this method is called, further modifications are not
  1281. * possible any more.
  1282. *
  1283. * <p>This method dose not close the output stream in the end.
  1284. *
  1285. * @param out the output stream that a class file is written to.
  1286. */
  1287. public void toBytecode(DataOutputStream out)
  1288. throws CannotCompileException, IOException
  1289. {
  1290. throw new CannotCompileException("not a class");
  1291. }
  1292. /**
  1293. * Makes a unique member name. This method guarantees that
  1294. * the returned name is not used as a prefix of any methods
  1295. * or fields visible in this class.
  1296. * If the returned name is XYZ, then any method or field names
  1297. * in this class do not start with XYZ.
  1298. *
  1299. * @param prefix the prefix of the member name.
  1300. */
  1301. public String makeUniqueName(String prefix) {
  1302. throw new RuntimeException("not available in " + getName());
  1303. }
  1304. /* Invoked from ClassPool#compress().
  1305. * This method is overridden by CtClassType.
  1306. */
  1307. void compress() {}
  1308. }