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

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