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.

OrAnnotationTypePattern.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.CompressingDataOutputStream;
  16. import org.aspectj.weaver.ISourceContext;
  17. import org.aspectj.weaver.ResolvedType;
  18. import org.aspectj.weaver.UnresolvedType;
  19. import org.aspectj.weaver.VersionedDataInputStream;
  20. import org.aspectj.weaver.World;
  21. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  22. public class OrAnnotationTypePattern extends AnnotationTypePattern {
  23. private AnnotationTypePattern left;
  24. private AnnotationTypePattern right;
  25. public OrAnnotationTypePattern(AnnotationTypePattern left, AnnotationTypePattern right) {
  26. this.left = left;
  27. this.right = right;
  28. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  29. }
  30. public FuzzyBoolean matches(AnnotatedElement annotated) {
  31. return left.matches(annotated).or(right.matches(annotated));
  32. }
  33. public FuzzyBoolean matches(AnnotatedElement annotated, ResolvedType[] parameterAnnotations) {
  34. return left.matches(annotated, parameterAnnotations).or(right.matches(annotated, parameterAnnotations));
  35. }
  36. public void resolve(World world) {
  37. left.resolve(world);
  38. right.resolve(world);
  39. }
  40. public AnnotationTypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding) {
  41. left = left.resolveBindings(scope, bindings, allowBinding);
  42. right = right.resolveBindings(scope, bindings, allowBinding);
  43. return this;
  44. }
  45. public AnnotationTypePattern parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  46. AnnotationTypePattern newLeft = left.parameterizeWith(typeVariableMap, w);
  47. AnnotationTypePattern newRight = right.parameterizeWith(typeVariableMap, w);
  48. OrAnnotationTypePattern ret = new OrAnnotationTypePattern(newLeft, newRight);
  49. ret.copyLocationFrom(this);
  50. if (isForParameterAnnotationMatch()) {
  51. ret.setForParameterAnnotationMatch();
  52. }
  53. return ret;
  54. }
  55. public Object accept(PatternNodeVisitor visitor, Object data) {
  56. return visitor.visit(this, data);
  57. }
  58. public Object traverse(PatternNodeVisitor visitor, Object data) {
  59. Object ret = accept(visitor, data);
  60. left.traverse(visitor, ret);
  61. right.traverse(visitor, ret);
  62. return ret;
  63. }
  64. public static AnnotationTypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  65. AnnotationTypePattern p = new OrAnnotationTypePattern(AnnotationTypePattern.read(s, context), AnnotationTypePattern.read(s,
  66. context));
  67. p.readLocation(context, s);
  68. if (s.getMajorVersion() >= WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ160) {
  69. if (s.readBoolean()) {
  70. p.setForParameterAnnotationMatch();
  71. }
  72. }
  73. return p;
  74. }
  75. public void write(CompressingDataOutputStream s) throws IOException {
  76. s.writeByte(AnnotationTypePattern.OR);
  77. left.write(s);
  78. right.write(s);
  79. writeLocation(s);
  80. s.writeBoolean(isForParameterAnnotationMatch());
  81. }
  82. public boolean equals(Object obj) {
  83. if (!(obj instanceof OrAnnotationTypePattern)) {
  84. return false;
  85. }
  86. OrAnnotationTypePattern other = (OrAnnotationTypePattern) obj;
  87. return (left.equals(other.left) && right.equals(other.right))
  88. && isForParameterAnnotationMatch() == other.isForParameterAnnotationMatch();
  89. }
  90. public int hashCode() {
  91. int result = 17;
  92. result = result * 37 + left.hashCode();
  93. result = result * 37 + right.hashCode();
  94. result = result * 37 + (isForParameterAnnotationMatch() ? 0 : 1);
  95. return result;
  96. }
  97. public String toString() {
  98. return "(" + left.toString() + " || " + right.toString() + ")";
  99. }
  100. public AnnotationTypePattern getLeft() {
  101. return left;
  102. }
  103. public AnnotationTypePattern getRight() {
  104. return right;
  105. }
  106. public void setForParameterAnnotationMatch() {
  107. left.setForParameterAnnotationMatch();
  108. right.setForParameterAnnotationMatch();
  109. }
  110. }