KickJava   Java API By Example, From Geeks To Geeks.

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


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 Inheritance implements Association {
41     public static final String JavaDoc NAME = "Inheritance";
42     public static final Relation INHERITS_RELATION = new Relation("inherits", "is inherited by", NAME, true, true);
43     public static final Relation IMPLEMENTS_RELATION = new Relation("implements", "is implemented by", NAME, true, true);
44     public static final Relation INHERITS_MEMBERS_RELATION = new Relation("inherits members", NAME, false);
45     private List relations = new ArrayList();
46
47     public Inheritance() {
48         relations.add(INHERITS_RELATION);
49         relations.add(IMPLEMENTS_RELATION);
50         relations.add(INHERITS_MEMBERS_RELATION);
51     }
52
53     public List getRelations() {
54         return relations;
55     }
56
57     public List getRelationNodes(ASTObject astObject) {
58         List relations = new ArrayList();
59         if (astObject instanceof TypeDec) {
60             TypeDec typeDec = (TypeDec)astObject;
61             boolean isInterface = (astObject instanceof InterfaceDec);
62             List superTypes = getTypeLinks(typeDec.getType().getDirectSuperTypes(), true, isInterface);
63             List subTypes = getTypeLinks(typeDec.getType().getDirectSubTypes(), true, isInterface);
64             if (!superTypes.isEmpty()) relations.add(new RelationNode(INHERITS_RELATION, INHERITS_RELATION.getForwardNavigationName(), superTypes));
65             if (!subTypes.isEmpty()) relations.add(new RelationNode(INHERITS_RELATION, INHERITS_RELATION.getBackNavigationName(), subTypes));
66
67             List implementedInterfaces = getTypeLinks(typeDec.getType().getDirectSuperTypes(), false, isInterface);
68             List implementors = getTypeLinks(typeDec.getType().getDirectSubTypes(), false, isInterface);
69             if (!implementedInterfaces.isEmpty()) relations.add(new RelationNode(IMPLEMENTS_RELATION, IMPLEMENTS_RELATION.getForwardNavigationName(), implementedInterfaces));
70             if (!implementors.isEmpty()) relations.add(new RelationNode(IMPLEMENTS_RELATION, IMPLEMENTS_RELATION.getBackNavigationName(), implementors));
71
72             List inheritedMembers = new ArrayList(getMemberLinks(typeDec.getType().getInheritedMethods()));
73 // inheritedMembers.addAll();
74
// List inheritedMemberDecs = new ArrayList();
75
if (!inheritedMembers.isEmpty()) relations.add(new RelationNode(INHERITS_MEMBERS_RELATION, INHERITS_MEMBERS_RELATION.getForwardNavigationName(), inheritedMembers));
76         }
77         return relations;
78     }
79
80     private List getTypeLinks(Collection types, boolean isInheritance, boolean isInterface) {
81         List links = new ArrayList();
82         if (types != null) {
83             for (Iterator it = types.iterator(); it.hasNext(); ) {
84                 NameType nameType = (NameType)it.next();
85                 if (!nameType.getId().equals("Object")) {
86                     if (isInheritance && ((isInterface && nameType.isInterface()) || (!isInterface && !nameType.isInterface()))
87                         || !isInheritance && (!isInterface && nameType.isInterface())) {
88                         Dec dec = nameType.getCorrespondingDec();
89                         links.add(StructureNodeFactory.makeLink(dec, false));
90                     }
91                 }
92             }
93         }
94         return links;
95     }
96
97     private List getMemberLinks(Collection members) {
98         List links = new ArrayList();
99         if (members != null) {
100             for (Iterator it = members.iterator(); it.hasNext(); ) {
101                 Object JavaDoc object = it.next();
102                 if (object instanceof Method) {
103                     Method method = (Method)object;
104                     if (!method.getDeclaringType().getId().equals("Object")) {
105                         links.add(StructureNodeFactory.makeLink(method.getCorrespondingDec(), false));
106                     }
107                 } else if (object instanceof Field) {
108                     Field field = (Field)object;
109                     if (!field.getDeclaringType().getId().equals("Object")) {
110                         links.add(StructureNodeFactory.makeLink(field.getCorrespondingDec(), false));
111                     }
112                 }
113             }
114         }
115         return links;
116     }
117
118     public String JavaDoc getName() {
119         return NAME;
120     }
121 }
122
Popular Tags