KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > model > JDIThisVariable


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.core.model;
12
13
14 import com.ibm.icu.text.MessageFormat;
15
16 import org.eclipse.debug.core.DebugException;
17
18 import com.sun.jdi.ObjectReference;
19 import com.sun.jdi.ReferenceType;
20 import com.sun.jdi.Type;
21 import com.sun.jdi.Value;
22
23
24 /**
25  * Represents the receiver in a stack frame.
26  */

27
28 public class JDIThisVariable extends JDIVariable {
29     /**
30      * The wrappered object
31      */

32     private ObjectReference fObject;
33     
34     /**
35      * Constructs a variable representing 'this' in a stack frame.
36      */

37     public JDIThisVariable(JDIDebugTarget target, ObjectReference object) {
38         super(target);
39         fObject= object;
40     }
41
42     /**
43      * Returns this variable's current Value.
44      */

45     protected Value retrieveValue() {
46         return fObject;
47     }
48
49     /**
50      * @see IVariable#getName()
51      */

52     public String JavaDoc getName() {
53         return "this"; //$NON-NLS-1$
54
}
55     
56     /**
57      * @see IJavaVariable#getSignature()
58      */

59     public String JavaDoc getSignature() throws DebugException {
60         try {
61             return retrieveValue().type().signature();
62         } catch (RuntimeException JavaDoc e) {
63             targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThisVariableexception_retrieving_type_signature, new String JavaDoc[] {e.toString()}), e);
64             // execution will not reach this line, as
65
// #targetRequestFailed will thrown an exception
66
return null;
67         }
68     }
69
70     /* (non-Javadoc)
71      * @see org.eclipse.jdt.debug.core.IJavaVariable#getGenericSignature()
72      */

73     public String JavaDoc getGenericSignature() throws DebugException {
74         return getSignature();
75     }
76
77     /**
78      * @see IVariable#getReferenceTypeName()
79      */

80     public String JavaDoc getReferenceTypeName() throws DebugException {
81         try {
82             return getValue().getReferenceTypeName();
83         } catch (RuntimeException JavaDoc e) {
84             targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThisVariableexception_retrieving_reference_type_name, new String JavaDoc[] {e.toString()}), e);
85             // execution will not reach this line, as
86
// #targetRequestFailed will thrown an exception
87
return null;
88         }
89     }
90     
91     /**
92      * @see JDIVariable#getUnderlyingType()
93      */

94     protected Type getUnderlyingType() throws DebugException {
95         try {
96             return retrieveValue().type();
97         } catch (RuntimeException JavaDoc e) {
98             targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIThisVariable_exception_while_retrieving_type_this, new String JavaDoc[]{e.toString()}), e);
99         }
100         // this line will not be exceucted as an exception
101
// will be throw in type retrieval fails
102
return null;
103     }
104     
105     /**
106      * @see org.eclipse.jdt.debug.core.IJavaModifiers#isPrivate()
107      */

108     public boolean isPrivate() throws DebugException {
109         try {
110             return ((ReferenceType)getUnderlyingType()).isPrivate();
111         } catch (RuntimeException JavaDoc e) {
112             targetRequestFailed(JDIDebugModelMessages.JDIThisVariable_Exception_occurred_while_retrieving_modifiers__1, e);
113         }
114         // this line will not be exceucted as an exception
115
// will be throw
116
return false;
117     }
118
119     /**
120      * @see org.eclipse.jdt.debug.core.IJavaModifiers#isProtected()
121      */

122     public boolean isProtected() throws DebugException {
123         try {
124             return ((ReferenceType)getUnderlyingType()).isProtected();
125         } catch (RuntimeException JavaDoc e) {
126             targetRequestFailed(JDIDebugModelMessages.JDIThisVariable_Exception_occurred_while_retrieving_modifiers__1, e);
127         }
128         // this line will not be exceucted as an exception
129
// will be throw
130
return false;
131     }
132
133     /**
134      * @see org.eclipse.jdt.debug.core.IJavaModifiers#isPublic()
135      */

136     public boolean isPublic() throws DebugException {
137         try {
138             return ((ReferenceType)getUnderlyingType()).isPublic();
139         } catch (RuntimeException JavaDoc e) {
140             targetRequestFailed(JDIDebugModelMessages.JDIThisVariable_Exception_occurred_while_retrieving_modifiers__1, e);
141         }
142         // this line will not be exceucted as an exception
143
// will be throw
144
return false;
145     }
146
147     /**
148      * @see java.lang.Object#equals(Object)
149      */

150     public boolean equals(Object JavaDoc o) {
151         if (o instanceof JDIThisVariable) {
152             return ((JDIThisVariable)o).fObject.equals(fObject);
153         }
154         return false;
155     }
156
157     /**
158      * @see java.lang.Object#hashCode()
159      */

160     public int hashCode() {
161         return fObject.hashCode();
162     }
163
164 }
165
Popular Tags