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.

CtArray.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2006 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. /**
  17. * Array types.
  18. */
  19. final class CtArray extends CtClass {
  20. protected ClassPool pool;
  21. // the name of array type ends with "[]".
  22. CtArray(String name, ClassPool cp) {
  23. super(name);
  24. pool = cp;
  25. }
  26. public ClassPool getClassPool() {
  27. return pool;
  28. }
  29. public boolean isArray() {
  30. return true;
  31. }
  32. public boolean subtypeOf(CtClass clazz) throws NotFoundException {
  33. if (super.subtypeOf(clazz))
  34. return true;
  35. String cname = clazz.getName();
  36. if (cname.equals(javaLangObject)
  37. || cname.equals("java.lang.Cloneable"))
  38. return true;
  39. return clazz.isArray()
  40. && getComponentType().subtypeOf(clazz.getComponentType());
  41. }
  42. public CtClass getComponentType() throws NotFoundException {
  43. String name = getName();
  44. return pool.get(name.substring(0, name.length() - 2));
  45. }
  46. public CtClass getSuperclass() throws NotFoundException {
  47. return pool.get(javaLangObject);
  48. }
  49. public CtMethod[] getMethods() {
  50. try {
  51. return getSuperclass().getMethods();
  52. }
  53. catch (NotFoundException e) {
  54. return super.getMethods();
  55. }
  56. }
  57. public CtMethod getMethod(String name, String desc)
  58. throws NotFoundException
  59. {
  60. return getSuperclass().getMethod(name, desc);
  61. }
  62. public CtConstructor[] getConstructors() {
  63. try {
  64. return getSuperclass().getConstructors();
  65. }
  66. catch (NotFoundException e) {
  67. return super.getConstructors();
  68. }
  69. }
  70. }