aboutsummaryrefslogtreecommitdiffstats
path: root/docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapUsageTest.java
blob: 98ecdfa7b89c8c0d2ba34f877eba2492c0909961 (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
71
72
73
74
75
76
77
78
79
80
81
/* *******************************************************************
 * Copyright (c) 2004 Contributors.
 * All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     Mik Kersten     initial implementation 
 * ******************************************************************/

package org.aspectj.samples;

import java.util.Iterator;
import java.util.List;

import org.aspectj.ajde.AjdeTestCase;
import org.aspectj.ajdt.internal.core.builder.AjBuildManager;
import org.aspectj.asm.*;

/**
 * Collects join point information for all advised methods and constructors.  
 * 
 * @author Mik Kersten
 */
public class AsmRelationshipMapUsageTest extends AjdeTestCase {

    public void testFindAdvisedMethods() {        
        System.out.println("----------------------------------");
        System.out.println("Methods affected by advice: ");
        HierarchyWalker walker = new HierarchyWalker() {
            public void preProcess(IProgramElement node) {
                if (node.getKind().equals(IProgramElement.Kind.METHOD)) {
                    List relations = AsmManager.getDefault().getRelationshipMap().get(node);
                    if (relations != null) {
	                    for (Iterator it = relations.iterator(); it.hasNext(); ) {
	                        IRelationship relationship = (IRelationship)it.next();
	                        if (relationship.getKind().equals(IRelationship.Kind.ADVICE)) {
	                            System.out.println(
	                                    "method: " + node.toString() 
	                                    + ", advised by: " + relationship.getTargets());
	                        } 
	                    }
                    }
                }
            }
        };
        AsmManager.getDefault().getHierarchy().getRoot().walk(walker);
    }
    
    public void testListFilesAffectedByInterTypeDecs() {
        System.out.println("----------------------------------");
        System.out.println("Files affected by inter type declarations: ");
        HierarchyWalker walker = new HierarchyWalker() {
            public void preProcess(IProgramElement node) {
                if (node.getKind().equals(IProgramElement.Kind.CLASS)) {
                    List relations = AsmManager.getDefault().getRelationshipMap().get(node);
                    if (relations != null) {
	                    for (Iterator it = relations.iterator(); it.hasNext(); ) {
	                        IRelationship relationship = (IRelationship)it.next();
	                        if (relationship.getKind().equals(IRelationship.Kind.DECLARE_INTER_TYPE)) {
	                            System.out.println(
                                    "file: " + node.getSourceLocation().getSourceFile().getName() 
                                    + ", declared on by: " + relationship.getTargets());
	                        } 
	                    }
                    }
                }
            }
        };
        AsmManager.getDefault().getHierarchy().getRoot().walk(walker);
    }
    
	
	protected void setUp() throws Exception {
	    super.setUp("examples");
		assertTrue("build success", doSynchronousBuild("../examples/spacewar/spacewar/debug.lst"));	
	}
}