]> source.dussan.org Git - aspectj.git/blob
329e5b57e468cdd1b19741921fe59d38be1e4a83
[aspectj.git] /
1 /* *******************************************************************
2  * Copyright (c) 2003 Contributors.
3  * All rights reserved. 
4  * This program and the accompanying materials are made available 
5  * under the terms of the Common Public License v1.0 
6  * which accompanies this distribution and is available at 
7  * http://www.eclipse.org/legal/cpl-v10.html 
8  *  
9  * Contributors: 
10  *     Mik Kersten     initial implementation 
11  * ******************************************************************/
12  
13 package org.aspectj.ajdt.internal.compiler.lookup;
14
15 import java.util.*;
16
17 import org.aspectj.asm.*;
18 import org.aspectj.asm.internal.Relationship;
19 import org.aspectj.weaver.*;
20
21 /**
22  * @author Mik Kersten
23  */
24 public class AsmInterTypeRelationshipProvider {
25
26         public static final String INTER_TYPE_DECLARES = "declares on";
27         public static final String INTER_TYPE_DECLARED_BY = "aspect declarations";
28
29         public static void addRelationship(
30                 ResolvedTypeX onType,
31                 EclipseTypeMunger munger) {
32                         
33                 IProgramElement.Kind kind = IProgramElement.Kind.ERROR;
34                 if (munger.getMunger().getKind() == ResolvedTypeMunger.Field) {
35                         kind = IProgramElement.Kind.INTER_TYPE_FIELD;
36                 } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Constructor) {
37                         kind = IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR;
38                 } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Method) {
39                         kind = IProgramElement.Kind.INTER_TYPE_METHOD;
40                 } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Parent) {
41                         kind = IProgramElement.Kind.INTER_TYPE_PARENT;
42                 }        
43         
44                 if (munger.getSourceLocation() != null
45                         && munger.getSourceLocation() != null) {
46                         String sourceHandle = 
47                                 munger.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM
48                                 + munger.getSourceLocation().getLine() + IProgramElement.ID_DELIM
49                                 + munger.getSourceLocation().getColumn();
50                                 
51                         String targetHandle = 
52                                 onType.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM
53                                 + onType.getSourceLocation().getLine() + IProgramElement.ID_DELIM
54                                 + onType.getSourceLocation().getColumn();
55         
56                         IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
57                         if (sourceHandle != null && targetHandle != null) {
58                                 IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARES);
59                                 foreward.getTargets().add(targetHandle);
60                                 
61                                 IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARED_BY);
62                                 back.getTargets().add(sourceHandle);
63                         }
64                 }
65         }
66
67 }