From 96ebaaed65fe5d507cae3d56126d76f217a9f13a Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Mon, 21 Jan 2013 10:46:15 -0800 Subject: [PATCH] 398588 fix --- tests/bugs172/pr398588/Anno.java | 7 +++ tests/bugs172/pr398588/Anno2.java | 7 +++ tests/bugs172/pr398588/AspectA.java | 5 ++ tests/bugs172/pr398588/AspectB.java | 3 ++ tests/bugs172/pr398588/AspectC.java | 5 ++ tests/bugs172/pr398588/AspectD.java | 5 ++ tests/bugs172/pr398588/Blah.java | 6 +++ tests/bugs172/pr398588/Code.java | 10 ++++ tests/bugs172/pr398588/Code2.java | 11 ++++ tests/bugs172/pr398588/META-INF/aop.xml | 9 ++++ .../systemtest/ajc172/Ajc172Tests.java | 27 ++++++---- .../org/aspectj/systemtest/ajc172/ajc172.xml | 34 ++++++++++++- .../org/aspectj/weaver/bcel/BcelWorld.java | 51 ++++++++++--------- 13 files changed, 145 insertions(+), 35 deletions(-) create mode 100644 tests/bugs172/pr398588/Anno.java create mode 100644 tests/bugs172/pr398588/Anno2.java create mode 100644 tests/bugs172/pr398588/AspectA.java create mode 100644 tests/bugs172/pr398588/AspectB.java create mode 100644 tests/bugs172/pr398588/AspectC.java create mode 100644 tests/bugs172/pr398588/AspectD.java create mode 100644 tests/bugs172/pr398588/Blah.java create mode 100644 tests/bugs172/pr398588/Code.java create mode 100644 tests/bugs172/pr398588/Code2.java create mode 100644 tests/bugs172/pr398588/META-INF/aop.xml diff --git a/tests/bugs172/pr398588/Anno.java b/tests/bugs172/pr398588/Anno.java new file mode 100644 index 000000000..f298cf761 --- /dev/null +++ b/tests/bugs172/pr398588/Anno.java @@ -0,0 +1,7 @@ +package a.b.c; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Anno { +} diff --git a/tests/bugs172/pr398588/Anno2.java b/tests/bugs172/pr398588/Anno2.java new file mode 100644 index 000000000..16abf0957 --- /dev/null +++ b/tests/bugs172/pr398588/Anno2.java @@ -0,0 +1,7 @@ +package a.b.c; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Anno2 { +} diff --git a/tests/bugs172/pr398588/AspectA.java b/tests/bugs172/pr398588/AspectA.java new file mode 100644 index 000000000..95919fa8f --- /dev/null +++ b/tests/bugs172/pr398588/AspectA.java @@ -0,0 +1,5 @@ +import a.b.c.Anno; + +public aspect AspectA { + before(): execution(@Anno * *(..)) {System.out.println("A");} +} diff --git a/tests/bugs172/pr398588/AspectB.java b/tests/bugs172/pr398588/AspectB.java new file mode 100644 index 000000000..6f6ac8e62 --- /dev/null +++ b/tests/bugs172/pr398588/AspectB.java @@ -0,0 +1,3 @@ +public aspect AspectB { + before():staticinitialization(!Aspect*) { System.out.println("staticinitialization");} +} diff --git a/tests/bugs172/pr398588/AspectC.java b/tests/bugs172/pr398588/AspectC.java new file mode 100644 index 000000000..143cd974e --- /dev/null +++ b/tests/bugs172/pr398588/AspectC.java @@ -0,0 +1,5 @@ +import a.b.c.Blah; + +public aspect AspectC { + before(): execution(@Blah * *(..)) {System.out.println("C");} +} diff --git a/tests/bugs172/pr398588/AspectD.java b/tests/bugs172/pr398588/AspectD.java new file mode 100644 index 000000000..5c14845ee --- /dev/null +++ b/tests/bugs172/pr398588/AspectD.java @@ -0,0 +1,5 @@ +import a.b.c.Anno2; + +public aspect AspectD { + before(): execution(@Anno2 * *(..)) {System.out.println("D");} +} diff --git a/tests/bugs172/pr398588/Blah.java b/tests/bugs172/pr398588/Blah.java new file mode 100644 index 000000000..6288a2734 --- /dev/null +++ b/tests/bugs172/pr398588/Blah.java @@ -0,0 +1,6 @@ +package a.b.c; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Blah {} diff --git a/tests/bugs172/pr398588/Code.java b/tests/bugs172/pr398588/Code.java new file mode 100644 index 000000000..a11192728 --- /dev/null +++ b/tests/bugs172/pr398588/Code.java @@ -0,0 +1,10 @@ +import java.lang.annotation.*; +import a.b.c.Blah; + +@Blah +public class Code { + @Blah + public static void main(String[] argv) { + System.out.println("abcde"); + } +} diff --git a/tests/bugs172/pr398588/Code2.java b/tests/bugs172/pr398588/Code2.java new file mode 100644 index 000000000..bb48df62a --- /dev/null +++ b/tests/bugs172/pr398588/Code2.java @@ -0,0 +1,11 @@ +import java.lang.annotation.*; +import a.b.c.*; + +@Anno +public class Code2 { + @Anno + public static void main(String[] argv) { + System.out.println("abcde"); + } +} + diff --git a/tests/bugs172/pr398588/META-INF/aop.xml b/tests/bugs172/pr398588/META-INF/aop.xml new file mode 100644 index 000000000..a1157bb15 --- /dev/null +++ b/tests/bugs172/pr398588/META-INF/aop.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/src/org/aspectj/systemtest/ajc172/Ajc172Tests.java b/tests/src/org/aspectj/systemtest/ajc172/Ajc172Tests.java index 88094cba6..292efcbee 100644 --- a/tests/src/org/aspectj/systemtest/ajc172/Ajc172Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc172/Ajc172Tests.java @@ -18,13 +18,17 @@ import org.aspectj.testing.XMLBasedAjcTestCase; /** * @author Andy Clement - */ + */ public class Ajc172Tests extends org.aspectj.testing.XMLBasedAjcTestCase { - + + public void testOptionalAspects_pr398588() { + runTest("optional aspects"); + } + public void testInconsistentClassFile_pr389750() { runTest("inconsistent class file"); } - + public void testInconsistentClassFile_pr389750_2() { runTest("inconsistent class file 2"); } @@ -44,13 +48,16 @@ public class Ajc172Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testAnnotationValueError_pr389752_2() { runTest("annotation value error 2"); } - - // this needs some cleverness to fix... the annotation value is parsed as a string and then not checked - // to see if the user is accidentally supplying, for example, an enum value. Due to the use of strings, it - // is hard to check. The verification code might go here: WildAnnotationTypePattern, line 205 (the string case) -// public void testAnnotationValueError_pr389752_3() { -// runTest("annotation value error 3"); -// } + + // this needs some cleverness to fix... the annotation value is parsed as a + // string and then not checked + // to see if the user is accidentally supplying, for example, an enum value. + // Due to the use of strings, it + // is hard to check. The verification code might go here: + // WildAnnotationTypePattern, line 205 (the string case) + // public void testAnnotationValueError_pr389752_3() { + // runTest("annotation value error 3"); + // } // --- diff --git a/tests/src/org/aspectj/systemtest/ajc172/ajc172.xml b/tests/src/org/aspectj/systemtest/ajc172/ajc172.xml index d6a2897ad..81217b60f 100644 --- a/tests/src/org/aspectj/systemtest/ajc172/ajc172.xml +++ b/tests/src/org/aspectj/systemtest/ajc172/ajc172.xml @@ -1,7 +1,39 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index c46c68985..7bf873bb1 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -1000,41 +1000,44 @@ public class BcelWorld extends World implements Repository { @Override public boolean hasUnsatisfiedDependency(ResolvedType aspectType) { - if (!aspectRequiredTypesProcessed) { - if (aspectRequiredTypes != null) { - List forRemoval = new ArrayList(); - for (Map.Entry entry : aspectRequiredTypes.entrySet()) { - ResolvedType rt = this.resolve(UnresolvedType.forName(entry.getValue())); - if (!rt.isMissing()) { - forRemoval.add(entry.getKey()); - } else { - if (!getMessageHandler().isIgnoring(IMessage.INFO)) { - getMessageHandler().handleMessage( - MessageUtil.info("deactivating aspect '" + aspectType.getName() + "' as it requires type '" - + rt.getName() + "' which cannot be found on the classpath")); - } + if (aspectRequiredTypes == null) { + // no aspects require anything, so there can be no unsatisfied dependencies + return false; + } + String aspectName = aspectType.getName(); + if (!aspectRequiredTypesProcessed.contains(aspectName)) { + String requiredTypeName = aspectRequiredTypes.get(aspectName); + if (requiredTypeName==null) { + aspectRequiredTypesProcessed.add(aspectName); + return false; + } else { + ResolvedType rt = resolve(UnresolvedType.forName(requiredTypeName)); + if (!rt.isMissing()) { + aspectRequiredTypesProcessed.add(aspectName); + aspectRequiredTypes.remove(aspectName); + return false; + } else { + if (!getMessageHandler().isIgnoring(IMessage.INFO)) { + getMessageHandler().handleMessage( + MessageUtil.info("deactivating aspect '" + aspectName + "' as it requires type '" + + requiredTypeName + "' which cannot be found on the classpath")); } - } - for (String key : forRemoval) { - aspectRequiredTypes.remove(key); + aspectRequiredTypesProcessed.add(aspectName); + return true; } } - aspectRequiredTypesProcessed = true; - } - if (aspectRequiredTypes == null) { - return false; } - return aspectRequiredTypes.containsKey(aspectType.getName()); + return aspectRequiredTypes.containsKey(aspectName); } - private boolean aspectRequiredTypesProcessed = false; + private List aspectRequiredTypesProcessed = new ArrayList(); private Map aspectRequiredTypes = null; - public void addAspectRequires(String name, String requiredType) { + public void addAspectRequires(String aspectClassName, String requiredType) { if (aspectRequiredTypes == null) { aspectRequiredTypes = new HashMap(); } - aspectRequiredTypes.put(name, requiredType); + aspectRequiredTypes.put(aspectClassName, requiredType); } /** -- 2.39.5