From 2da9b31be2c1e5af9d33b25be798f3a47362fb88 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 27 Oct 2005 15:49:49 +0000 Subject: testcode and fixes for pr99191: thanks to Helen. --- tests/bugs150/pr99191/pr99191_1.java | 10 +++ tests/bugs150/pr99191/pr99191_2.java | 14 ++++ tests/bugs150/pr99191/pr99191_3.java | 10 +++ tests/bugs150/pr99191/pr99191_4.java | 16 ++++ tests/bugs150/pr99191/pr99191_5.java | 10 +++ tests/bugs150/pr99191/pr99191_6.java | 15 ++++ .../org/aspectj/systemtest/ajc150/Ajc150Tests.java | 7 ++ tests/src/org/aspectj/systemtest/ajc150/ajc150.xml | 42 ++++++++++ .../org/aspectj/weaver/bcel/BcelClassWeaver.java | 91 +++++++++++++++++++++- 9 files changed, 211 insertions(+), 4 deletions(-) create mode 100644 tests/bugs150/pr99191/pr99191_1.java create mode 100644 tests/bugs150/pr99191/pr99191_2.java create mode 100644 tests/bugs150/pr99191/pr99191_3.java create mode 100644 tests/bugs150/pr99191/pr99191_4.java create mode 100644 tests/bugs150/pr99191/pr99191_5.java create mode 100644 tests/bugs150/pr99191/pr99191_6.java diff --git a/tests/bugs150/pr99191/pr99191_1.java b/tests/bugs150/pr99191/pr99191_1.java new file mode 100644 index 000000000..f716b2748 --- /dev/null +++ b/tests/bugs150/pr99191/pr99191_1.java @@ -0,0 +1,10 @@ +@interface Annotation{} +aspect B { + + declare @field : int C.noSuchField : @Annotation; // should be an error + declare @field : int B.noSuchField : @Annotation; // should be an error + +} + +class C { +} diff --git a/tests/bugs150/pr99191/pr99191_2.java b/tests/bugs150/pr99191/pr99191_2.java new file mode 100644 index 000000000..aca5b53f2 --- /dev/null +++ b/tests/bugs150/pr99191/pr99191_2.java @@ -0,0 +1,14 @@ +@interface Annotation{} +aspect B { + declare @field : int C.anotherField : @Annotation; // should be woven + declare @field : int someField : @Annotation; // shouldn't have any errors + declare @field : int C.aField : @Annotation; // shouldn't have any errors +} + +class C { + @Annotation int aField = 1; +} + +aspect D { + public int C.anotherField; +} diff --git a/tests/bugs150/pr99191/pr99191_3.java b/tests/bugs150/pr99191/pr99191_3.java new file mode 100644 index 000000000..40bbbcad0 --- /dev/null +++ b/tests/bugs150/pr99191/pr99191_3.java @@ -0,0 +1,10 @@ +@interface Annotation{} +aspect B { + + declare @method : public * C.noSuchMethod(..) : @Annotation; // should be an error + declare @method : * B.noSuchMethod(..) : @Annotation; // should be an error + +} + +class C { +} diff --git a/tests/bugs150/pr99191/pr99191_4.java b/tests/bugs150/pr99191/pr99191_4.java new file mode 100644 index 000000000..600e804ce --- /dev/null +++ b/tests/bugs150/pr99191/pr99191_4.java @@ -0,0 +1,16 @@ +@interface Annotation{} +aspect B { + declare @method : public void C.anotherMethod(..) : @Annotation; // shouldn't have any errors + declare @method : * someMethod(..) : @Annotation; // shouldn't have any errors + declare @method : public void C.amethod(..) : @Annotation; // already get a warning for this, don't want an error saying method doesn't exist +} + +class C { + @Annotation public void amethod() { + } +} + +aspect D { + public void C.anotherMethod() { + } +} diff --git a/tests/bugs150/pr99191/pr99191_5.java b/tests/bugs150/pr99191/pr99191_5.java new file mode 100644 index 000000000..71a697316 --- /dev/null +++ b/tests/bugs150/pr99191/pr99191_5.java @@ -0,0 +1,10 @@ +@interface Annotation{} +aspect B { + + declare @constructor : C.new(String) : @Annotation; // should be an error + declare @constructor : B.new(int) : @Annotation; // should be an error + +} + +class C { +} diff --git a/tests/bugs150/pr99191/pr99191_6.java b/tests/bugs150/pr99191/pr99191_6.java new file mode 100644 index 000000000..4f176bb66 --- /dev/null +++ b/tests/bugs150/pr99191/pr99191_6.java @@ -0,0 +1,15 @@ +@interface Annotation{} +aspect B { + declare @constructor : C.new(String) : @Annotation; // shouldn't have any errors + declare @constructor : *.new(int) : @Annotation; // shouldn't have any errors + declare @constructor : *.new(int) : @Annotation; // already get a warning for this, don't want an error saying method doesn't exist +} + +class C { + @Annotation public C(int i) { + } +} + +aspect D { + public C.new(String s){} +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index fc05dad53..1829956cf 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -64,6 +64,13 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testIncompatibleClassChangeError_pr113630_1() {runTest("IncompatibleClassChangeError - errorscenario");} public void testIncompatibleClassChangeError_pr113630_2() {runTest("IncompatibleClassChangeError - workingscenario");} + + public void testDeclareAnnotationOnNonExistentType_pr99191_1() { runTest("declare annotation on non existent type - 1");} + public void testDeclareAnnotationOnNonExistentType_pr99191_2() { runTest("declare annotation on non existent type - 2");} + public void testDeclareAnnotationOnNonExistentType_pr99191_3() { runTest("declare annotation on non existent type - 3");} + public void testDeclareAnnotationOnNonExistentType_pr99191_4() { runTest("declare annotation on non existent type - 4");} + public void testDeclareAnnotationOnNonExistentType_pr99191_5() { runTest("declare annotation on non existent type - 5");} + public void testBadGenericSigAttribute_pr110927() { runTest("cant create signature attribute"); Signature sig = GenericsTests.getClassSignature(ajc,"I"); diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index b476f9e39..78e4d9318 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -10,6 +10,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index f4cb5ab32..179ec31b6 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -56,6 +56,7 @@ import org.aspectj.apache.bcel.generic.Type; import org.aspectj.apache.bcel.generic.annotation.AnnotationGen; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; +import org.aspectj.bridge.Message; import org.aspectj.bridge.WeaveMessage; import org.aspectj.bridge.context.CompilationAndWeavingContext; import org.aspectj.bridge.context.ContextToken; @@ -82,6 +83,7 @@ import org.aspectj.weaver.WeaverMessages; import org.aspectj.weaver.WeaverMetrics; import org.aspectj.weaver.WeaverStateInfo; import org.aspectj.weaver.patterns.DeclareAnnotation; +import org.aspectj.weaver.patterns.ExactTypePattern; class BcelClassWeaver implements IClassWeaver { @@ -467,6 +469,8 @@ class BcelClassWeaver implements IClassWeaver { List decaMs = getMatchingSubset(allDecams,clazz.getType()); if (decaMs.isEmpty()) return false; // nothing to do if (!members.isEmpty()) { + Set unusedDecams = new HashSet(); + unusedDecams.addAll(decaMs); for (int memberCounter = 0;memberCounter