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.

AnnotationTypePattern.java 4.6KB

пре 15 година
пре 15 година
пре 9 година
пре 15 година
пре 14 година
пре 15 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 9 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 13 година
пре 15 година
пре 14 година
пре 13 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
пре 14 година
пре 15 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * ******************************************************************/
  10. package org.aspectj.weaver.patterns;
  11. import java.io.IOException;
  12. import java.util.Map;
  13. import org.aspectj.util.FuzzyBoolean;
  14. import org.aspectj.weaver.AnnotatedElement;
  15. import org.aspectj.weaver.BCException;
  16. import org.aspectj.weaver.CompressingDataOutputStream;
  17. import org.aspectj.weaver.ISourceContext;
  18. import org.aspectj.weaver.IntMap;
  19. import org.aspectj.weaver.ResolvedType;
  20. import org.aspectj.weaver.UnresolvedType;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.World;
  23. public abstract class AnnotationTypePattern extends PatternNode {
  24. public static final AnnotationTypePattern ANY = new AnyAnnotationTypePattern();
  25. public static final AnnotationTypePattern ELLIPSIS = new EllipsisAnnotationTypePattern();
  26. public static final AnnotationTypePattern[] NONE = new AnnotationTypePattern[0];
  27. private boolean isForParameterAnnotationMatch;
  28. /**
  29. * TODO: write, read, equals & hashCode both in annotation hierarchy and in altered TypePattern hierarchy
  30. */
  31. protected AnnotationTypePattern() {
  32. super();
  33. }
  34. public abstract FuzzyBoolean matches(AnnotatedElement annotated);
  35. public abstract FuzzyBoolean matches(AnnotatedElement annotated, ResolvedType[] parameterAnnotations);
  36. public FuzzyBoolean fastMatches(AnnotatedElement annotated) {
  37. return FuzzyBoolean.MAYBE;
  38. }
  39. public AnnotationTypePattern remapAdviceFormals(IntMap bindings) {
  40. return this;
  41. }
  42. public abstract void resolve(World world);
  43. public abstract AnnotationTypePattern parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w);
  44. public boolean isAny() {
  45. return false;
  46. }
  47. /**
  48. * This can modify in place, or return a new TypePattern if the type changes.
  49. */
  50. public AnnotationTypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding) {
  51. return this;
  52. }
  53. public static final byte EXACT = 1;
  54. public static final byte BINDING = 2;
  55. public static final byte NOT = 3;
  56. public static final byte OR = 4;
  57. public static final byte AND = 5;
  58. public static final byte ELLIPSIS_KEY = 6;
  59. public static final byte ANY_KEY = 7;
  60. public static final byte WILD = 8;
  61. public static final byte EXACTFIELD = 9;
  62. public static final byte BINDINGFIELD = 10;
  63. public static final byte BINDINGFIELD2 = 11;
  64. public static AnnotationTypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  65. byte key = s.readByte();
  66. switch (key) {
  67. case EXACT:
  68. return ExactAnnotationTypePattern.read(s, context);
  69. case BINDING:
  70. return BindingAnnotationTypePattern.read(s, context);
  71. case NOT:
  72. return NotAnnotationTypePattern.read(s, context);
  73. case OR:
  74. return OrAnnotationTypePattern.read(s, context);
  75. case AND:
  76. return AndAnnotationTypePattern.read(s, context);
  77. case WILD:
  78. return WildAnnotationTypePattern.read(s, context);
  79. case EXACTFIELD:
  80. return ExactAnnotationFieldTypePattern.read(s, context);
  81. case BINDINGFIELD:
  82. return BindingAnnotationFieldTypePattern.read(s, context);
  83. case BINDINGFIELD2:
  84. return BindingAnnotationFieldTypePattern.read2(s, context);
  85. case ELLIPSIS_KEY:
  86. return ELLIPSIS;
  87. case ANY_KEY:
  88. return ANY;
  89. }
  90. throw new BCException("unknown TypePattern kind: " + key);
  91. }
  92. public void setForParameterAnnotationMatch() {
  93. isForParameterAnnotationMatch = true;
  94. }
  95. public boolean isForParameterAnnotationMatch() {
  96. return isForParameterAnnotationMatch;
  97. }
  98. }
  99. class EllipsisAnnotationTypePattern extends AnnotationTypePattern {
  100. @Override
  101. public FuzzyBoolean matches(AnnotatedElement annotated) {
  102. return FuzzyBoolean.NO;
  103. }
  104. @Override
  105. public FuzzyBoolean matches(AnnotatedElement annotated, ResolvedType[] parameterAnnotations) {
  106. return FuzzyBoolean.NO;
  107. }
  108. @Override
  109. public void write(CompressingDataOutputStream s) throws IOException {
  110. s.writeByte(AnnotationTypePattern.ELLIPSIS_KEY);
  111. }
  112. @Override
  113. public void resolve(World world) {
  114. }
  115. @Override
  116. public String toString() {
  117. return "..";
  118. }
  119. @Override
  120. public Object accept(PatternNodeVisitor visitor, Object data) {
  121. return visitor.visit(this, data);
  122. }
  123. @Override
  124. public AnnotationTypePattern parameterizeWith(Map arg0, World w) {
  125. return this;
  126. }
  127. @Override
  128. public void setForParameterAnnotationMatch() {
  129. }
  130. }