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.

HasMemberTypePatternForPerThisMatching.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* *******************************************************************
  2. * Copyright (c) 2011 Contributors.
  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://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import java.util.List;
  15. import org.aspectj.weaver.CompressingDataOutputStream;
  16. import org.aspectj.weaver.ConcreteTypeMunger;
  17. import org.aspectj.weaver.ResolvedType;
  18. /**
  19. * pr354470. This is a special subtype of HasMemberTypePattern. In order to optimize this situation:
  20. * <pre><code>
  21. * aspect X perthis(transactional()) {<br>
  22. * pointcut transactional: execution(@Foo * *(..));<br>
  23. * </code></pre>
  24. * <p>
  25. * When this occurs we obviously only want an aspect instance when there is a method annotated with @Foo. For a regular execution
  26. * pointcut we couldn't really do this due to the multiple joinpoint signatures for each joinpoint (and so lots of types get the
  27. * ajcMightHaveAspect interface). However, for an execution pointcut involving an annotation we can do something clever. Annotations
  28. * must match against the first primary joinpoint signature - so when computing the type pattern to use for matching when processing
  29. * the perthis() clause above, we can use the HasMemberTypePattern - because that effectively does what we want. We want an aspect
  30. * instance if the type hasmethod(...) with the appropriate annotation. This would be great... but breaks in the face of ITDs. If
  31. * the method that hasmethod() would match is introduced via an ITD we come unstuck, the code in HasMemberTypePattern.hasMethod()
  32. * does look at ITDs but it won't see annotations, they aren't visible (at least through EclipseResolvedMember objects). And so this
  33. * subclass is created to say 'if the supertype thinks it is a match, great, but if it doesnt then if there are ITDs on the target,
  34. * they might match so just say 'true''. Note that returning true is just confirming whether the 'mightHaveAspect' interface (and
  35. * friends) are getting added.
  36. * </p>
  37. *
  38. * @author Andy Clement
  39. */
  40. public class HasMemberTypePatternForPerThisMatching extends HasMemberTypePattern {
  41. public HasMemberTypePatternForPerThisMatching(SignaturePattern aSignaturePattern) {
  42. super(aSignaturePattern);
  43. }
  44. protected boolean hasMethod(ResolvedType type) {
  45. boolean b = super.hasMethod(type);
  46. if (b) {
  47. return true;
  48. }
  49. // If there are ITDs, have to be safe and just assume one of them might match
  50. List<ConcreteTypeMunger> mungers = type.getInterTypeMungersIncludingSupers();
  51. if (mungers.size() != 0) {
  52. return true;
  53. }
  54. return false;
  55. }
  56. @Override
  57. public void write(CompressingDataOutputStream s) throws IOException {
  58. throw new IllegalAccessError("Should never be called, these are transient and don't get serialized");
  59. }
  60. }