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.

NotAnnotationTypePattern.java 4.1KB

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