KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > models > Local


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.models;
21
22 import com.sun.jdi.AbsentInformationException;
23 import com.sun.jdi.ClassNotLoadedException;
24 import com.sun.jdi.InvalidTypeException;
25 import com.sun.jdi.LocalVariable;
26 import com.sun.jdi.ObjectReference;
27 import com.sun.jdi.StackFrame;
28 import com.sun.jdi.Value;
29 import org.netbeans.api.debugger.jpda.InvalidExpressionException;
30 import org.netbeans.api.debugger.jpda.JPDAThread;
31 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
32
33
34 /**
35  * @author Jan Jancura
36  */

37 class Local extends AbstractVariable implements
38 org.netbeans.api.debugger.jpda.LocalVariable {
39         
40     protected LocalVariable local;
41     JPDAThread thread;
42     int depth;
43     String JavaDoc className;
44     String JavaDoc genericSignature;
45     
46     Local (
47         JPDADebuggerImpl debugger,
48         Value value,
49         String JavaDoc className,
50         LocalVariable local,
51         CallStackFrameImpl frame
52     ) {
53         super (
54             debugger,
55             value,
56             local.name () + local.hashCode() +
57                 (value instanceof ObjectReference ? "^" : "")
58         );
59         this.local = local;
60         if (frame != null) {
61             this.thread = frame.getThread();
62             this.depth = frame.getFrameDepth();
63         }
64         this.className = className;
65     }
66
67     Local (
68         JPDADebuggerImpl debugger,
69         Value value,
70         String JavaDoc className,
71         LocalVariable local,
72         String JavaDoc genericSignature,
73         CallStackFrameImpl frame
74     ) {
75         super (
76             debugger,
77             value,
78             genericSignature,
79             local.name () + local.hashCode() +
80                 (value instanceof ObjectReference ? "^" : "")
81         );
82         this.local = local;
83         if (frame != null) {
84             this.thread = frame.getThread();
85             this.depth = frame.getFrameDepth();
86         }
87         this.className = className;
88         this.genericSignature = genericSignature;
89     }
90
91     // LocalVariable impl.......................................................
92

93
94     /**
95     * Returns string representation of type of this variable.
96     *
97     * @return string representation of type of this variable.
98     */

99     public String JavaDoc getName () {
100         return local.name ();
101     }
102
103     /**
104      * Returns name of enclosing class.
105      *
106      * @return name of enclosing class
107      */

108     public String JavaDoc getClassName () {
109         return className;
110     }
111     
112     protected final void setClassName(String JavaDoc className) {
113         this.className = className;
114     }
115
116     /**
117     * Returns string representation of type of this variable.
118     *
119     * @return string representation of type of this variable.
120     */

121     public String JavaDoc getDeclaredType () {
122         return local.typeName ();
123     }
124     
125     protected final void setValue (Value value) throws InvalidExpressionException {
126         try {
127             StackFrame sf = ((CallStackFrameImpl) thread.getCallStack(depth, depth + 1)[0]).getStackFrame();
128             sf.setValue (local, value);
129         } catch (AbsentInformationException aiex) {
130             throw new InvalidExpressionException(aiex);
131         } catch (InvalidTypeException ex) {
132             throw new InvalidExpressionException (ex);
133         } catch (ClassNotLoadedException ex) {
134             throw new InvalidExpressionException (ex);
135         }
136     }
137     
138     // other methods ...........................................................
139

140     final void setFrame(CallStackFrameImpl frame) {
141         this.thread = frame.getThread();
142         this.depth = frame.getFrameDepth();
143     }
144
145     public Local clone() {
146         Local clon;
147         if (genericSignature == null) {
148             clon = new Local(getDebugger(), getJDIValue(), className, local, null);
149         } else {
150             clon = new Local(getDebugger(), getJDIValue(), className, local, genericSignature, null);
151         }
152         clon.depth = this.depth;
153         clon.thread = this.thread;
154         return clon;
155     }
156     
157     public String JavaDoc toString () {
158         return "LocalVariable " + local.name ();
159     }
160 }
161
Popular Tags