Browse Source

Fix for Bug 83563: pertypewithin() handling of inner classes

tags/Root_AspectJ5_Development
aclement 19 years ago
parent
commit
1b01255892

+ 23
- 0
tests/bugs150/PR83563_1.java View File

@@ -0,0 +1,23 @@
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);
}
}

+ 25
- 0
tests/bugs150/PR83563_2.java View File

@@ -0,0 +1,25 @@
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);
}
}

+ 12
- 0
tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java View File

@@ -75,4 +75,16 @@ public class Ajc150TestsNoHarness extends TestUtils {
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");
}
}

+ 14
- 2
weaver/src/org/aspectj/weaver/PerTypeWithinTargetTypeMunger.java View File

@@ -15,9 +15,9 @@ package org.aspectj.weaver;
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 {
@@ -45,8 +45,20 @@ 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;
}

}

+ 10
- 4
weaver/src/org/aspectj/weaver/patterns/PerTypeWithin.java View File

@@ -126,16 +126,22 @@ public class PerTypeWithin extends PerClause {
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));

Loading…
Cancel
Save