KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > AJClassNode


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

22 package org.aspectj.debugger.gui;
23
24 import com.sun.jdi.*;
25 import java.util.*;
26
27 public class AJClassNode extends AJTreeNode {
28
29     private ReferenceType refType;
30
31     public AJClassNode(ReferenceType refType) {
32         super(AJIcons.CLASS_ICON);
33         this.refType = refType;
34         setUserObject(refType);
35         if (!callsAddKids()) addKids();
36     }
37
38     private byte numAddKids = 0;
39     protected void addKids() {
40         if (numAddKids++ > 1) throw new RuntimeException JavaDoc("Only call addKids() once");
41         addSuperTypes();
42         addStaticFields();
43         addMethods();
44     }
45
46     protected boolean callsAddKids() {
47         return false;
48     }
49
50     private void addSuperTypes() {
51         if (refType instanceof ClassType) addSuperTypes((ClassType) refType);
52         else if (refType instanceof InterfaceType) addSuperTypes((InterfaceType) refType);
53         else if (refType instanceof ArrayType) addSuperTypes((ArrayType) refType);
54     }
55
56     private void addSuperTypes(ClassType classType) {
57         if (classType.name().equals("java.lang.Object")) {
58             return;
59         }
60         ClassType superClass = classType.superclass();
61         if (superClass != null) {
62             add(newClassNode(superClass));
63         }
64         addSuperTypes(classType.allInterfaces());
65     }
66
67     protected AJClassNode newClassNode(ReferenceType refType) {
68         return new AJClassNode(refType);
69     }
70
71     private void addSuperTypes(InterfaceType interfaceType) {
72         addSuperTypes(interfaceType.superinterfaces());
73     }
74
75     private void addSuperTypes(List interfaces) {
76         Iterator iter = interfaces.iterator();
77         while (iter.hasNext()) {
78             InterfaceType interfaceType = (InterfaceType) iter.next();
79             add(newClassNode(interfaceType));
80         }
81     }
82
83     private void addSuperTypes(ArrayType arrayType) {
84     }
85
86     private void addStaticFields() {
87         if (refType == null) return;
88         Iterator iter = refType.allFields().iterator();
89         while (iter.hasNext()) {
90             Field field = (Field) iter.next();
91             if (field.isStatic() && field.declaringType().equals(refType)) {
92                 AJValueNode valueNode = AJValueNodeFactory.make(refType, field);
93
94                 //??? We don't want any compiler-generated fields
95
if (valueNode.getName().indexOf("$") == -1) {
96                     add(valueNode);
97                 }
98             }
99         }
100     }
101
102     /**
103      * Nodes in the class tree should implement this method.
104      */

105     protected void addMethods() {
106     }
107
108     public int getType() {
109         if (refType == null) {
110 // throw new RuntimeException
111
// ("This should have been overriden " + this + ":" + getClass());
112
} else if (refType instanceof ClassType) {
113             ClassType type = (ClassType) refType;
114             if (type.isStatic()) {
115                 if (type.isPublic()) return AJIcons.CLASS_STATIC_PUBLIC_ICON;
116                 if (type.isPackagePrivate()) return AJIcons.CLASS_STATIC_PACKAGE_ICON;
117                 if (type.isProtected()) return AJIcons.CLASS_STATIC_PROTECTED_ICON;
118                 if (type.isPrivate()) return AJIcons.CLASS_STATIC_PRIVATE_ICON;
119             } else {
120                 if (type.isPublic()) return AJIcons.CLASS_PUBLIC_ICON;
121                 if (type.isPackagePrivate()) return AJIcons.CLASS_PACKAGE_ICON;
122                 if (type.isProtected()) return AJIcons.CLASS_PROTECTED_ICON;
123                 if (type.isPrivate()) return AJIcons.CLASS_PRIVATE_ICON;
124             }
125             return AJIcons.CLASS_ICON;
126         } else if (refType instanceof InterfaceType) {
127             return AJIcons.INTERFACE_ICON;
128         }
129         //XXX
130
//throw new RuntimeException("Bad type for class node " + refType);
131
return AJIcons.CLASS_ICON;
132     }
133
134     public String JavaDoc toString() {
135         return ((ReferenceType)getUserObject()).name();
136     }
137
138 }
139
Popular Tags