001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.model.debug;
038:
039: /**
040: * Class for keeping track of watched fields and variables.
041: * @version $Id: DebugWatchData.java 4255 2007-08-28 19:17:37Z mgricken $
042: */
043: public class DebugWatchData {
044: /**
045: * String to display if the value is not in scope.
046: */
047: public static final String NO_VALUE = "<not found>";
048:
049: /**
050: * String to display if the type is not in scope.
051: */
052: public static final String NO_TYPE = "";
053:
054: /**
055: * String to display if the type is not loaded.
056: */
057: public static final String NOT_LOADED = "<not loaded>";
058:
059: private String _name;
060: private String _value;
061: private String _type;
062: private boolean _showValue;
063: private boolean _showType;
064: private boolean _changed;
065:
066: /**
067: * Object to keep track of a watched field or variable.
068: * @param name Name of the field or variable to watch
069: */
070: public DebugWatchData(String name) {
071: _name = name;
072: _value = "";
073: _type = "";
074: _showValue = false;
075: _showType = false;
076: _changed = false;
077: }
078:
079: /**
080: * Returns the name of this field or variable
081: */
082: public String getName() {
083: return _name;
084: }
085:
086: /**
087: * Returns the most recently determined value for this field or variable.
088: */
089: public String getValue() {
090: return (_showValue) ? _value : "";
091: }
092:
093: /**
094: * Returns the type of this field or variable in the current context.
095: */
096: public String getType() {
097: return (_showType) ? _type : "";
098: }
099:
100: /**
101: * Sets a new name for this field or variable.
102: * @param name Name of the field or variable
103: */
104: public void setName(String name) {
105: _name = name;
106: }
107:
108: /**
109: * Sets the most recently determined value for this field or variable.
110: * @param value Value of the field or variable
111: */
112: public void setValue(Object value) {
113: _showValue = true;
114: String valString = String.valueOf(value);
115: if (!valString.equals(_value)) {
116: _changed = true;
117: } else {
118: _changed = false;
119: }
120: _value = valString;
121: }
122:
123: /**
124: * Hides the value for this watch (when no thread is suspended).
125: */
126: public void hideValueAndType() {
127: _showValue = false;
128: _showType = false;
129: _changed = false;
130: }
131:
132: /**
133: * Called to indicate that this watch has no value in the current scope.
134: */
135: public void setNoValue() {
136: _showValue = true;
137: _value = NO_VALUE;
138: _changed = false;
139: }
140:
141: /**
142: * Sets the most recently determined type of this field or variable.
143: * @param type Type of the field or variable
144: */
145: public void setType(String type) {
146: _showType = true;
147: _type = type;
148: }
149:
150: /**
151: * Called to indicate that this watch has no type in the current scope.
152: */
153: public void setNoType() {
154: _showType = true;
155: _type = NO_TYPE;
156: }
157:
158: /**
159: * Called to indicate that this watch's type has not been loaded.
160: */
161: public void setTypeNotLoaded() {
162: _showType = true;
163: _type = NOT_LOADED;
164: }
165:
166: /**
167: * Returns whether this value has changed since the last call to setValue.
168: */
169: public boolean isChanged() {
170: return _changed;
171: }
172:
173: /**
174: * Returns a legible representation of the type, name, and value.
175: */
176: public String toString() {
177: return _type + " " + _name + ": " + _value;
178: }
179: }
|