KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > variables > IndexedVariablePartition


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.debug.internal.ui.views.variables;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.PlatformObject;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.core.ILaunch;
18 import org.eclipse.debug.core.model.IDebugElement;
19 import org.eclipse.debug.core.model.IDebugTarget;
20 import org.eclipse.debug.core.model.IIndexedValue;
21 import org.eclipse.debug.core.model.IValue;
22 import org.eclipse.debug.core.model.IVariable;
23 import org.eclipse.debug.ui.IDebugUIConstants;
24
25 /**
26  * A variable containing a subset/range of values from an indexed value
27  * (<code>IIndexedValue</code>).
28  */

29 public class IndexedVariablePartition extends PlatformObject implements IVariable {
30     
31     // the starting offset of this partition, into the associated collection
32
private int fOffset;
33     
34     // the length of this partition
35
private int fLength;
36     
37     // the root variable or expression containing the indexed value
38
private IDebugElement fOriginalVariable;
39
40     // the indexed value
41
private IIndexedValue fOriginalValue;
42     
43     // sub-range of values
44
private IIndexedValue fValuePartition;
45     
46     private String JavaDoc fName = null;
47     
48     /**
49      * Creates a partition for an indexed value.
50      *
51      * @param variable variable or expression containing the indexed value
52      * @param value indexed value
53      * @param offset beginning offset of this partition (into the value)
54      * @param length the length of this partition
55      */

56     public IndexedVariablePartition(IDebugElement variable, IIndexedValue value, int offset, int length) {
57         fOriginalVariable = variable;
58         fOriginalValue = value;
59         fOffset = offset;
60         fLength = length;
61         fValuePartition = new IndexedValuePartition(value, offset, length);
62     }
63     
64     /* (non-Javadoc)
65      * @see org.eclipse.debug.core.model.IVariable#getValue()
66      */

67     public IValue getValue() {
68         return fValuePartition;
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.debug.core.model.IVariable#getName()
73      */

74     public String JavaDoc getName() {
75         if (fName == null) {
76             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
77             buf.append("["); //$NON-NLS-1$
78
buf.append(fOffset);
79             buf.append("..."); //$NON-NLS-1$
80
buf.append(fOffset + fLength - 1);
81             buf.append("]"); //$NON-NLS-1$
82
fName = buf.toString();
83         }
84         return fName;
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
89      */

90     public String JavaDoc getReferenceTypeName() throws DebugException {
91         if (fOriginalVariable instanceof IVariable) {
92             IVariable variable = (IVariable) fOriginalVariable;
93             return variable.getReferenceTypeName();
94         }
95         return ""; //$NON-NLS-1$
96
}
97
98     /* (non-Javadoc)
99      * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
100      */

101     public boolean hasValueChanged() {
102         return false;
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
107      */

108     public String JavaDoc getModelIdentifier() {
109         return fOriginalValue.getModelIdentifier();
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
114      */

115     public IDebugTarget getDebugTarget() {
116         return fOriginalValue.getDebugTarget();
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
121      */

122     public ILaunch getLaunch() {
123         return fOriginalValue.getLaunch();
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
128      */

129     public void setValue(String JavaDoc expression) throws DebugException {
130         throw new DebugException(new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, VariablesViewMessages.IndexedVariablePartition_4, null));
131     }
132
133     /* (non-Javadoc)
134      * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
135      */

136     public void setValue(IValue value) throws DebugException {
137         throw new DebugException(new Status(IStatus.ERROR, IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.INTERNAL_ERROR, VariablesViewMessages.IndexedVariablePartition_4, null));
138     }
139
140     /* (non-Javadoc)
141      * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
142      */

143     public boolean supportsValueModification() {
144         return false;
145     }
146
147     /* (non-Javadoc)
148      * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
149      */

150     public boolean verifyValue(String JavaDoc expression) {
151         return false;
152     }
153
154     /* (non-Javadoc)
155      * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
156      */

157     public boolean verifyValue(IValue value) {
158         return false;
159     }
160
161     /* (non-Javadoc)
162      * @see java.lang.Object#equals(java.lang.Object)
163      */

164     public boolean equals(Object JavaDoc obj) {
165         if (obj instanceof IndexedVariablePartition) {
166             IndexedVariablePartition partition = (IndexedVariablePartition)obj;
167             return fOriginalVariable.equals(partition.fOriginalVariable) &&
168                 fOffset == partition.fOffset && fLength == partition.fLength;
169         }
170         return false;
171     }
172
173     /* (non-Javadoc)
174      * @see java.lang.Object#hashCode()
175      */

176     public int hashCode() {
177         return fOriginalVariable.hashCode() + fOffset;
178     }
179
180 }
181
Popular Tags