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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.util.Iterator;
  14. import java.util.List;
  15. import org.aspectj.apache.bcel.classfile.Attribute;
  16. import org.aspectj.apache.bcel.classfile.Field;
  17. import org.aspectj.apache.bcel.classfile.Synthetic;
  18. import org.aspectj.apache.bcel.classfile.annotation.Annotation;
  19. import org.aspectj.weaver.AjAttribute;
  20. import org.aspectj.weaver.BCException;
  21. import org.aspectj.weaver.ResolvedMember;
  22. import org.aspectj.weaver.ResolvedTypeX;
  23. import org.aspectj.weaver.TypeX;
  24. import org.aspectj.weaver.World;
  25. final class BcelField extends ResolvedMember {
  26. private Field field;
  27. private boolean isAjSynthetic;
  28. private boolean isSynthetic = false;
  29. private ResolvedTypeX[] resolvedAnnotations;
  30. private World world;
  31. BcelField(BcelObjectType declaringType, Field field) {
  32. super(
  33. FIELD,
  34. declaringType.getResolvedTypeX(),
  35. field.getAccessFlags(),
  36. field.getName(),
  37. field.getSignature());
  38. this.field = field;
  39. this.world = declaringType.getResolvedTypeX().getWorld();
  40. unpackAttributes(world);
  41. checkedExceptions = TypeX.NONE;
  42. }
  43. // ----
  44. private void unpackAttributes(World world) {
  45. Attribute[] attrs = field.getAttributes();
  46. List as = BcelAttributes.readAjAttributes(getDeclaringType().getClassName(),attrs, getSourceContext(world),world.getMessageHandler());
  47. for (Iterator iter = as.iterator(); iter.hasNext();) {
  48. AjAttribute a = (AjAttribute) iter.next();
  49. if (a instanceof AjAttribute.AjSynthetic) {
  50. isAjSynthetic = true;
  51. } else {
  52. throw new BCException("weird field attribute " + a);
  53. }
  54. }
  55. isAjSynthetic = false;
  56. for (int i = attrs.length - 1; i >= 0; i--) {
  57. if (attrs[i] instanceof Synthetic) isSynthetic = true;
  58. }
  59. }
  60. public boolean isAjSynthetic() {
  61. return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX);
  62. }
  63. public boolean isSynthetic() {
  64. return isSynthetic;
  65. }
  66. public boolean hasAnnotation(TypeX ofType) {
  67. Annotation[] anns = field.getAnnotations();
  68. for (int i = 0; i < anns.length; i++) {
  69. Annotation annotation = anns[i];
  70. if (annotation.getTypeName().equals(ofType.getName())) return true;
  71. }
  72. return false;
  73. }
  74. public ResolvedTypeX[] getAnnotationTypes() {
  75. if (resolvedAnnotations == null) {
  76. Annotation[] annotations = field.getAnnotations();
  77. resolvedAnnotations = new ResolvedTypeX[annotations.length];
  78. for (int i = 0; i < annotations.length; i++) {
  79. Annotation annotation = annotations[i];
  80. ResolvedTypeX rtx = world.resolve(TypeX.forName(annotation.getTypeName()));
  81. resolvedAnnotations[i] = rtx;
  82. }
  83. }
  84. return resolvedAnnotations;
  85. }
  86. }