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.

SignatureAttribute.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later,
  9. * or the Apache License Version 2.0.
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. */
  16. package javassist.bytecode;
  17. import java.io.DataInputStream;
  18. import java.io.IOException;
  19. import java.util.Map;
  20. import java.util.ArrayList;
  21. import javassist.CtClass;
  22. /**
  23. * <code>Signature_attribute</code>.
  24. */
  25. public class SignatureAttribute extends AttributeInfo {
  26. /**
  27. * The name of this attribute <code>"Signature"</code>.
  28. */
  29. public static final String tag = "Signature";
  30. SignatureAttribute(ConstPool cp, int n, DataInputStream in)
  31. throws IOException
  32. {
  33. super(cp, n, in);
  34. }
  35. /**
  36. * Constructs a Signature attribute.
  37. *
  38. * @param cp a constant pool table.
  39. * @param signature the signature represented by this attribute.
  40. */
  41. public SignatureAttribute(ConstPool cp, String signature) {
  42. super(cp, tag);
  43. int index = cp.addUtf8Info(signature);
  44. byte[] bvalue = new byte[2];
  45. bvalue[0] = (byte)(index >>> 8);
  46. bvalue[1] = (byte)index;
  47. set(bvalue);
  48. }
  49. /**
  50. * Returns the signature indicated by <code>signature_index</code>.
  51. *
  52. * @see #toClassSignature(String)
  53. * @see #toMethodSignature(String)
  54. */
  55. public String getSignature() {
  56. return getConstPool().getUtf8Info(ByteArray.readU16bit(get(), 0));
  57. }
  58. /**
  59. * Sets <code>signature_index</code> to the index of the given signature,
  60. * which is added to a constant pool.
  61. *
  62. * @param sig new signature.
  63. * @since 3.11
  64. */
  65. public void setSignature(String sig) {
  66. int index = getConstPool().addUtf8Info(sig);
  67. ByteArray.write16bit(index, info, 0);
  68. }
  69. /**
  70. * Makes a copy. Class names are replaced according to the
  71. * given <code>Map</code> object.
  72. *
  73. * @param newCp the constant pool table used by the new copy.
  74. * @param classnames pairs of replaced and substituted
  75. * class names.
  76. */
  77. public AttributeInfo copy(ConstPool newCp, Map classnames) {
  78. return new SignatureAttribute(newCp, getSignature());
  79. }
  80. void renameClass(String oldname, String newname) {
  81. String sig = renameClass(getSignature(), oldname, newname);
  82. setSignature(sig);
  83. }
  84. void renameClass(Map classnames) {
  85. String sig = renameClass(getSignature(), classnames);
  86. setSignature(sig);
  87. }
  88. static String renameClass(String desc, String oldname, String newname) {
  89. Map map = new java.util.HashMap();
  90. map.put(oldname, newname);
  91. return renameClass(desc, map);
  92. }
  93. static String renameClass(String desc, Map map) {
  94. if (map == null)
  95. return desc;
  96. StringBuilder newdesc = new StringBuilder();
  97. int head = 0;
  98. int i = 0;
  99. for (;;) {
  100. int j = desc.indexOf('L', i);
  101. if (j < 0)
  102. break;
  103. StringBuilder nameBuf = new StringBuilder();
  104. int k = j;
  105. char c;
  106. try {
  107. while ((c = desc.charAt(++k)) != ';') {
  108. nameBuf.append(c);
  109. if (c == '<') {
  110. while ((c = desc.charAt(++k)) != '>')
  111. nameBuf.append(c);
  112. nameBuf.append(c);
  113. }
  114. }
  115. }
  116. catch (IndexOutOfBoundsException e) { break; }
  117. i = k + 1;
  118. String name = nameBuf.toString();
  119. String name2 = (String)map.get(name);
  120. if (name2 != null) {
  121. newdesc.append(desc.substring(head, j));
  122. newdesc.append('L');
  123. newdesc.append(name2);
  124. newdesc.append(c);
  125. head = i;
  126. }
  127. }
  128. if (head == 0)
  129. return desc;
  130. else {
  131. int len = desc.length();
  132. if (head < len)
  133. newdesc.append(desc.substring(head, len));
  134. return newdesc.toString();
  135. }
  136. }
  137. private static boolean isNamePart(int c) {
  138. return c != ';' && c != '<';
  139. }
  140. static private class Cursor {
  141. int position = 0;
  142. int indexOf(String s, int ch) throws BadBytecode {
  143. int i = s.indexOf(ch, position);
  144. if (i < 0)
  145. throw error(s);
  146. else {
  147. position = i + 1;
  148. return i;
  149. }
  150. }
  151. }
  152. /**
  153. * Class signature.
  154. */
  155. public static class ClassSignature {
  156. TypeParameter[] params;
  157. ClassType superClass;
  158. ClassType[] interfaces;
  159. ClassSignature(TypeParameter[] p, ClassType s, ClassType[] i) {
  160. params = p;
  161. superClass = s;
  162. interfaces = i;
  163. }
  164. /**
  165. * Returns the type parameters.
  166. *
  167. * @return a zero-length array if the type parameters are not specified.
  168. */
  169. public TypeParameter[] getParameters() {
  170. return params;
  171. }
  172. /**
  173. * Returns the super class.
  174. */
  175. public ClassType getSuperClass() { return superClass; }
  176. /**
  177. * Returns the super interfaces.
  178. *
  179. * @return a zero-length array if the super interfaces are not specified.
  180. */
  181. public ClassType[] getInterfaces() { return interfaces; }
  182. /**
  183. * Returns the string representation.
  184. */
  185. public String toString() {
  186. StringBuffer sbuf = new StringBuffer();
  187. TypeParameter.toString(sbuf, params);
  188. sbuf.append(" extends ").append(superClass);
  189. if (interfaces.length > 0) {
  190. sbuf.append(" implements ");
  191. Type.toString(sbuf, interfaces);
  192. }
  193. return sbuf.toString();
  194. }
  195. }
  196. /**
  197. * Method type signature.
  198. */
  199. public static class MethodSignature {
  200. TypeParameter[] typeParams;
  201. Type[] params;
  202. Type retType;
  203. ObjectType[] exceptions;
  204. MethodSignature(TypeParameter[] tp, Type[] p, Type ret, ObjectType[] ex) {
  205. typeParams = tp;
  206. params = p;
  207. retType = ret;
  208. exceptions = ex;
  209. }
  210. /**
  211. * Returns the formal type parameters.
  212. *
  213. * @return a zero-length array if the type parameters are not specified.
  214. */
  215. public TypeParameter[] getTypeParameters() { return typeParams; }
  216. /**
  217. * Returns the types of the formal parameters.
  218. *
  219. * @return a zero-length array if no formal parameter is taken.
  220. */
  221. public Type[] getParameterTypes() { return params; }
  222. /**
  223. * Returns the type of the returned value.
  224. */
  225. public Type getReturnType() { return retType; }
  226. /**
  227. * Returns the types of the exceptions that may be thrown.
  228. *
  229. * @return a zero-length array if exceptions are never thrown or
  230. * the exception types are not parameterized types or type variables.
  231. */
  232. public ObjectType[] getExceptionTypes() { return exceptions; }
  233. /**
  234. * Returns the string representation.
  235. */
  236. public String toString() {
  237. StringBuffer sbuf = new StringBuffer();
  238. TypeParameter.toString(sbuf, typeParams);
  239. sbuf.append(" (");
  240. Type.toString(sbuf, params);
  241. sbuf.append(") ");
  242. sbuf.append(retType);
  243. if (exceptions.length > 0) {
  244. sbuf.append(" throws ");
  245. Type.toString(sbuf, exceptions);
  246. }
  247. return sbuf.toString();
  248. }
  249. }
  250. /**
  251. * Formal type parameters.
  252. */
  253. public static class TypeParameter {
  254. String name;
  255. ObjectType superClass;
  256. ObjectType[] superInterfaces;
  257. TypeParameter(String sig, int nb, int ne, ObjectType sc, ObjectType[] si) {
  258. name = sig.substring(nb, ne);
  259. superClass = sc;
  260. superInterfaces = si;
  261. }
  262. /**
  263. * Returns the name of the type parameter.
  264. */
  265. public String getName() {
  266. return name;
  267. }
  268. /**
  269. * Returns the class bound of this parameter.
  270. *
  271. * @return null if the class bound is not specified.
  272. */
  273. public ObjectType getClassBound() { return superClass; }
  274. /**
  275. * Returns the interface bound of this parameter.
  276. *
  277. * @return a zero-length array if the interface bound is not specified.
  278. */
  279. public ObjectType[] getInterfaceBound() { return superInterfaces; }
  280. /**
  281. * Returns the string representation.
  282. */
  283. public String toString() {
  284. StringBuffer sbuf = new StringBuffer(getName());
  285. if (superClass != null)
  286. sbuf.append(" extends ").append(superClass.toString());
  287. int len = superInterfaces.length;
  288. if (len > 0) {
  289. for (int i = 0; i < len; i++) {
  290. if (i > 0 || superClass != null)
  291. sbuf.append(" & ");
  292. else
  293. sbuf.append(" extends ");
  294. sbuf.append(superInterfaces[i].toString());
  295. }
  296. }
  297. return sbuf.toString();
  298. }
  299. static void toString(StringBuffer sbuf, TypeParameter[] tp) {
  300. sbuf.append('<');
  301. for (int i = 0; i < tp.length; i++) {
  302. if (i > 0)
  303. sbuf.append(", ");
  304. sbuf.append(tp[i]);
  305. }
  306. sbuf.append('>');
  307. }
  308. }
  309. /**
  310. * Type argument.
  311. */
  312. public static class TypeArgument {
  313. ObjectType arg;
  314. char wildcard;
  315. TypeArgument(ObjectType a, char w) {
  316. arg = a;
  317. wildcard = w;
  318. }
  319. /**
  320. * Returns the kind of this type argument.
  321. *
  322. * @return <code>' '</code> (not-wildcard), <code>'*'</code> (wildcard), <code>'+'</code> (wildcard with
  323. * upper bound), or <code>'-'</code> (wildcard with lower bound).
  324. */
  325. public char getKind() { return wildcard; }
  326. /**
  327. * Returns true if this type argument is a wildcard type
  328. * such as <code>?</code>, <code>? extends String</code>, or <code>? super Integer</code>.
  329. */
  330. public boolean isWildcard() { return wildcard != ' '; }
  331. /**
  332. * Returns the type represented by this argument
  333. * if the argument is not a wildcard type. Otherwise, this method
  334. * returns the upper bound (if the kind is '+'),
  335. * the lower bound (if the kind is '-'), or null (if the upper or lower
  336. * bound is not specified).
  337. */
  338. public ObjectType getType() { return arg; }
  339. /**
  340. * Returns the string representation.
  341. */
  342. public String toString() {
  343. if (wildcard == '*')
  344. return "?";
  345. String type = arg.toString();
  346. if (wildcard == ' ')
  347. return type;
  348. else if (wildcard == '+')
  349. return "? extends " + type;
  350. else
  351. return "? super " + type;
  352. }
  353. }
  354. /**
  355. * Primitive types and object types.
  356. */
  357. public static abstract class Type {
  358. static void toString(StringBuffer sbuf, Type[] ts) {
  359. for (int i = 0; i < ts.length; i++) {
  360. if (i > 0)
  361. sbuf.append(", ");
  362. sbuf.append(ts[i]);
  363. }
  364. }
  365. }
  366. /**
  367. * Primitive types.
  368. */
  369. public static class BaseType extends Type {
  370. char descriptor;
  371. BaseType(char c) { descriptor = c; }
  372. /**
  373. * Returns the descriptor representing this primitive type.
  374. *
  375. * @see javassist.bytecode.Descriptor
  376. */
  377. public char getDescriptor() { return descriptor; }
  378. /**
  379. * Returns the <code>CtClass</code> representing this
  380. * primitive type.
  381. */
  382. public CtClass getCtlass() {
  383. return Descriptor.toPrimitiveClass(descriptor);
  384. }
  385. /**
  386. * Returns the string representation.
  387. */
  388. public String toString() {
  389. return Descriptor.toClassName(Character.toString(descriptor));
  390. }
  391. }
  392. /**
  393. * Class types, array types, and type variables.
  394. */
  395. public static abstract class ObjectType extends Type {}
  396. /**
  397. * Class types.
  398. */
  399. public static class ClassType extends ObjectType {
  400. String name;
  401. TypeArgument[] arguments;
  402. static ClassType make(String s, int b, int e,
  403. TypeArgument[] targs, ClassType parent) {
  404. if (parent == null)
  405. return new ClassType(s, b, e, targs);
  406. else
  407. return new NestedClassType(s, b, e, targs, parent);
  408. }
  409. ClassType(String signature, int begin, int end, TypeArgument[] targs) {
  410. name = signature.substring(begin, end).replace('/', '.');
  411. arguments = targs;
  412. }
  413. /**
  414. * Returns the class name.
  415. */
  416. public String getName() {
  417. return name;
  418. }
  419. /**
  420. * Returns the type arguments.
  421. *
  422. * @return null if no type arguments are given to this class.
  423. */
  424. public TypeArgument[] getTypeArguments() { return arguments; }
  425. /**
  426. * If this class is a member of another class, returns the
  427. * class in which this class is declared.
  428. *
  429. * @return null if this class is not a member of another class.
  430. */
  431. public ClassType getDeclaringClass() { return null; }
  432. /**
  433. * Returns the string representation.
  434. */
  435. public String toString() {
  436. StringBuffer sbuf = new StringBuffer();
  437. ClassType parent = getDeclaringClass();
  438. if (parent != null)
  439. sbuf.append(parent.toString()).append('.');
  440. sbuf.append(name);
  441. if (arguments != null) {
  442. sbuf.append('<');
  443. int n = arguments.length;
  444. for (int i = 0; i < n; i++) {
  445. if (i > 0)
  446. sbuf.append(", ");
  447. sbuf.append(arguments[i].toString());
  448. }
  449. sbuf.append('>');
  450. }
  451. return sbuf.toString();
  452. }
  453. }
  454. /**
  455. * Nested class types.
  456. */
  457. public static class NestedClassType extends ClassType {
  458. ClassType parent;
  459. NestedClassType(String s, int b, int e,
  460. TypeArgument[] targs, ClassType p) {
  461. super(s, b, e, targs);
  462. parent = p;
  463. }
  464. /**
  465. * Returns the class that declares this nested class.
  466. * This nested class is a member of that declaring class.
  467. */
  468. public ClassType getDeclaringClass() { return parent; }
  469. }
  470. /**
  471. * Array types.
  472. */
  473. public static class ArrayType extends ObjectType {
  474. int dim;
  475. Type componentType;
  476. public ArrayType(int d, Type comp) {
  477. dim = d;
  478. componentType = comp;
  479. }
  480. /**
  481. * Returns the dimension of the array.
  482. */
  483. public int getDimension() { return dim; }
  484. /**
  485. * Returns the component type.
  486. */
  487. public Type getComponentType() {
  488. return componentType;
  489. }
  490. /**
  491. * Returns the string representation.
  492. */
  493. public String toString() {
  494. StringBuffer sbuf = new StringBuffer(componentType.toString());
  495. for (int i = 0; i < dim; i++)
  496. sbuf.append("[]");
  497. return sbuf.toString();
  498. }
  499. }
  500. /**
  501. * Type variables.
  502. */
  503. public static class TypeVariable extends ObjectType {
  504. String name;
  505. TypeVariable(String sig, int begin, int end) {
  506. name = sig.substring(begin, end);
  507. }
  508. /**
  509. * Returns the variable name.
  510. */
  511. public String getName() {
  512. return name;
  513. }
  514. /**
  515. * Returns the string representation.
  516. */
  517. public String toString() {
  518. return name;
  519. }
  520. }
  521. /**
  522. * Parses the given signature string as a class signature.
  523. *
  524. * @param sig the signature.
  525. * @throws BadBytecode thrown when a syntactical error is found.
  526. * @since 3.5
  527. */
  528. public static ClassSignature toClassSignature(String sig) throws BadBytecode {
  529. try {
  530. return parseSig(sig);
  531. }
  532. catch (IndexOutOfBoundsException e) {
  533. throw error(sig);
  534. }
  535. }
  536. /**
  537. * Parses the given signature string as a method type signature.
  538. *
  539. * @param sig the signature.
  540. * @throws BadBytecode thrown when a syntactical error is found.
  541. * @since 3.5
  542. */
  543. public static MethodSignature toMethodSignature(String sig) throws BadBytecode {
  544. try {
  545. return parseMethodSig(sig);
  546. }
  547. catch (IndexOutOfBoundsException e) {
  548. throw error(sig);
  549. }
  550. }
  551. /**
  552. * Parses the given signature string as a field type signature.
  553. *
  554. * @param sig the signature string.
  555. * @return the field type signature.
  556. * @throws BadBytecode thrown when a syntactical error is found.
  557. * @since 3.5
  558. */
  559. public static ObjectType toFieldSignature(String sig) throws BadBytecode {
  560. try {
  561. return parseObjectType(sig, new Cursor(), false);
  562. }
  563. catch (IndexOutOfBoundsException e) {
  564. throw error(sig);
  565. }
  566. }
  567. private static ClassSignature parseSig(String sig)
  568. throws BadBytecode, IndexOutOfBoundsException
  569. {
  570. Cursor cur = new Cursor();
  571. TypeParameter[] tp = parseTypeParams(sig, cur);
  572. ClassType superClass = parseClassType(sig, cur);
  573. int sigLen = sig.length();
  574. ArrayList ifArray = new ArrayList();
  575. while (cur.position < sigLen && sig.charAt(cur.position) == 'L')
  576. ifArray.add(parseClassType(sig, cur));
  577. ClassType[] ifs
  578. = (ClassType[])ifArray.toArray(new ClassType[ifArray.size()]);
  579. return new ClassSignature(tp, superClass, ifs);
  580. }
  581. private static MethodSignature parseMethodSig(String sig)
  582. throws BadBytecode
  583. {
  584. Cursor cur = new Cursor();
  585. TypeParameter[] tp = parseTypeParams(sig, cur);
  586. if (sig.charAt(cur.position++) != '(')
  587. throw error(sig);
  588. ArrayList params = new ArrayList();
  589. while (sig.charAt(cur.position) != ')') {
  590. Type t = parseType(sig, cur);
  591. params.add(t);
  592. }
  593. cur.position++;
  594. Type ret = parseType(sig, cur);
  595. int sigLen = sig.length();
  596. ArrayList exceptions = new ArrayList();
  597. while (cur.position < sigLen && sig.charAt(cur.position) == '^') {
  598. cur.position++;
  599. ObjectType t = parseObjectType(sig, cur, false);
  600. if (t instanceof ArrayType)
  601. throw error(sig);
  602. exceptions.add(t);
  603. }
  604. Type[] p = (Type[])params.toArray(new Type[params.size()]);
  605. ObjectType[] ex = (ObjectType[])exceptions.toArray(new ObjectType[exceptions.size()]);
  606. return new MethodSignature(tp, p, ret, ex);
  607. }
  608. private static TypeParameter[] parseTypeParams(String sig, Cursor cur)
  609. throws BadBytecode
  610. {
  611. ArrayList typeParam = new ArrayList();
  612. if (sig.charAt(cur.position) == '<') {
  613. cur.position++;
  614. while (sig.charAt(cur.position) != '>') {
  615. int nameBegin = cur.position;
  616. int nameEnd = cur.indexOf(sig, ':');
  617. ObjectType classBound = parseObjectType(sig, cur, true);
  618. ArrayList ifBound = new ArrayList();
  619. while (sig.charAt(cur.position) == ':') {
  620. cur.position++;
  621. ObjectType t = parseObjectType(sig, cur, false);
  622. ifBound.add(t);
  623. }
  624. TypeParameter p = new TypeParameter(sig, nameBegin, nameEnd,
  625. classBound, (ObjectType[])ifBound.toArray(new ObjectType[ifBound.size()]));
  626. typeParam.add(p);
  627. }
  628. cur.position++;
  629. }
  630. return (TypeParameter[])typeParam.toArray(new TypeParameter[typeParam.size()]);
  631. }
  632. private static ObjectType parseObjectType(String sig, Cursor c, boolean dontThrow)
  633. throws BadBytecode
  634. {
  635. int i;
  636. int begin = c.position;
  637. switch (sig.charAt(begin)) {
  638. case 'L' :
  639. return parseClassType2(sig, c, null);
  640. case 'T' :
  641. i = c.indexOf(sig, ';');
  642. return new TypeVariable(sig, begin + 1, i);
  643. case '[' :
  644. return parseArray(sig, c);
  645. default :
  646. if (dontThrow)
  647. return null;
  648. else
  649. throw error(sig);
  650. }
  651. }
  652. private static ClassType parseClassType(String sig, Cursor c)
  653. throws BadBytecode
  654. {
  655. if (sig.charAt(c.position) == 'L')
  656. return parseClassType2(sig, c, null);
  657. else
  658. throw error(sig);
  659. }
  660. private static ClassType parseClassType2(String sig, Cursor c, ClassType parent)
  661. throws BadBytecode
  662. {
  663. int start = ++c.position;
  664. char t;
  665. do {
  666. t = sig.charAt(c.position++);
  667. } while (t != '$' && t != '<' && t != ';');
  668. int end = c.position - 1;
  669. TypeArgument[] targs;
  670. if (t == '<') {
  671. targs = parseTypeArgs(sig, c);
  672. t = sig.charAt(c.position++);
  673. }
  674. else
  675. targs = null;
  676. ClassType thisClass = ClassType.make(sig, start, end, targs, parent);
  677. if (t == '$') {
  678. c.position--;
  679. return parseClassType2(sig, c, thisClass);
  680. }
  681. else
  682. return thisClass;
  683. }
  684. private static TypeArgument[] parseTypeArgs(String sig, Cursor c) throws BadBytecode {
  685. ArrayList args = new ArrayList();
  686. char t;
  687. while ((t = sig.charAt(c.position++)) != '>') {
  688. TypeArgument ta;
  689. if (t == '*' )
  690. ta = new TypeArgument(null, '*');
  691. else {
  692. if (t != '+' && t != '-') {
  693. t = ' ';
  694. c.position--;
  695. }
  696. ta = new TypeArgument(parseObjectType(sig, c, false), t);
  697. }
  698. args.add(ta);
  699. }
  700. return (TypeArgument[])args.toArray(new TypeArgument[args.size()]);
  701. }
  702. private static ObjectType parseArray(String sig, Cursor c) throws BadBytecode {
  703. int dim = 1;
  704. while (sig.charAt(++c.position) == '[')
  705. dim++;
  706. return new ArrayType(dim, parseType(sig, c));
  707. }
  708. private static Type parseType(String sig, Cursor c) throws BadBytecode {
  709. Type t = parseObjectType(sig, c, true);
  710. if (t == null)
  711. t = new BaseType(sig.charAt(c.position++));
  712. return t;
  713. }
  714. private static BadBytecode error(String sig) {
  715. return new BadBytecode("bad signature: " + sig);
  716. }
  717. }