diff options
author | Andy Clement <aclement@gopivotal.com> | 2014-10-06 17:35:51 -0700 |
---|---|---|
committer | Andy Clement <aclement@gopivotal.com> | 2014-10-06 17:35:51 -0700 |
commit | c8e951296c5f95e82d4c7c3f8eb9b0a647014e20 (patch) | |
tree | 2eaed5b80ad735e4c91e424098e35e221f4fea44 /weaver | |
parent | 102173fc11fc6648ed8f2283d3c5ad535e412c73 (diff) | |
download | aspectj-c8e951296c5f95e82d4c7c3f8eb9b0a647014e20.tar.gz aspectj-c8e951296c5f95e82d4c7c3f8eb9b0a647014e20.zip |
Fix 436653: conditional aspect activation plus various polish
Modified test expectation system so it is possible to say
the test cares about one particular message and the rest
do not matter (prefix message string with '*') - crude but
quick.
Polished many places to exploit generics
Upgraded all the tests to work on Java8 - some serious changes
regarding ajdoc on Java8. Hopefully it has stayed backwards
compatible with earlier JDK versions (e.g. if using AspectJ 1.8.3+
with a JDK less than 8) but no explicit testing done for this.
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java | 5 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelWorld.java | 45 | ||||
-rw-r--r-- | weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java | 17 |
3 files changed, 62 insertions, 5 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java index 2286a06cf..5c1ae918b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java @@ -587,6 +587,11 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate { ensureAnnotationsUnpacked(); return annotations; } + + public boolean hasAnnotations() { + ensureAnnotationsUnpacked(); + return annotations.length != 0; + } public boolean hasAnnotation(UnresolvedType ofType) { // Due to re-entrancy we may be in the middle of unpacking the annotations already... in which case use this slow diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index 4dfb30e68..4f0dfe1bc 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -1016,11 +1016,52 @@ public class BcelWorld extends World implements Repository { @Override public boolean hasUnsatisfiedDependency(ResolvedType aspectType) { + String aspectName = aspectType.getName(); + + if (aspectType.hasAnnotations()) { + AnnotationAJ[] annos = aspectType.getAnnotations(); + for (AnnotationAJ anno: annos) { + if (anno.getTypeName().equals("org.aspectj.lang.annotation.RequiredTypes")) { + String values = anno.getStringFormOfValue("value"); // Example: "[A,org.foo.Bar]" + if (values != null && values.length() > 2) { + values = values.substring(1,values.length()-1); + StringTokenizer tokenizer = new StringTokenizer(values,","); + boolean anythingMissing = false; + while (tokenizer.hasMoreElements()) { + String requiredTypeName = tokenizer.nextToken(); + ResolvedType rt = resolve(UnresolvedType.forName(requiredTypeName)); + if (rt.isMissing()) { + if (!getMessageHandler().isIgnoring(IMessage.INFO)) { + getMessageHandler().handleMessage( + MessageUtil.info("deactivating aspect '" + aspectName + "' as it requires type '" + + requiredTypeName + "' which cannot be found on the classpath")); + } + anythingMissing = true; + if (aspectRequiredTypes == null) { + aspectRequiredTypes = new HashMap<String,String>(); + } + // Record that it has an invalid type reference + aspectRequiredTypes.put(aspectName,requiredTypeName); + } + } + if (anythingMissing) { + return true; + } + else { + return false; + } + } + else { + // no value specified for annotation + return false; + } + } + } + } 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) { @@ -1053,7 +1094,7 @@ public class BcelWorld extends World implements Repository { if (aspectRequiredTypes == null) { aspectRequiredTypes = new HashMap<String, String>(); } - aspectRequiredTypes.put(aspectClassName, requiredType); + aspectRequiredTypes.put(aspectClassName,requiredType); } /** diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java index e7332b73c..111d7e54d 100644 --- a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java @@ -13,6 +13,8 @@ package org.aspectj.weaver.bcel; import java.lang.reflect.Modifier; +import java.util.Objects; +import java.util.function.Consumer; import org.aspectj.weaver.Advice; import org.aspectj.weaver.BcweaverTests; @@ -108,11 +110,20 @@ public class WorldTestCase extends CommonWorldTests { modifiersTest(iter, abstractPublic | Modifier.INTERFACE); fieldsTest(iter, ResolvedMember.NONE); - methodsTest(iter, new Member[] { MemberImpl.method(iter, 0, "hasNext", "()Z"), MemberImpl.method(iter, 0, "remove", "()V"), - MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), }); + methodsTest(iter, new Member[] { + MemberImpl.method(iter, 0, "hasNext", "()Z"), + MemberImpl.method(iter, 0, "remove", "()V"), + MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), + MemberImpl.method(iter, 0, "forEachRemaining", "(Ljava/util/function/Consumer;)V") +// default void forEachRemaining(Consumer<? super E> action) { +// Objects.requireNonNull(action); +// while (hasNext()) +// action.accept(next()); +// } + }); ResolvedMember remove = iter.lookupMethod(MemberImpl.method(iter, 0, "remove", "()V")); assertNotNull("iterator doesn't have remove", remove); - modifiersTest(remove, abstractPublic | Modifier.INTERFACE); + modifiersTest(remove, Modifier.PUBLIC | Modifier.INTERFACE); // no longer abstract in Java8 (default instead) exceptionsTest(remove, UnresolvedType.NONE); ResolvedMember clone = iter.lookupMethod(MemberImpl.method(UnresolvedType.OBJECT, 0, "clone", "()Ljava/lang/Object;")); |