KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > debug > DebugWatchData


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model.debug;
35
36 /**
37  * Class for keeping track of watched fields and variables.
38  * @version $Id: DebugWatchData.java 3553 2006-02-20 21:22:09Z rcartwright $
39  */

40 public class DebugWatchData {
41   /**
42    * String to display if the value is not in scope.
43    */

44   public static final String JavaDoc NO_VALUE = "<not found>";
45
46   /**
47    * String to display if the type is not in scope.
48    */

49   public static final String JavaDoc NO_TYPE = "";
50
51   /**
52    * String to display if the type is not loaded.
53    */

54   public static final String JavaDoc NOT_LOADED = "<not loaded>";
55
56   private String JavaDoc _name;
57   private String JavaDoc _value;
58   private String JavaDoc _type;
59   private boolean _showValue;
60   private boolean _showType;
61   private boolean _changed;
62
63   /**
64    * Object to keep track of a watched field or variable.
65    * @param name Name of the field or variable to watch
66    */

67   public DebugWatchData(String JavaDoc name) {
68     _name = name;
69     _value = "";
70     _type = "";
71     _showValue = false;
72     _showType = false;
73     _changed = false;
74   }
75
76   /**
77    * Returns the name of this field or variable
78    */

79   public String JavaDoc getName() {
80     return _name;
81   }
82
83   /**
84    * Returns the most recently determined value for this field or variable.
85    */

86   public String JavaDoc getValue() {
87     return (_showValue) ? _value : "";
88   }
89
90   /**
91    * Returns the type of this field or variable in the current context.
92    */

93   public String JavaDoc getType() {
94     return (_showType) ? _type : "";
95   }
96
97   /**
98    * Sets a new name for this field or variable.
99    * @param name Name of the field or variable
100    */

101   void setName(String JavaDoc name) {
102     _name = name;
103   }
104
105   /**
106    * Sets the most recently determined value for this field or variable.
107    * @param value Value of the field or variable
108    */

109   void setValue(Object JavaDoc value) {
110     _showValue = true;
111     String JavaDoc valString = String.valueOf(value);
112     if (!valString.equals(_value)) {
113       _changed = true;
114     }
115     else {
116       _changed = false;
117     }
118     _value = valString;
119   }
120
121   /**
122    * Hides the value for this watch (when no thread is suspended).
123    */

124   void hideValueAndType() {
125     _showValue = false;
126     _showType = false;
127     _changed = false;
128   }
129
130   /**
131    * Called to indicate that this watch has no value in the current scope.
132    */

133   void setNoValue() {
134     _showValue = true;
135     _value = NO_VALUE;
136     _changed = false;
137   }
138
139   /**
140    * Sets the most recently determined type of this field or variable.
141    * @param type Type of the field or variable
142    */

143   void setType(String JavaDoc type) {
144     _showType = true;
145     _type = type;
146   }
147
148   /**
149    * Called to indicate that this watch has no type in the current scope.
150    */

151   void setNoType() {
152     _showType = true;
153     _type = NO_TYPE;
154   }
155
156   /**
157    * Called to indicate that this watch's type has not been loaded.
158    */

159   void setTypeNotLoaded() {
160     _showType = true;
161     _type = NOT_LOADED;
162   }
163
164   /**
165    * Returns whether this value has changed since the last call to setValue.
166    */

167   public boolean isChanged() {
168     return _changed;
169   }
170
171   /**
172    * Returns a legible representation of the type, name, and value.
173    */

174   public String JavaDoc toString() {
175     return _type + " " + _name + ": " + _value;
176   }
177 }
178
Popular Tags