blob: cf1c6a4d5c11e3b44f9267ef398a5be0967a45f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/* @author Mik Kersten */
// WTI sample broke with API updates in 1.1.1
// START-BROKEN-SAMPLE api-ajde-modelWalker Walk model to collect join point information for advised methods and constructors
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.
*
* @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);
}
}
//END-BROKEN-SAMPLE api-ajde-modelWalker
|