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.

AnnotationMemberValue.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 2004 Bill Burke. 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.annotation;
  17. import javassist.ClassPool;
  18. import javassist.bytecode.ConstPool;
  19. import java.io.IOException;
  20. import java.lang.reflect.Method;
  21. /**
  22. * Nested annotation.
  23. *
  24. * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
  25. * @author Shigeru Chiba
  26. */
  27. public class AnnotationMemberValue extends MemberValue {
  28. Annotation value;
  29. /**
  30. * Constructs an annotation member. The initial value is not specified.
  31. */
  32. public AnnotationMemberValue(ConstPool cp) {
  33. this(null, cp);
  34. }
  35. /**
  36. * Constructs an annotation member. The initial value is specified by
  37. * the first parameter.
  38. */
  39. public AnnotationMemberValue(Annotation a, ConstPool cp) {
  40. super('@', cp);
  41. value = a;
  42. }
  43. Object getValue(ClassLoader cl, ClassPool cp, Method m)
  44. throws ClassNotFoundException
  45. {
  46. return AnnotationImpl.make(cl, getType(cl), cp, value);
  47. }
  48. Class getType(ClassLoader cl) throws ClassNotFoundException {
  49. if (value == null)
  50. throw new ClassNotFoundException("no type specified");
  51. else
  52. return loadClass(cl, value.getTypeName());
  53. }
  54. /**
  55. * Obtains the value.
  56. */
  57. public Annotation getValue() {
  58. return value;
  59. }
  60. /**
  61. * Sets the value of this member.
  62. */
  63. public void setValue(Annotation newValue) {
  64. value = newValue;
  65. }
  66. /**
  67. * Obtains the string representation of this object.
  68. */
  69. public String toString() {
  70. return value.toString();
  71. }
  72. /**
  73. * Writes the value.
  74. */
  75. public void write(AnnotationsWriter writer) throws IOException {
  76. writer.annotationValue();
  77. value.write(writer);
  78. }
  79. /**
  80. * Accepts a visitor.
  81. */
  82. public void accept(MemberValueVisitor visitor) {
  83. visitor.visitAnnotationMemberValue(this);
  84. }
  85. }