--- /dev/null
+public class PR83563_1 {
+ public static void main(String[] args) {
+ new NestedTest().run();
+ int c = PertypewithinTest.aspectOf(PR83563_1.class).cnt;
+ if (c!=2)
+ throw new RuntimeException("Expected 2 advice executions: "+c);
+ }
+
+ static class NestedTest implements Runnable {
+ public void run() {
+ System.out.println("Running...");
+ }
+ }
+}
+
+aspect PertypewithinTest pertypewithin(PR83563_1) {
+ public static int cnt = 0;
+
+ before() : execution(* *.*(..)) {
+ cnt++;
+ System.out.println(thisJoinPointStaticPart);
+ }
+}
--- /dev/null
+public class PR83563_2 {
+ public void bar() {
+ new Runnable() {
+ public void run() {
+ System.out.println("Running...");
+ }
+ }.run();
+ }
+
+ public static void main(String[] args) {
+ new PR83563_2().bar();
+ int c = PertypewithinTest.aspectOf(PR83563_2.class).cnt;
+ if (c!=3)
+ throw new RuntimeException("Expected 3 advice executions but got:"+c);
+ }
+}
+
+aspect PertypewithinTest pertypewithin(PR83563_2) {
+ public static int cnt = 0;
+
+ before() : execution(* *.*(..)) {
+ cnt++;
+ System.out.println(thisJoinPoint);
+ }
+}
CompilationResult cR = ajc(baseDir,new String[]{"PR83303.java"});
assertTrue("Should be no errors:"+cR,!cR.hasErrorMessages());
}
+
+ public void testPerTypeWithinMissesNamedInnerTypes() {
+ CompilationResult cR = ajc(baseDir,new String[]{"PR83563_1.java"});
+ assertTrue("Should be no errors:"+cR,!cR.hasErrorMessages());
+ RunResult rR = run("PR83563_1");
+ }
+
+ public void testPerTypeWithinMissesAnonymousInnerTypes() {
+ CompilationResult cR = ajc(baseDir,new String[]{"PR83563_2.java"});
+ assertTrue("Should be no errors:"+cR,!cR.hasErrorMessages());
+ RunResult rR = run("PR83563_2");
+ }
}
\ No newline at end of file
import java.io.DataOutputStream;
import java.io.IOException;
+import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.patterns.PerTypeWithin;
import org.aspectj.weaver.patterns.Pointcut;
-import org.aspectj.weaver.patterns.TypePattern;
// PTWIMPL Target type munger adds the localAspectOf() method
public class PerTypeWithinTargetTypeMunger extends ResolvedTypeMunger {
return testPointcut;
}
+ // This is a lexical within() so if you say PerTypeWithin(Test) and matchType is an
+ // inner type (e.g. Test$NestedType) then it should match successfully
public boolean matches(ResolvedTypeX matchType, ResolvedTypeX aspectType) {
- return testPointcut.getTypePattern().matches(matchType,TypePattern.STATIC).alwaysTrue();
+ return isWithinType(matchType).alwaysTrue();
+ }
+
+ private FuzzyBoolean isWithinType(ResolvedTypeX type) {
+ while (type != null) {
+ if (testPointcut.getTypePattern().matchesStatically(type)) {
+ return FuzzyBoolean.YES;
+ }
+ type = type.getDeclaringType();
+ }
+ return FuzzyBoolean.NO;
}
}
Member.STATIC_INITIALIZATION,
ModifiersPattern.ANY,
TypePattern.ANY,
- typePattern,
+ TypePattern.ANY,//typePattern,
NamePattern.ANY,
TypePatternList.ANY,
ThrowsPattern.ANY,
AnnotationTypePattern.ANY
);
- Pointcut testPc = new KindedPointcut(Shadow.StaticInitialization,sigpat);
- Pointcut testPc2= new WithinPointcut(typePattern);
+
+ Pointcut staticInitStar = new KindedPointcut(Shadow.StaticInitialization,sigpat);
+ Pointcut withinTp= new WithinPointcut(typePattern);
+ Pointcut andPcut = new AndPointcut(staticInitStar,withinTp);
+ // We want the pointcut to be 'staticinitialization(*) && within(<typepattern>' -
+ // we *cannot* shortcut this to staticinitialization(<typepattern>) because it
+ // doesnt mean the same thing.
+
// This munger will initialize the aspect instance field in the matched type
- inAspect.crosscuttingMembers.addConcreteShadowMunger(Advice.makePerTypeWithinEntry(world, testPc, inAspect));
+ inAspect.crosscuttingMembers.addConcreteShadowMunger(Advice.makePerTypeWithinEntry(world, andPcut, inAspect));
ResolvedTypeMunger munger = new PerTypeWithinTargetTypeMunger(inAspect, ret);
inAspect.crosscuttingMembers.addTypeMunger(world.concreteTypeMunger(munger, inAspect));