]> source.dussan.org Git - aspectj.git/blob
b7f81415ff199a9962862700d4437ac0e80ea1cb
[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 Eclipse Public License v1.0 
6  * which accompanies this distribution and is available at 
7  * http://www.eclipse.org/legal/epl-v10.html 
8  *  
9  * Contributors: 
10  *     Mik Kersten     initial implementation 
11  * ******************************************************************/
12  
13 package org.aspectj.ajdt.internal.compiler.lookup;
14
15 //import java.io.IOException;
16
17 import org.aspectj.asm.AsmManager;
18 import org.aspectj.asm.IProgramElement;
19 import org.aspectj.asm.IRelationship;
20 import org.aspectj.asm.IRelationshipMap;
21 import org.aspectj.weaver.ResolvedType;
22
23 /**
24  * !!! is this class still being used?
25  * 
26  * @author Mik Kersten
27  */
28 public class AsmInterTypeRelationshipProvider {
29
30     protected static AsmInterTypeRelationshipProvider INSTANCE = new AsmInterTypeRelationshipProvider();
31     
32         public static final String INTER_TYPE_DECLARES = "declared on";
33         public static final String INTER_TYPE_DECLARED_BY = "aspect declarations";
34
35         public void addRelationship(
36                 ResolvedType onType,
37                 EclipseTypeMunger munger) {
38                         
39 //              IProgramElement.Kind kind = IProgramElement.Kind.ERROR;
40 //              if (munger.getMunger().getKind() == ResolvedTypeMunger.Field) {
41 //                      kind = IProgramElement.Kind.INTER_TYPE_FIELD;
42 //              } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Constructor) {
43 //                      kind = IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR;
44 //              } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Method) {
45 //                      kind = IProgramElement.Kind.INTER_TYPE_METHOD;
46 //              } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Parent) {
47 //                      kind = IProgramElement.Kind.INTER_TYPE_PARENT;
48 //              }        
49         
50                 if (munger.getSourceLocation() != null
51                         && munger.getSourceLocation() != null) {
52                         IProgramElement sourceIPE = AsmManager.getDefault().getHierarchy()
53                                 .findElementForSourceLine(munger.getSourceLocation());
54                         String sourceHandle = AsmManager.getDefault().getHandleProvider()
55                                 .createHandleIdentifier(sourceIPE);
56                         
57                         IProgramElement targetIPE = AsmManager.getDefault().getHierarchy()
58                                 .findElementForSourceLine(onType.getSourceLocation());
59                         String targetHandle = AsmManager.getDefault().getHandleProvider()
60                                 .createHandleIdentifier(targetIPE);
61                                 
62                         IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
63                         if (sourceHandle != null && targetHandle != null) {
64                                 IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARES,false,true);
65                                 foreward.addTarget(targetHandle);
66                                 
67                                 IRelationship back = mapper.get(targetHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARED_BY,false,true);
68                                 back.addTarget(sourceHandle);
69                         }
70                 }
71         }
72         
73     public static AsmInterTypeRelationshipProvider getDefault() {
74         return INSTANCE;
75     }
76     
77     /**
78      * Reset the instance of this class, intended for extensibility.
79      * This enables a subclass to become used as the default instance.
80      */
81     public static void setDefault(AsmInterTypeRelationshipProvider instance) {
82         INSTANCE = instance;
83     }
84 }