diff options
author | mkersten <mkersten> | 2004-08-18 23:38:38 +0000 |
---|---|---|
committer | mkersten <mkersten> | 2004-08-18 23:38:38 +0000 |
commit | 9be4b2e3694e69244a003d1b279f91d79eb2abe8 (patch) | |
tree | 904c348e647654c4fa5a6c3bda568268e581282e /docs/sandbox | |
parent | f335d93e363941f212bb3126339a3bca505a69f2 (diff) | |
download | aspectj-9be4b2e3694e69244a003d1b279f91d79eb2abe8.tar.gz aspectj-9be4b2e3694e69244a003d1b279f91d79eb2abe8.zip |
Added support for clients to extend the ASM relationships in order to add
new relationships (such as the example in the sandbox that adds additional
declared-parents relationships). There is no structural change to the compiler
or weaver. The AsmRelationshipProvider is now accessed by getDefault()
instead of statically, and its instance can be reset to be a subtype.
Diffstat (limited to 'docs/sandbox')
-rw-r--r-- | docs/sandbox/api-clients/.classpath | 1 | ||||
-rw-r--r-- | docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java | 88 |
2 files changed, 89 insertions, 0 deletions
diff --git a/docs/sandbox/api-clients/.classpath b/docs/sandbox/api-clients/.classpath index 66888ff8c..03a2855ea 100644 --- a/docs/sandbox/api-clients/.classpath +++ b/docs/sandbox/api-clients/.classpath @@ -10,5 +10,6 @@ <classpathentry kind="var" path="JUNIT_HOME/junit.jar"/> <classpathentry kind="lib" path="/org.aspectj.ajdt.core/out/lib.jar"/> <classpathentry kind="src" path="/org.eclipse.jdt.core"/> + <classpathentry kind="src" path="/weaver"/> <classpathentry kind="output" path=""/> </classpath> diff --git a/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java b/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java new file mode 100644 index 000000000..11b9ff0d4 --- /dev/null +++ b/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java @@ -0,0 +1,88 @@ +package org.aspectj.samples; + +import java.util.Iterator; +import java.util.List; + +import org.aspectj.ajde.AjdeTestCase; +import org.aspectj.asm.*; +import org.aspectj.asm.internal.ProgramElement; +import org.aspectj.bridge.ISourceLocation; +import org.aspectj.weaver.AsmRelationshipProvider; +import org.aspectj.weaver.ResolvedTypeX; + +/** + * @author Mik Kersten + */ +public class AsmRelationshipMapExtensionTest extends AjdeTestCase { + + public void testDeclares() { + System.out.println("----------------------------------"); + System.out.println("Parents declared by declare parents statements: "); + HierarchyWalker walker = new HierarchyWalker() { + public void preProcess(IProgramElement node) { + if (node.getKind().equals(IProgramElement.Kind.DECLARE_PARENTS)) { + System.out.println(node); + + List relations = AsmManager.getDefault().getRelationshipMap().get(node); + if (relations != null) { + for (Iterator it = relations.iterator(); it.hasNext();) { + IRelationship relationship = (IRelationship) it.next(); + List targets = relationship.getTargets(); + for (Iterator iter = targets.iterator(); iter.hasNext();) { + IProgramElement currElt = AsmManager + .getDefault().getHierarchy() + .getElement((String) iter.next()); + System.out.println("--> " + relationship.getName() + ": " + currElt); + } + } + } + } + } + }; + AsmManager.getDefault().getHierarchy().getRoot().walk(walker); + } + + protected void setUp() throws Exception { + AsmRelationshipProvider.setDefault(new DeclareInfoProvider()); + super.setUp("examples"); + + assertTrue("build success", + doSynchronousBuild("../examples/coverage/coverage.lst")); + } +} + +class DeclareInfoProvider extends AsmRelationshipProvider { + + public void addDeclareParentsRelationship(ISourceLocation decp, + ResolvedTypeX targetType, List newParents) { + super.addDeclareParentsRelationship(decp, targetType, newParents); + for (Iterator it = newParents.iterator(); it.hasNext();) { + ResolvedTypeX superType = (ResolvedTypeX) it.next(); + + String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn()); + IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle); + + String superHandle = ProgramElement.createHandleIdentifier( + superType.getSourceLocation().getSourceFile(), + superType.getSourceLocation().getLine(), + superType.getSourceLocation().getColumn()); + + if (sourceHandle != null && superHandle != null) { + IRelationship foreward = AsmManager.getDefault().getRelationshipMap().get( + sourceHandle, + IRelationship.Kind.DECLARE, + "super types declared", + false, + true); + foreward.addTarget(superHandle); + + IRelationship back = AsmManager.getDefault().getRelationshipMap().get( + superHandle, IRelationship.Kind.DECLARE, + "declared as super type by", + false, + true); + back.addTarget(sourceHandle); + } + } + } +}
\ No newline at end of file |