diff options
author | acolyer <acolyer> | 2005-09-02 14:38:11 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-09-02 14:38:11 +0000 |
commit | b17ff4ed2d55ec24f1f1a6f3fe70ffd91ac18e62 (patch) | |
tree | 1a81ea166acb33fd033592a43e0ed503509116eb | |
parent | e29ca524955b2112bbf63e740ca71516c13fbb4c (diff) | |
download | aspectj-b17ff4ed2d55ec24f1f1a6f3fe70ffd91ac18e62.tar.gz aspectj-b17ff4ed2d55ec24f1f1a6f3fe70ffd91ac18e62.zip |
second part of test and fix for pr102212 - synchronized itdm on interfaces generate synchronized members for implementing classes, but not for the interface itself.
5 files changed, 50 insertions, 0 deletions
diff --git a/tests/bugs150/SynchronizedInterfaceMethods.aj b/tests/bugs150/SynchronizedInterfaceMethods.aj new file mode 100644 index 000000000..9611f3434 --- /dev/null +++ b/tests/bugs150/SynchronizedInterfaceMethods.aj @@ -0,0 +1,25 @@ +import java.lang.reflect.*; + +public class SynchronizedInterfaceMethods { + + public static void main(String[] args) throws NoSuchMethodException { + Class myClass = SynchronizedInterfaceMethods.class; + Method m = myClass.getMethod("foo"); + if (!Modifier.isSynchronized(m.getModifiers())) throw new RuntimeException("Expecting method on class to be synchronized"); + Class iClass = I.class; + Method im = iClass.getMethod("foo"); + if (Modifier.isSynchronized(im.getModifiers())) throw new RuntimeException("Interface method must NOT be synchronized"); + } + + +} + +interface I {} + + +aspect A { + + public synchronized void I.foo() {} + + declare parents : SynchronizedInterfaceMethods implements I; +}
\ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index d9baeec72..2cf9dc7a9 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -374,6 +374,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("abstract synchronized itdms not detected"); } + public void testSynchronizedITDInterfaceMethods() { + runTest("synchronized itd interface methods"); + } + // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index fc7622c38..7814d3cd8 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -462,6 +462,12 @@ <message line="7" kind="error" text="The abstract method _abstract in type Parent can only set a visibility modifier, one of public or protected"/> </compile> </ajc-test> + + <ajc-test dir="bugs150" pr="102212" title="synchronized itd interface methods"> + <compile files="SynchronizedInterfaceMethods.aj" options="-1.5"> + </compile> + <run class="SynchronizedInterfaceMethods"/> + </ajc-test> <!-- ============================================================================ --> <!-- ============================================================================ --> diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index 114b6560c..e677685ed 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -716,6 +716,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger { ResolvedMember interMethodDispatcher = munger.getInterMethodDispatcher(aspectType); LazyClassGen gen = weaver.getLazyClassGen(); + boolean mungingInterface = gen.isInterface(); ResolvedType onType = weaver.getWorld().resolve(unMangledInterMethod.getDeclaringType(),munger.getSourceLocation()); if (onType.isRawType()) onType = onType.getGenericType(); @@ -738,6 +739,11 @@ public class BcelTypeMunger extends ConcreteTypeMunger { LazyMethodGen mg = makeMethodGen(gen, mangledInterMethod); + if (mungingInterface) { + // we want the modifiers of the ITD to be used for all *implementors* of the + // interface, but the method itself we add to the interface must be public abstract + mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT); + } // pr98901 // For copying the annotations across, we have to discover the real member in the aspect @@ -829,6 +835,11 @@ public class BcelTypeMunger extends ConcreteTypeMunger { AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, false); LazyMethodGen mg = makeMethodGen(gen, mangledInterMethod); + if (mungingInterface) { + // we want the modifiers of the ITD to be used for all *implementors* of the + // interface, but the method itself we add to the interface must be public abstract + mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT); + } Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes()); Type returnType = BcelWorld.makeBcelType(mangledInterMethod.getReturnType()); diff --git a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java index cb31e7a36..f74306851 100644 --- a/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java +++ b/weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java @@ -782,6 +782,10 @@ public final class LazyMethodGen { public int getAccessFlags() { return accessFlags; } + + public void setAccessFlags(int newFlags) { + this.accessFlags = newFlags; + } public Type[] getArgumentTypes() { initialize(); |