diff options
author | avasseur <avasseur> | 2005-11-07 10:04:00 +0000 |
---|---|---|
committer | avasseur <avasseur> | 2005-11-07 10:04:00 +0000 |
commit | e2db71535154c6564fb30bebf2f51fc321a94f7c (patch) | |
tree | 921469eefab6b04632185444fcaf153d064a055d /loadtime | |
parent | 85cde56e2795a70ddc79e59a74652b66218385e0 (diff) | |
download | aspectj-e2db71535154c6564fb30bebf2f51fc321a94f7c.tar.gz aspectj-e2db71535154c6564fb30bebf2f51fc321a94f7c.zip |
aspects/include handling and doc update as per #115275
Diffstat (limited to 'loadtime')
6 files changed, 62 insertions, 14 deletions
diff --git a/loadtime/src/aspectj_1_5_0.dtd b/loadtime/src/aspectj_1_5_0.dtd index 060962745..88856f7e3 100644 --- a/loadtime/src/aspectj_1_5_0.dtd +++ b/loadtime/src/aspectj_1_5_0.dtd @@ -92,16 +92,13 @@ dump aspects ********************************************************************************************************************************* [aspects] defines a set of aspects -TODO we were about to use include but it is already used for weaver scope with "within" which is not relevant -for aspects. I (AV) decided to use only aspect and provide include= thru name, and exclude= as exclude. -see sample. +Note: include only include among Union{aspect, concrete-aspect} WITHIN THIS SOLE aop.xml ******************************************************************************************************************************--> <!ELEMENT aspects ( - (aspect | exclude | concrete-aspect)* + (aspect | exclude | include | concrete-aspect)* )> <!--***************************************************************************************************************************** aspect -TODO: did not used include since already used in weaver/include@within and @within does not makes sense ********************************************************************************************************************************* [aspect] defines an aspect to include @name FQN of the aspect, nested class must use $ diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java index 21249b766..dca1baab9 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java @@ -59,6 +59,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { private List m_excludeStartsWith = new ArrayList(); private List m_aspectExcludeTypePattern = new ArrayList(); private List m_aspectExcludeStartsWith = new ArrayList(); + private List m_aspectIncludeTypePattern = new ArrayList(); + private List m_aspectIncludeStartsWith = new ArrayList(); private StringBuffer namespace; private IWeavingContext weavingContext; @@ -66,7 +68,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { public ClassLoaderWeavingAdaptor(final ClassLoader loader, IWeavingContext wContext) { super(null); } - + void initialize(final ClassLoader loader, IWeavingContext wContext) { //super(null);// at this stage we don't have yet a generatedClassHandler to define to the VM the closures this.generatedClassHandler = new GeneratedClassHandler() { @@ -88,7 +90,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { Aj.defineClass(loader, name, bytes);// could be done lazily using the hook } }; - + if(wContext==null){ weavingContext = new DefaultWeavingContext(loader); }else{ @@ -142,7 +144,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { definitions.add(DocumentParser.parse((new File(file)).toURL())); } } - + String resourcePath = System.getProperty("org.aspectj.weaver.loadtime.configuration",AOP_XML); StringTokenizer st = new StringTokenizer(resourcePath,";"); @@ -164,6 +166,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { // AV - see #113511 if (!definitions.isEmpty()) { registerAspectExclude(weaver, loader, definitions); + registerAspectInclude(weaver, loader, definitions); registerAspects(weaver, loader, definitions); registerIncludeExclude(weaver, loader, definitions); registerDump(weaver, loader, definitions); @@ -203,7 +206,6 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { world.setPinpointMode(weaverOption.pinpoint); weaver.setReweavableMode(weaverOption.notReWeavable); world.setXnoInline(weaverOption.noInline); - //world.setBehaveInJava5Way(weaverOption.java5);//TODO should be autodetected ? // AMC - autodetect as per line below, needed for AtAjLTWTests.testLTWUnweavable world.setBehaveInJava5Way(LangUtil.is15VMOrGreater()); //-Xlintfile: first so that lint wins @@ -261,6 +263,22 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { } } + private void registerAspectInclude(final BcelWeaver weaver, final ClassLoader loader, final List definitions) { + String fastMatchInfo = null; + for (Iterator iterator = definitions.iterator(); iterator.hasNext();) { + Definition definition = (Definition) iterator.next(); + for (Iterator iterator1 = definition.getAspectIncludePatterns().iterator(); iterator1.hasNext();) { + String include = (String) iterator1.next(); + TypePattern includePattern = new PatternParser(include).parseTypePattern(); + m_aspectIncludeTypePattern.add(includePattern); + fastMatchInfo = looksLikeStartsWith(include); + if (fastMatchInfo != null) { + m_aspectIncludeStartsWith.add(fastMatchInfo); + } + } + } + } + /** * Register the aspect, following include / exclude rules * @@ -464,19 +482,28 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { return accept; } + //FIXME we don't use include/exclude of others aop.xml + //this can be nice but very dangerous as well to change that private boolean acceptAspect(String aspectClassName) { // avoid ResolvedType if not needed - if (m_aspectExcludeTypePattern.isEmpty()) { + if (m_aspectExcludeTypePattern.isEmpty() && m_aspectIncludeTypePattern.isEmpty()) { return true; } // still try to avoid ResolvedType if we have simple patterns + // EXCLUDE: if one match then reject String fastClassName = aspectClassName.replace('/', '.').replace('.', '$'); for (int i = 0; i < m_aspectExcludeStartsWith.size(); i++) { if (fastClassName.startsWith((String)m_aspectExcludeStartsWith.get(i))) { return false; } } + //INCLUDE: if one match then accept + for (int i = 0; i < m_aspectIncludeStartsWith.size(); i++) { + if (fastClassName.startsWith((String)m_aspectIncludeStartsWith.get(i))) { + return true; + } + } // needs further analysis ResolvedType classInfo = weaver.getWorld().resolve(UnresolvedType.forName(aspectClassName), true); @@ -488,7 +515,17 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { return false; } } - return true; + //include are "OR"ed + boolean accept = true;//defaults to true if no include + for (Iterator iterator = m_aspectIncludeTypePattern.iterator(); iterator.hasNext();) { + TypePattern typePattern = (TypePattern) iterator.next(); + accept = typePattern.matchesStatically(classInfo); + if (accept) { + break; + } + // goes on if this include did not match ("OR"ed) + } + return accept; } public boolean shouldDump(String className) { @@ -508,11 +545,11 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { } return false; } - + /* * shared classes methods */ - + /** * @return Returns the key. */ @@ -532,7 +569,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { } return false; } - + /** * Flush the generated classes cache */ diff --git a/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java b/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java index 9bea5cd2d..efb7d3259 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/definition/Definition.java @@ -33,6 +33,8 @@ public class Definition { private List m_aspectExcludePatterns; + private List m_aspectIncludePatterns; + private List m_concreteAspects; public Definition() { @@ -42,6 +44,7 @@ public class Definition { m_excludePatterns = new ArrayList(0); m_aspectClassNames = new ArrayList(); m_aspectExcludePatterns = new ArrayList(0); + m_aspectIncludePatterns = new ArrayList(0); m_concreteAspects = new ArrayList(0); } @@ -69,6 +72,10 @@ public class Definition { return m_aspectExcludePatterns; } + public List getAspectIncludePatterns() { + return m_aspectIncludePatterns; + } + public List getConcreteAspects() { return m_concreteAspects; } diff --git a/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java b/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java index ac80afd20..c5744a85e 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java @@ -193,6 +193,11 @@ public class DocumentParser extends DefaultHandler { if (!isNull(typePattern)) { m_definition.getAspectExcludePatterns().add(typePattern); } + } else if (INCLUDE_ELEMENT.equals(qName) && m_inAspects) { + String typePattern = attributes.getValue(WITHIN_ATTRIBUTE); + if (!isNull(typePattern)) { + m_definition.getAspectIncludePatterns().add(typePattern); + } } else { throw new SAXException("Unknown element while parsing <aspectj> element: " + qName); } diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java index d8204d263..fddbc2794 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/DocumentParserTest.java @@ -37,6 +37,7 @@ public class DocumentParserTest extends TestCase { assertEquals("foo..bar.Goo+", def.getIncludePatterns().get(0)); assertEquals("@Baz", def.getAspectExcludePatterns().get(0)); + assertEquals("@Whoo", def.getAspectIncludePatterns().get(0)); assertEquals("foo..*", def.getDumpPatterns().get(0)); } diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml index ef4946e19..f565e6ef1 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml @@ -7,6 +7,7 @@ </weaver> <aspects> <exclude within="@Baz"/> + <include within="@Whoo"/> <aspect name="test.Aspect"/> </aspects> </aspectj> |