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.

AndAnnotationTypePattern.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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. /**
  23. * @author colyer
  24. *
  25. * TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code
  26. * Templates
  27. */
  28. public class AndAnnotationTypePattern extends AnnotationTypePattern {
  29. private AnnotationTypePattern left;
  30. private AnnotationTypePattern right;
  31. public AndAnnotationTypePattern(AnnotationTypePattern left, AnnotationTypePattern right) {
  32. this.left = left;
  33. this.right = right;
  34. setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
  35. }
  36. public FuzzyBoolean matches(AnnotatedElement annotated) {
  37. return left.matches(annotated).and(right.matches(annotated));
  38. }
  39. public FuzzyBoolean matches(AnnotatedElement annotated, ResolvedType[] parameterAnnotations) {
  40. return left.matches(annotated, parameterAnnotations).and(right.matches(annotated, parameterAnnotations));
  41. }
  42. public void resolve(World world) {
  43. left.resolve(world);
  44. right.resolve(world);
  45. }
  46. /*
  47. * (non-Javadoc)
  48. *
  49. * @see org.aspectj.weaver.patterns.AnnotationTypePattern#resolveBindings(org.aspectj.weaver.patterns.IScope,
  50. * org.aspectj.weaver.patterns.Bindings, boolean)
  51. */
  52. public AnnotationTypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding) {
  53. left = left.resolveBindings(scope, bindings, allowBinding);
  54. right = right.resolveBindings(scope, bindings, allowBinding);
  55. return this;
  56. }
  57. public AnnotationTypePattern parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  58. AnnotationTypePattern newLeft = left.parameterizeWith(typeVariableMap, w);
  59. AnnotationTypePattern newRight = right.parameterizeWith(typeVariableMap, w);
  60. AndAnnotationTypePattern ret = new AndAnnotationTypePattern(newLeft, newRight);
  61. ret.copyLocationFrom(this);
  62. if (this.isForParameterAnnotationMatch()) {
  63. ret.setForParameterAnnotationMatch();
  64. }
  65. return ret;
  66. }
  67. public static AnnotationTypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
  68. AnnotationTypePattern p = new AndAnnotationTypePattern(AnnotationTypePattern.read(s, context), AnnotationTypePattern.read(
  69. s, context));
  70. p.readLocation(context, s);
  71. if (s.getMajorVersion() >= WeaverVersionInfo.WEAVER_VERSION_MAJOR_AJ160) {
  72. if (s.readBoolean()) {
  73. p.setForParameterAnnotationMatch();
  74. }
  75. }
  76. return p;
  77. }
  78. public void write(CompressingDataOutputStream s) throws IOException {
  79. s.writeByte(AnnotationTypePattern.AND);
  80. left.write(s);
  81. right.write(s);
  82. writeLocation(s);
  83. s.writeBoolean(isForParameterAnnotationMatch());
  84. }
  85. public boolean equals(Object obj) {
  86. if (!(obj instanceof AndAnnotationTypePattern)) {
  87. return false;
  88. }
  89. AndAnnotationTypePattern other = (AndAnnotationTypePattern) obj;
  90. return (left.equals(other.left) && right.equals(other.right) && left.isForParameterAnnotationMatch() == right
  91. .isForParameterAnnotationMatch());
  92. }
  93. public int hashCode() {
  94. int result = 17;
  95. result = result * 37 + left.hashCode();
  96. result = result * 37 + right.hashCode();
  97. result = result * 37 + (isForParameterAnnotationMatch() ? 0 : 1);
  98. return result;
  99. }
  100. public String toString() {
  101. return left.toString() + " " + right.toString();
  102. }
  103. public AnnotationTypePattern getLeft() {
  104. return left;
  105. }
  106. public AnnotationTypePattern getRight() {
  107. return right;
  108. }
  109. public Object accept(PatternNodeVisitor visitor, Object data) {
  110. return visitor.visit(this, data);
  111. }
  112. public Object traverse(PatternNodeVisitor visitor, Object data) {
  113. Object ret = accept(visitor, data);
  114. left.traverse(visitor, ret);
  115. right.traverse(visitor, ret);
  116. return ret;
  117. }
  118. public void setForParameterAnnotationMatch() {
  119. left.setForParameterAnnotationMatch();
  120. right.setForParameterAnnotationMatch();
  121. }
  122. }