diff options
author | mkersten <mkersten> | 2003-07-29 10:53:29 +0000 |
---|---|---|
committer | mkersten <mkersten> | 2003-07-29 10:53:29 +0000 |
commit | 579a6d779f41e89318e5549657058d9008857863 (patch) | |
tree | 9c701dd18573d80ed30225de06c099ac45ae6d86 /docs/samples | |
parent | d203b7fbc03f2a4d6845baeaa653dba6c6e4d55f (diff) | |
download | aspectj-579a6d779f41e89318e5549657058d9008857863.tar.gz aspectj-579a6d779f41e89318e5549657058d9008857863.zip |
Added sample for extending Main to collect joinpoints from ASM.
Diffstat (limited to 'docs/samples')
-rw-r--r-- | docs/samples/extensions/JoinPointCollector.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/docs/samples/extensions/JoinPointCollector.java b/docs/samples/extensions/JoinPointCollector.java new file mode 100644 index 000000000..44065c437 --- /dev/null +++ b/docs/samples/extensions/JoinPointCollector.java @@ -0,0 +1,67 @@ + +package org.aspectj.samples; + +import java.util.*; +import org.aspectj.tools.ajc.Main; + + +import org.aspectj.asm.*; + +/** + * Collects join point information for all advised methods and constructors. Prints results + * to + * + * @author Mik Kersten + */ +public class JoinPointCollector extends Main { + + /** + * + * @param args + */ + public static void main(String[] args) { + String[] newArgs = new String[args.length +1]; + newArgs[0] = "-emacssym"; + for (int i = 0; i < args.length; i++) { + newArgs[i+1] = args[i]; + } + new JoinPointCollector().runMain(newArgs, false); + } + + public void runMain(String[] args, boolean useSystemExit) { + super.runMain(args, useSystemExit); + + ModelWalker walker = new ModelWalker() { + public void preProcess(StructureNode node) { + ProgramElementNode p = (ProgramElementNode)node; + + // first check if it is a method or constructor + if (p.getProgramElementKind().equals(ProgramElementNode.Kind.METHOD)) { + + // now check if it is advsied + for (Iterator it = p.getRelations().iterator(); it.hasNext(); ) { + + RelationNode relationNode = (RelationNode)it.next(); + Relation relation = relationNode.getRelation(); + if (relation == AdviceAssociation.METHOD_RELATION) { + System.out.println("method: " + p.toString() + ", advised by: " + relationNode.getChildren()); + } + } + } + + // code around the fact that constructor advice relationship is on the type + if (p.getProgramElementKind().equals(ProgramElementNode.Kind.CONSTRUCTOR)) { + for (Iterator it = ((ProgramElementNode)p.getParent()).getRelations().iterator(); it.hasNext(); ) { + RelationNode relationNode = (RelationNode)it.next(); + Relation relation = relationNode.getRelation(); + if (relation == AdviceAssociation.CONSTRUCTOR_RELATION) { + System.out.println("constructor: " + p.toString() + ", advised by: " + relationNode.getChildren()); + } + } + } + } + }; + + StructureModelManager.getDefault().getStructureModel().getRoot().walk(walker); + } +} |