summaryrefslogtreecommitdiffstats
path: root/weaver/src/org
diff options
context:
space:
mode:
authoraclement <aclement>2010-06-16 18:13:32 +0000
committeraclement <aclement>2010-06-16 18:13:32 +0000
commit1e617a5a4a1e0eded7b7d924a4a4b9f0c033b9cf (patch)
tree83190db33e56b4b3947757ce7969d265e684a070 /weaver/src/org
parent52c4b84db0281b3a393179d6ea14618d04467ca4 (diff)
downloadaspectj-1e617a5a4a1e0eded7b7d924a4a4b9f0c033b9cf.tar.gz
aspectj-1e617a5a4a1e0eded7b7d924a4a4b9f0c033b9cf.zip
310506: optional aspects
Diffstat (limited to 'weaver/src/org')
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelWorld.java39
-rw-r--r--weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java14
-rw-r--r--weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java5
3 files changed, 58 insertions, 0 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java
index 31f146480..d9d0ab071 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java
@@ -959,6 +959,45 @@ public class BcelWorld extends World implements Repository {
return xmlConfiguration.getScopeFor(declaringType.getName());
}
+ @Override
+ public boolean hasUnsatisfiedDependency(ResolvedType aspectType) {
+ if (!aspectRequiredTypesProcessed) {
+ if (aspectRequiredTypes != null) {
+ List<String> forRemoval = new ArrayList<String>();
+ for (Map.Entry<String, String> 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"));
+ }
+ }
+ }
+ for (String key : forRemoval) {
+ aspectRequiredTypes.remove(key);
+ }
+ }
+ aspectRequiredTypesProcessed = true;
+ }
+ if (aspectRequiredTypes == null) {
+ return false;
+ }
+ return aspectRequiredTypes.containsKey(aspectType.getName());
+ }
+
+ private boolean aspectRequiredTypesProcessed = false;
+ private Map<String, String> aspectRequiredTypes = null;
+
+ public void addAspectRequires(String name, String requiredType) {
+ if (aspectRequiredTypes == null) {
+ aspectRequiredTypes = new HashMap<String, String>();
+ }
+ aspectRequiredTypes.put(name, requiredType);
+ }
+
/**
* A WeavingXmlConfig is initially a collection of definitions from XML files - once the world is ready and weaving is running
* it will initialize and transform those definitions into an optimized set of values (eg. resolve type patterns and string
diff --git a/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java b/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java
index e3fc3e6f2..dc4d5d77e 100644
--- a/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java
+++ b/weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java
@@ -39,6 +39,11 @@ public class Definition {
*/
private final Map<String, String> scopedAspects;
+ /**
+ * Some aspects (from aspect libraries) will describe a type that must be around for them to function properly
+ */
+ private final Map<String, String> requiredTypesForAspects;
+
public Definition() {
weaverOptions = new StringBuffer();
dumpBefore = false;
@@ -51,6 +56,7 @@ public class Definition {
aspectIncludePatterns = new ArrayList<String>();
concreteAspects = new ArrayList<Definition.ConcreteAspect>();
scopedAspects = new HashMap<String, String>();
+ requiredTypesForAspects = new HashMap<String, String>();
}
public String getWeaverOptions() {
@@ -165,4 +171,12 @@ public class Definition {
return scopedAspects.get(name);
}
+ public void setAspectRequires(String name, String requiredType) {
+ requiredTypesForAspects.put(name, requiredType);
+ }
+
+ public String getAspectRequires(String name) {
+ return requiredTypesForAspects.get(name);
+ }
+
}
diff --git a/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java b/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
index 555311ec1..d20d06e3f 100644
--- a/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
+++ b/weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
@@ -56,6 +56,7 @@ public class DocumentParser extends DefaultHandler {
private final static String CONCRETE_ASPECT_ELEMENT = "concrete-aspect";
private final static String NAME_ATTRIBUTE = "name";
private final static String SCOPE_ATTRIBUTE = "scope";
+ private final static String REQUIRES_ATTRIBUTE = "requires";
private final static String EXTEND_ATTRIBUTE = "extends";
private final static String PRECEDENCE_ATTRIBUTE = "precedence";
private final static String PERCLAUSE_ATTRIBUTE = "perclause";
@@ -147,11 +148,15 @@ public class DocumentParser extends DefaultHandler {
if (ASPECT_ELEMENT.equals(qName)) {
String name = attributes.getValue(NAME_ATTRIBUTE);
String scopePattern = replaceXmlAnd(attributes.getValue(SCOPE_ATTRIBUTE));
+ String requiredType = attributes.getValue(REQUIRES_ATTRIBUTE);
if (!isNull(name)) {
m_definition.getAspectClassNames().add(name);
if (scopePattern != null) {
m_definition.addScopedAspect(name, scopePattern);
}
+ if (requiredType != null) {
+ m_definition.setAspectRequires(name, requiredType);
+ }
}
} else if (WEAVER_ELEMENT.equals(qName)) {
String options = attributes.getValue(OPTIONS_ATTRIBUTE);