KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > asm > associations > Reference


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25
26 package org.aspectj.asm.associations;
27
28 import java.util.*;
29 import org.aspectj.compiler.base.*;
30 import org.aspectj.compiler.base.ast.*;
31 import org.aspectj.compiler.base.cst.*;
32 import org.aspectj.compiler.crosscuts.*;
33 import org.aspectj.compiler.crosscuts.ast.*;
34 import org.aspectj.asm.*;
35 import org.aspectj.asm.internal.*;
36
37 /**
38  * @author Mik Kersten
39  */

40 public class Reference implements Association {
41     public static final String JavaDoc NAME = "Reference";
42     public static final Relation USES_POINTCUT_RELATION = new Relation("uses pointcut", "pointcut used by", NAME, true, true);
43     public static final Relation IMPORTS_RELATION = new Relation("imports", NAME, false);
44     //public static final Relation THROWS_RELATION = new Relation("throws", NAME, false);
45
//public static final Relation USES_TYPE_RELATION = new Relation("uses type", NAME, false);
46

47     private List relations = new ArrayList();
48
49     public Reference() {
50         relations.add(USES_POINTCUT_RELATION);
51         relations.add(IMPORTS_RELATION);
52         //relations.add(THROWS_RELATION);
53
//relations.add(USES_TYPE_RELATION);
54
}
55
56     public List getRelations() {
57         return relations;
58     }
59
60     public List getRelationNodes(ASTObject astObject) {
61         List relations = new ArrayList();
62         List pointcutsUsed = new ArrayList();
63         List pointcutUsedBy = new ArrayList();
64         List throwsTypes = new ArrayList();
65         List imports = new ArrayList();
66         List usesType = new ArrayList();
67         Set forwardCorrs = StructureModelManager.correspondences.getAffects(astObject);
68         Set backCorrs = StructureModelManager.correspondences.getAffectedBy(astObject);
69
70         if (astObject instanceof AdviceDec) {
71             for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) {
72                 ASTObject node = (ASTObject)it.next();
73                 if (node instanceof PointcutDec) {
74                     pointcutsUsed.add(StructureNodeFactory.makeLink(node, false));
75                 }
76             }
77         } else if (astObject instanceof PointcutDec) {
78             for (Iterator it = backCorrs.iterator(); it.hasNext(); ) {
79                 ASTObject node = (ASTObject)it.next();
80                 if (node instanceof PointcutDec || node instanceof AdviceDec) {
81                     pointcutUsedBy.add(StructureNodeFactory.makeLink(node, false));
82                 }
83             }
84             for (Iterator it = forwardCorrs.iterator(); it.hasNext(); ) {
85                 ASTObject node = (ASTObject)it.next();
86                 if (node instanceof PointcutDec) {
87                     pointcutsUsed.add(StructureNodeFactory.makeLink(node, false));
88                 }
89             }
90         } else if (astObject instanceof MethodDec) {
91             Method method = ((MethodDec)astObject).getMethod();
92             TypeDs throwsDs = method.getThrows();
93             if (throwsDs != null) {
94                 for (Iterator it = throwsDs.iterator(); it.hasNext(); ) {
95                     Object JavaDoc o = it.next();
96                     if (o instanceof ResolvedTypeD) {
97                         ResolvedTypeD resolved = (ResolvedTypeD)o;
98                         if (resolved.getType().getCorrespondingDec() != null) {
99                             throwsTypes.add(StructureNodeFactory.makeLink(resolved.getType().getCorrespondingDec(), false));
100                         }
101                     }
102                 }
103             }
104             if (!(method.getReturnType() instanceof PrimitiveType) && method.getReturnType().getCorrespondingDec() != null) {
105                     usesType.add(StructureNodeFactory.makeLink(method.getReturnType().getCorrespondingDec(), false));
106             }
107         } else if (astObject instanceof FieldDec) {
108             Field field = ((FieldDec)astObject).getField();
109             if (!(field.getFieldType() instanceof PrimitiveType) && field.getFieldType().getCorrespondingDec() != null) {
110                 usesType.add(StructureNodeFactory.makeLink(field.getFieldType().getCorrespondingDec(), false));
111             }
112         }
113         else if (astObject instanceof CompilationUnit) {
114             CompilationUnit cu = (CompilationUnit)astObject;
115             org.aspectj.compiler.base.ast.Imports cuImports = cu.getImports();
116             for (int i = 0; cuImports != null && i < cuImports.getChildCount(); i++) {
117                 Import imp = cuImports.get(i);
118                 if (!imp.getStar() && imp != null && imp.getType() != null) {
119                     Type type = imp.getType();
120                     Dec dec = type.getCorrespondingDec();
121                     if (dec != null) imports.add(StructureNodeFactory.makeLink(dec, true));
122                 }
123             }
124         }
125
126         if (!pointcutsUsed.isEmpty()) relations.add(new RelationNode(USES_POINTCUT_RELATION, USES_POINTCUT_RELATION.getForwardNavigationName(), pointcutsUsed));
127         if (!pointcutUsedBy.isEmpty()) relations.add(new RelationNode(USES_POINTCUT_RELATION, USES_POINTCUT_RELATION.getBackNavigationName(), pointcutUsedBy));
128         //if (!throwsTypes.isEmpty()) relations.add(new RelationNode(THROWS_RELATION, THROWS_RELATION.getForwardNavigationName(), throwsTypes));
129
if (!imports.isEmpty()) relations.add(new RelationNode(IMPORTS_RELATION, IMPORTS_RELATION.getForwardNavigationName(), imports));
130         //if (!usesType.isEmpty()) relations.add(new RelationNode(USES_TYPE_RELATION, USES_TYPE_RELATION.getForwardNavigationName(), usesType));
131
return relations;
132     }
133
134     public String JavaDoc getName() {
135         return NAME;
136     }
137 }
138
139
140 //public class JavadocSeeAlso {
141
//
142
// private static final String DOC =
143
// "<b>Relates:</b> a declaration to another by the @seeAlso tag<br>" +
144
// "<b>Symmetric: </b> yes";
145
//
146
// public List makeLinks(ASTObject astObject, boolean forwardNavigation) {
147
// List linkList = new Vector();
148
// org.aspectj.compiler.base.ast.Comment comment = astObject.getComment();
149
// try {
150
// Object[] os = (Object[])comment.getClass().getMethod("seeTags", new Class[]{}).invoke(comment, new Object[]{});
151
// for (int i = 0; i < os.length; i++) {
152
// Object o = os[i];
153
// Dec docDec = null;
154
// TypeDec typeDec = (TypeDec)o.getClass().getMethod("referencedClass", new Class[]{}).invoke(o, new Object[]{});
155
// Dec memberDec = (Dec)o.getClass().getMethod("referencedMember", new Class[]{}).invoke(o, new Object[]{});
156
// if (memberDec != null) {
157
// docDec = memberDec;
158
// } else if (typeDec != null) {
159
// docDec = typeDec;
160
// }
161
// if (docDec != null) {
162
// linkList.add(StructureNodeFactory.makeLink(docDec, false));
163
//
164
// }
165
// }
166
// } catch (Throwable t) {
167
// // ingore
168
// }
169
// return linkList;
170
// }
171

172
173
Popular Tags