001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.debug.eval;
011:
012: import java.util.ArrayList;
013: import java.util.Iterator;
014: import java.util.List;
015:
016: import org.eclipse.debug.core.DebugException;
017: import org.eclipse.jdt.core.dom.Message;
018: import org.eclipse.jdt.debug.core.IJavaThread;
019: import org.eclipse.jdt.debug.core.IJavaValue;
020: import org.eclipse.jdt.debug.eval.IEvaluationEngine;
021: import org.eclipse.jdt.debug.eval.IEvaluationResult;
022:
023: /**
024: * The result of an evaluation.
025: *
026: * @see org.eclipse.jdt.debug.eval.IEvaluationResult
027: */
028: public class EvaluationResult implements IEvaluationResult {
029:
030: /**
031: * The result of an evaluation, possibly <code>null</code>
032: */
033: private IJavaValue fValue;
034:
035: /**
036: * Thread in which the associated evaluation was
037: * executed.
038: */
039: private IJavaThread fThread;
040:
041: /**
042: * Evaluation engine that created this result
043: */
044: private IEvaluationEngine fEngine;
045:
046: /**
047: * Source that was evaluated.
048: */
049: private String fSnippet;
050:
051: /**
052: * Exception that occurred during evaluation,
053: * or <code>null</code> if none.
054: */
055: private DebugException fException;
056:
057: /**
058: * List of <code>String</code>s describing compilation problems.
059: */
060: private List fErrors;
061:
062: /**
063: * Constructs a new evaluation result for the given
064: * engine, thread, and code snippet.
065: */
066: public EvaluationResult(IEvaluationEngine engine, String snippet,
067: IJavaThread thread) {
068: setEvaluationEngine(engine);
069: setThread(thread);
070: setSnippet(snippet);
071: fErrors = new ArrayList();
072: }
073:
074: /**
075: * @see IEvaluationResult#getValue()
076: */
077: public IJavaValue getValue() {
078: return fValue;
079: }
080:
081: /**
082: * Sets the result of an evaluation, possibly
083: * <code>null</code>.
084: *
085: * @param value result of an evaluation, possibly
086: * <code>null</code>
087: */
088: public void setValue(IJavaValue value) {
089: fValue = value;
090: }
091:
092: /**
093: * @see IEvaluationResult#hasProblems()
094: */
095: public boolean hasErrors() {
096: return getErrors().length > 0 || getException() != null;
097: }
098:
099: /**
100: * @see IEvaluationResult#getProblems()
101: * @deprecated
102: */
103: public Message[] getErrors() {
104: Message[] messages = new Message[fErrors.size()];
105: int i = 0;
106: for (Iterator iter = fErrors.iterator(); iter.hasNext();) {
107: messages[i++] = new Message((String) iter.next(), -1);
108: }
109: return messages;
110: }
111:
112: /**
113: * @see org.eclipse.jdt.debug.eval.IEvaluationResult#getErrorMessages()
114: */
115: public String[] getErrorMessages() {
116: return (String[]) fErrors.toArray(new String[fErrors.size()]);
117: }
118:
119: /**
120: * @see IEvaluationResult#getSnippet()
121: */
122: public String getSnippet() {
123: return fSnippet;
124: }
125:
126: /**
127: * Sets the code snippet that was evaluated.
128: *
129: * @param snippet the source code that was evaluated
130: */
131: private void setSnippet(String snippet) {
132: fSnippet = snippet;
133: }
134:
135: /**
136: * @see IEvaluationResult#getException()
137: */
138: public DebugException getException() {
139: return fException;
140: }
141:
142: /**
143: * Sets an exception that occurred while attempting
144: * the associated evaluation.
145: *
146: * @param e exception
147: */
148: public void setException(DebugException e) {
149: fException = e;
150: }
151:
152: /**
153: * @see IEvaluationResult#getThread()
154: */
155: public IJavaThread getThread() {
156: return fThread;
157: }
158:
159: /**
160: * Sets the thread this result was generated
161: * from.
162: *
163: * @param thread thread in which the associated
164: * evaluation was executed
165: */
166: private void setThread(IJavaThread thread) {
167: fThread = thread;
168: }
169:
170: /**
171: * @see IEvaluationResult#getEvaluationEngine()
172: */
173: public IEvaluationEngine getEvaluationEngine() {
174: return fEngine;
175: }
176:
177: /**
178: * Sets the evaluation that created this result.
179: *
180: * @param engine the evaluation that created this result
181: */
182: private void setEvaluationEngine(IEvaluationEngine engine) {
183: fEngine = engine;
184: }
185:
186: /**
187: * Adds the given message to the list of error messages.
188: */
189: public void addError(String message) {
190: fErrors.add(message);
191: }
192: }
|