選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BindingAnnotationTypePattern.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* *******************************************************************
  2. * Copyright (c) 2004 IBM Corporation.
  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. * ******************************************************************/
  10. package org.aspectj.weaver.patterns;
  11. import java.io.DataOutputStream;
  12. import java.io.IOException;
  13. import org.aspectj.bridge.IMessage;
  14. import org.aspectj.bridge.MessageUtil;
  15. import org.aspectj.weaver.BCException;
  16. import org.aspectj.weaver.ISourceContext;
  17. import org.aspectj.weaver.IntMap;
  18. import org.aspectj.weaver.TypeX;
  19. import org.aspectj.weaver.VersionedDataInputStream;
  20. import org.aspectj.weaver.WeaverMessages;
  21. import org.aspectj.weaver.World;
  22. public class BindingAnnotationTypePattern extends ExactAnnotationTypePattern implements BindingPattern {
  23. private int formalIndex;
  24. /**
  25. * @param annotationType
  26. */
  27. public BindingAnnotationTypePattern(TypeX annotationType, int index) {
  28. super(annotationType);
  29. this.formalIndex = index;
  30. }
  31. public BindingAnnotationTypePattern(FormalBinding binding) {
  32. this(binding.getType(),binding.getIndex());
  33. }
  34. public void resolveBinding(World world) {
  35. // For 1.5.0 M1
  36. IMessage lim = MessageUtil.error("Binding not supported in @pcds (1.5.0 M1 limitation): " +
  37. getSourceLocation());
  38. world.getMessageHandler().handleMessage(lim);
  39. // End of 1.5.0 M1
  40. if (resolved) return;
  41. resolved = true;
  42. annotationType = annotationType.resolve(world);
  43. if (!annotationType.isAnnotation(world)) {
  44. IMessage m = MessageUtil.error(
  45. WeaverMessages.format(WeaverMessages.REFERENCE_TO_NON_ANNOTATION_TYPE,annotationType.getName()),
  46. getSourceLocation());
  47. world.getMessageHandler().handleMessage(m);
  48. resolved = false;
  49. }
  50. if (!annotationType.hasAnnotation(TypeX.AT_RETENTION)) {
  51. // default is class visibility
  52. IMessage m = MessageUtil.error(
  53. WeaverMessages.format(WeaverMessages.BINDING_NON_RUNTIME_RETENTION_ANNOTATION,annotationType.getName()),
  54. getSourceLocation());
  55. world.getMessageHandler().handleMessage(m);
  56. resolved = false;
  57. } else {
  58. // TO DO... get the retention policy annotation, and check the value is
  59. // RetentionPolicy.RUNTIME;
  60. }
  61. }
  62. public int getFormalIndex() {
  63. return formalIndex;
  64. }
  65. public boolean equals(Object obj) {
  66. if (!(obj instanceof BindingAnnotationTypePattern)) return false;
  67. BindingAnnotationTypePattern btp = (BindingAnnotationTypePattern) obj;
  68. return (super.equals(btp) && (btp.formalIndex == formalIndex));
  69. }
  70. public int hashCode() {
  71. return super.hashCode()*37 + formalIndex;
  72. }
  73. public AnnotationTypePattern remapAdviceFormals(IntMap bindings) {
  74. if (!bindings.hasKey(formalIndex)) {
  75. return new ExactAnnotationTypePattern(annotationType);
  76. } else {
  77. int newFormalIndex = bindings.get(formalIndex);
  78. return new BindingAnnotationTypePattern(annotationType, newFormalIndex);
  79. }
  80. }
  81. private static final byte VERSION = 1; // rev if serialised form changed
  82. /* (non-Javadoc)
  83. * @see org.aspectj.weaver.patterns.ExactAnnotationTypePattern#write(java.io.DataOutputStream)
  84. */
  85. public void write(DataOutputStream s) throws IOException {
  86. s.writeByte(AnnotationTypePattern.BINDING);
  87. s.writeByte(VERSION);
  88. annotationType.write(s);
  89. s.writeShort((short)formalIndex);
  90. writeLocation(s);
  91. }
  92. public static AnnotationTypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  93. byte version = s.readByte();
  94. if (version > VERSION) {
  95. throw new BCException("BindingAnnotationTypePattern was written by a more recent version of AspectJ");
  96. }
  97. AnnotationTypePattern ret = new BindingAnnotationTypePattern(TypeX.read(s),s.readShort());
  98. ret.readLocation(context,s);
  99. return ret;
  100. }
  101. }