KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 package org.aspectj.debugger.gui;
24
25 import org.aspectj.debugger.base.*;
26
27 import java.awt.datatransfer.*;
28 import java.awt.event.MouseEvent JavaDoc;
29 import java.util.*;
30 import javax.swing.tree.*;
31 import com.sun.jdi.*;
32
33 public class AJValueNode extends AJTreeNode {
34
35     protected AJValueGetter getter = null;
36
37     public AJValueNode(AJValueGetter getter, int type) {
38         super(type);
39         this.getter = getter;
40         //setType(_getType());
41
}
42     public AJValueNode(AJValueGetter getter) {
43         this(getter, AJIcons.BAD_ICON);
44         setType(_getType());
45     }
46
47     public Value getValue() {
48         return getter.getValue();
49     }
50
51     public Value getValue(String JavaDoc s) {
52         return getter.getValue(s);
53     }
54
55     public ReferenceType getDeclaringClass() {
56         return getter.getDeclaringClass();
57     }
58
59     public boolean canSetWatchPoint() {
60         return (getDeclaringClass() != null);
61     }
62
63     public void setValue(Object JavaDoc o) throws DebuggerException {
64         if (o == null) return;
65         AJTreeNode parent = (AJTreeNode) getParent();
66         while (!parent.isStackFrame()) {
67             parent = (AJTreeNode) parent.getParent();
68         }
69         AJStackFrameNode parentHack = (AJStackFrameNode) parent;
70         try {
71             getter.setValue(ComponentRepository.getAJDebugger().getValue(o, parentHack.getStackFrame()));
72         } catch (ClassNotLoadedException cnle) {
73         } catch (InvalidTypeException ite) {
74             AJUtil.ex(ite);
75         }
76     }
77
78     public void setWatchPoint() {
79         ReferenceType refType = getDeclaringClass();
80         if (refType == null) {
81             AJUtil.warn("You cannot set a watchpoint on: " + this);
82             return;
83         }
84         String JavaDoc declaringType = refType.name();
85         String JavaDoc name = getName();
86         String JavaDoc command = "watch " + declaringType + "." + name;
87         ComponentRepository.getCommandLine().executeCommand(command);
88     }
89
90     //
91
//TODO: Deal with exception
92
//
93
public ThreadReference getThread()
94             throws ClassNotLoadedException,
95                     IncompatibleThreadStateException {
96         return getter.getThread();
97     }
98
99     public String JavaDoc getName() {
100         return getter.getName();
101     }
102
103     public Type getTypeRef() throws ClassNotLoadedException {
104         return getter.getTypeRef();
105     }
106
107     //
108
// TODO: Deal with exception
109
//
110
public String JavaDoc getTypeName() {
111         try {
112         return getter.getTypeName();
113         } catch (Exception JavaDoc e) { Util.error(e); }
114         return "";
115     }
116
117     //
118
// TODO: Deal with exception
119
//
120
public String JavaDoc getValueString() {
121         try {
122             return "" + getter.getValue();
123         } catch (Exception JavaDoc e) {
124         }
125         return "";
126     }
127
128     //
129
// TODO: Deal with exception
130
//
131
public String JavaDoc toString() {
132         String JavaDoc name = "<no-name>";
133         String JavaDoc type = "<no-type>";
134         Value value = null;
135         try {
136             name = getter.getName();
137         } catch (Exception JavaDoc e) {
138         }
139         try {
140             type = AJUtil.stripParens(getter.getTypeName());
141         } catch (Exception JavaDoc e) {
142         }
143         try {
144             value = getValue();
145         } catch (InvalidStackFrameException isfe) {
146         }
147         return name + ": " + type + " = " + format(value);
148     }
149
150     //!!! Should be abstract
151
protected String JavaDoc format(Value value) {
152         return value + "";
153     }
154
155     public boolean isField() {
156         return g() instanceof FieldGetter;
157     }
158
159     //private int type = -1;
160
// public int getType() {
161
// return (type == -1) ? (type = _getType()) : type;
162
// }
163
private int _getType() {
164         if (isField()) {
165             FieldGetter g = (FieldGetter) g();
166             Field field = g.getField();
167             if (field.isStatic()) {
168                 if (field.isPublic()) return AJIcons.FIELD_STATIC_PUBLIC_ICON;
169                 if (field.isPackagePrivate()) return AJIcons.FIELD_STATIC_PACKAGE_ICON;
170                 if (field.isProtected()) return AJIcons.FIELD_STATIC_PROTECTED_ICON;
171                 if (field.isPrivate()) return AJIcons.FIELD_STATIC_PRIVATE_ICON;
172             } else {
173                 if (field.isPublic()) return AJIcons.FIELD_PUBLIC_ICON;
174                 if (field.isPackagePrivate()) return AJIcons.FIELD_PACKAGE_ICON;
175                 if (field.isProtected()) return AJIcons.FIELD_PROTECTED_ICON;
176                 if (field.isPrivate()) return AJIcons.FIELD_PRIVATE_ICON;
177             }
178         }
179         return getType();
180     }
181
182     protected AJValueGetter g() {
183         return getter;
184     }
185
186     public void leftMouseButton(MouseEvent JavaDoc e) {
187     }
188
189     public void middleMouseButton(MouseEvent JavaDoc e) {
190         AJTreeNodeMenu.showValueNodeMenu(this, e.getComponent(), e.getX(), e.getY());
191     }
192
193     public void rightMouseButton(MouseEvent JavaDoc e) {
194         AJTreeNodeMenu.showValueNodeMenu(this, e.getComponent(), e.getX(), e.getY());
195     }
196
197     public void setValue() {
198         Dialogs.showNewValueDialog(this);
199     }
200
201     public boolean isValueNode() {
202         return true;
203     }
204 }
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
Popular Tags