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.

AnyWithAnnotationTypePattern.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* *******************************************************************
  2. * Copyright (c) 2002, 2010 Palo Alto Research Center, Incorporated (PARC) and others.
  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. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.lang.reflect.Modifier;
  15. import java.util.Map;
  16. import org.aspectj.bridge.MessageUtil;
  17. import org.aspectj.util.FuzzyBoolean;
  18. import org.aspectj.weaver.CompressingDataOutputStream;
  19. import org.aspectj.weaver.ISourceContext;
  20. import org.aspectj.weaver.ResolvedType;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.WeaverMessages;
  23. import org.aspectj.weaver.World;
  24. /**
  25. * This type represents a type pattern of '*' but with an annotation specified, e.g. '@Color *'
  26. */
  27. public class AnyWithAnnotationTypePattern extends TypePattern {
  28. public AnyWithAnnotationTypePattern(AnnotationTypePattern atp) {
  29. super(false, false);
  30. annotationPattern = atp;
  31. }
  32. @Override
  33. public Object accept(PatternNodeVisitor visitor, Object data) {
  34. return visitor.visit(this, data);
  35. }
  36. @Override
  37. protected boolean couldEverMatchSameTypesAs(TypePattern other) {
  38. return true;
  39. }
  40. @Override
  41. protected boolean matchesExactly(ResolvedType type) {
  42. annotationPattern.resolve(type.getWorld());
  43. boolean b = false;
  44. if (type.temporaryAnnotationTypes != null) {
  45. b = annotationPattern.matches(type, type.temporaryAnnotationTypes).alwaysTrue();
  46. } else {
  47. b = annotationPattern.matches(type).alwaysTrue();
  48. }
  49. return b;
  50. }
  51. @Override
  52. public TypePattern resolveBindings(IScope scope, Bindings bindings, boolean allowBinding, boolean requireExactType) {
  53. if (requireExactType) {
  54. scope.getWorld().getMessageHandler().handleMessage(
  55. MessageUtil.error(WeaverMessages.format(WeaverMessages.WILDCARD_NOT_ALLOWED), getSourceLocation()));
  56. return NO;
  57. }
  58. return super.resolveBindings(scope, bindings, allowBinding, requireExactType);
  59. }
  60. @Override
  61. protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType) {
  62. annotationPattern.resolve(type.getWorld());
  63. return annotationPattern.matches(annotatedType).alwaysTrue();
  64. }
  65. @Override
  66. public FuzzyBoolean matchesInstanceof(ResolvedType type) {
  67. if (Modifier.isFinal(type.getModifiers())) {
  68. return FuzzyBoolean.fromBoolean(matchesExactly(type));
  69. }
  70. return FuzzyBoolean.MAYBE;
  71. }
  72. @Override
  73. public TypePattern parameterizeWith(Map typeVariableMap, World w) {
  74. AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(this.annotationPattern.parameterizeWith(
  75. typeVariableMap, w));
  76. ret.copyLocationFrom(this);
  77. return ret;
  78. }
  79. @Override
  80. public void write(CompressingDataOutputStream s) throws IOException {
  81. s.writeByte(TypePattern.ANY_WITH_ANNO);
  82. annotationPattern.write(s);
  83. writeLocation(s);
  84. }
  85. public static TypePattern read(VersionedDataInputStream s, ISourceContext c) throws IOException {
  86. AnnotationTypePattern annPatt = AnnotationTypePattern.read(s, c);
  87. AnyWithAnnotationTypePattern ret = new AnyWithAnnotationTypePattern(annPatt);
  88. ret.readLocation(c, s);
  89. return ret;
  90. }
  91. // public FuzzyBoolean matches(IType type, MatchKind kind) {
  92. // return FuzzyBoolean.YES;
  93. // }
  94. @Override
  95. protected boolean matchesSubtypes(ResolvedType type) {
  96. return true;
  97. }
  98. @Override
  99. public boolean isStar() {
  100. return false;
  101. }
  102. @Override
  103. public String toString() {
  104. return "(" + annotationPattern + " *)";
  105. }
  106. public AnnotationTypePattern getAnnotationTypePattern() {
  107. return annotationPattern;
  108. }
  109. @Override
  110. public boolean equals(Object obj) {
  111. if (!(obj instanceof AnyWithAnnotationTypePattern)) {
  112. return false;
  113. }
  114. AnyWithAnnotationTypePattern awatp = (AnyWithAnnotationTypePattern) obj;
  115. return (annotationPattern.equals(awatp.annotationPattern));
  116. }
  117. @Override
  118. public int hashCode() {
  119. return annotationPattern.hashCode();
  120. }
  121. }