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