Procházet zdrojové kódy

310506: optional aspects

tags/V1_6_9RC2
aclement před 14 roky
rodič
revize
1e617a5a4a

+ 1
- 0
weaver/src/aspectj_1_5_0.dtd Zobrazit soubor

@@ -107,6 +107,7 @@ aspect
<!ATTLIST aspect
name CDATA #REQUIRED
scope CDATA #IMPLIED
requires CDATA #IMPLIED
>
<!--*****************************************************************************************************************************
exclude

+ 39
- 0
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java Zobrazit soubor

@@ -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

+ 14
- 0
weaver/src/org/aspectj/weaver/loadtime/definition/Definition.java Zobrazit soubor

@@ -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);
}

}

+ 5
- 0
weaver/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java Zobrazit soubor

@@ -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);

Načítá se…
Zrušit
Uložit