KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 java.util.Collections JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.debug.core.DebugException;
18 import org.eclipse.jdt.core.Signature;
19 import org.eclipse.jdt.debug.core.IJavaFieldVariable;
20 import org.eclipse.jdt.debug.core.IJavaObject;
21 import org.eclipse.jdt.debug.core.IJavaThread;
22 import org.eclipse.jdt.debug.core.IJavaType;
23 import org.eclipse.jdt.debug.core.IJavaValue;
24
25 import com.ibm.icu.text.MessageFormat;
26
27 /**
28  * Represents a value of "null"
29  */

30 public class JDINullValue extends JDIObjectValue {
31     
32     
33     /**
34      * Constructor
35      * @param target
36      */

37     public JDINullValue(JDIDebugTarget target) {
38         super(target, null);
39     }
40
41     /**
42      * @see org.eclipse.jdt.internal.debug.core.model.JDIValue#getVariablesList()
43      */

44     protected List JavaDoc getVariablesList() {
45         return Collections.EMPTY_LIST;
46     }
47     
48     /**
49      * @see IValue#getReferenceTypeName()
50      */

51     public String JavaDoc getReferenceTypeName() {
52         return "null"; //$NON-NLS-1$
53
}
54     
55     /**
56      * @see IValue#getValueString()
57      */

58     public String JavaDoc getValueString() {
59         return "null"; //$NON-NLS-1$
60
}
61
62     /**
63      * @see IJavaValue#getSignature()
64      */

65     public String JavaDoc getSignature() {
66         return null;
67     }
68
69     /**
70      * @see IJavaValue#getArrayLength()
71      */

72     public int getArrayLength() {
73         return -1;
74     }
75         
76     /**
77      * @see IJavaValue#getJavaType()
78      */

79     public IJavaType getJavaType() {
80         return null;
81     }
82     
83     /**
84      * @see Object#equals(Object)
85      */

86     public boolean equals(Object JavaDoc obj) {
87         return obj instanceof JDINullValue;
88     }
89
90     /**
91      * @see Object#hashCode()
92      */

93     public int hashCode() {
94         return getClass().hashCode();
95     }
96
97     /**
98      * @see java.lang.Object#toString()
99      */

100     public String JavaDoc toString() {
101         return "null"; //$NON-NLS-1$
102
}
103
104     /**
105      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#getField(java.lang.String, boolean)
106      */

107     public IJavaFieldVariable getField(String JavaDoc name, boolean superField) {
108         return null;
109     }
110     
111     /**
112      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#getField(java.lang.String, java.lang.String)
113      */

114     public IJavaFieldVariable getField(String JavaDoc name, String JavaDoc typeSignature) {
115         return null;
116     }
117     
118     /**
119      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#getWaitingThreads()
120      */

121     public IJavaThread[] getWaitingThreads() {
122         return null;
123     }
124     
125     /**
126      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#getOwningThread()
127      */

128     public IJavaThread getOwningThread() {
129         return null;
130     }
131     
132     /**
133      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#getReferringObjects(long)
134      */

135     public IJavaObject[] getReferringObjects(long max) {
136         return new IJavaObject[0];
137     }
138     
139     /**
140      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#sendMessage(java.lang.String, java.lang.String, org.eclipse.jdt.debug.core.IJavaValue[], org.eclipse.jdt.debug.core.IJavaThread, boolean)
141      */

142     public IJavaValue sendMessage(String JavaDoc selector, String JavaDoc signature, IJavaValue[] args, IJavaThread thread, boolean superSend) throws DebugException{
143         return npe(selector, signature);
144     }
145     
146     /**
147      * @see org.eclipse.jdt.internal.debug.core.model.JDIObjectValue#sendMessage(java.lang.String, java.lang.String, org.eclipse.jdt.debug.core.IJavaValue[], org.eclipse.jdt.debug.core.IJavaThread, java.lang.String)
148      */

149     public IJavaValue sendMessage(String JavaDoc selector, String JavaDoc signature, IJavaValue[] args, IJavaThread thread, String JavaDoc typeSignature) throws DebugException{
150         return npe(selector, signature);
151     }
152     
153     /**
154      * Creates an artificial NPE for display to the user as an error message
155      * @param selector
156      * @param signature
157      * @return
158      * @throws DebugException
159      */

160     private IJavaValue npe(String JavaDoc selector, String JavaDoc signature) throws DebugException {
161         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
162         buffer.append(selector);
163         String JavaDoc[] parameterTypes = Signature.getParameterTypes(signature);
164         buffer.append('(');
165         for (int i = 0; i < parameterTypes.length; i++) {
166             buffer.append(Signature.getSignatureSimpleName(parameterTypes[i].replace('/', '.')));
167             if (i+1 < parameterTypes.length) {
168                 buffer.append(", "); //$NON-NLS-1$
169
}
170         }
171         buffer.append(')');
172         requestFailed(MessageFormat.format(JDIDebugModelMessages.JDINullValue_0, new String JavaDoc[]{buffer.toString()}), null);
173         return null;
174     }
175 }
176
Popular Tags