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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.DataOutputStream;
  12. import java.io.IOException;
  13. import java.util.Map;
  14. import org.aspectj.util.FuzzyBoolean;
  15. import org.aspectj.weaver.AnnotatedElement;
  16. import org.aspectj.weaver.BCException;
  17. import org.aspectj.weaver.ISourceContext;
  18. import org.aspectj.weaver.IntMap;
  19. import org.aspectj.weaver.ResolvedType;
  20. import org.aspectj.weaver.VersionedDataInputStream;
  21. import org.aspectj.weaver.World;
  22. public abstract class AnnotationTypePattern extends PatternNode {
  23. public static final AnnotationTypePattern ANY = new AnyAnnotationTypePattern();
  24. public static final AnnotationTypePattern ELLIPSIS = new EllipsisAnnotationTypePattern();
  25. public static final AnnotationTypePattern[] NONE = new AnnotationTypePattern[0];
  26. private boolean isForParameterAnnotationMatch;
  27. /**
  28. * TODO: write, read, equals & hashcode both in annotation hierarachy and
  29. * 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/*name -> ResolvedType*/ typeVariableMap,World w);
  44. public boolean isAny() { return false; }
  45. /**
  46. * This can modify in place, or return a new TypePattern if the type changes.
  47. */
  48. public AnnotationTypePattern resolveBindings(IScope scope, Bindings bindings,
  49. boolean allowBinding)
  50. {
  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 AnnotationTypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  62. byte key = s.readByte();
  63. switch(key) {
  64. case EXACT: return ExactAnnotationTypePattern.read(s, context);
  65. case BINDING: return BindingAnnotationTypePattern.read(s, context);
  66. case NOT: return NotAnnotationTypePattern.read(s, context);
  67. case OR: return OrAnnotationTypePattern.read(s, context);
  68. case AND: return AndAnnotationTypePattern.read(s, context);
  69. case WILD: return WildAnnotationTypePattern.read(s,context);
  70. case ELLIPSIS_KEY: return ELLIPSIS;
  71. case ANY_KEY: return ANY;
  72. }
  73. throw new BCException("unknown TypePattern kind: " + key);
  74. }
  75. public void setForParameterAnnotationMatch() { isForParameterAnnotationMatch = true; }
  76. public boolean isForParameterAnnotationMatch() { return isForParameterAnnotationMatch; }
  77. }
  78. class EllipsisAnnotationTypePattern extends AnnotationTypePattern {
  79. public FuzzyBoolean matches(AnnotatedElement annotated) {
  80. return FuzzyBoolean.NO;
  81. }
  82. public FuzzyBoolean matches(AnnotatedElement annotated,ResolvedType[] parameterAnnotations) {
  83. return FuzzyBoolean.NO;
  84. }
  85. public void write(DataOutputStream s) throws IOException {
  86. s.writeByte(AnnotationTypePattern.ELLIPSIS_KEY);
  87. }
  88. public void resolve(World world) {
  89. }
  90. public String toString() { return ".."; }
  91. public Object accept(PatternNodeVisitor visitor, Object data) {
  92. return visitor.visit(this, data);
  93. }
  94. public AnnotationTypePattern parameterizeWith(Map arg0,World w) {
  95. return this;
  96. }
  97. }