KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > eval > EvaluationResult


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.eval;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.debug.core.DebugException;
19 import org.eclipse.jdt.core.dom.Message;
20 import org.eclipse.jdt.debug.core.IJavaThread;
21 import org.eclipse.jdt.debug.core.IJavaValue;
22 import org.eclipse.jdt.debug.eval.IEvaluationEngine;
23 import org.eclipse.jdt.debug.eval.IEvaluationResult;
24  
25 /**
26  * The result of an evaluation.
27  *
28  * @see org.eclipse.jdt.debug.eval.IEvaluationResult
29  */

30 public class EvaluationResult implements IEvaluationResult {
31     
32     /**
33      * The result of an evaluation, possibly <code>null</code>
34      */

35     private IJavaValue fValue;
36     
37     /**
38      * Thread in which the associated evaluation was
39      * executed.
40      */

41     private IJavaThread fThread;
42     
43     /**
44      * Evaluation engine that created this result
45      */

46     private IEvaluationEngine fEngine;
47     
48     /**
49      * Source that was evaluated.
50      */

51     private String JavaDoc fSnippet;
52     
53     /**
54      * Exception that occurred during evaluation,
55      * or <code>null</code> if none.
56      */

57     private DebugException fException;
58     
59     /**
60      * List of <code>String</code>s describing compilation problems.
61      */

62     private List JavaDoc fErrors;
63
64     /**
65      * Constructs a new evaluation result for the given
66      * engine, thread, and code snippet.
67      */

68     public EvaluationResult(IEvaluationEngine engine, String JavaDoc snippet, IJavaThread thread) {
69         setEvaluationEngine(engine);
70         setThread(thread);
71         setSnippet(snippet);
72         fErrors= new ArrayList JavaDoc();
73     }
74
75     /**
76      * @see IEvaluationResult#getValue()
77      */

78     public IJavaValue getValue() {
79         return fValue;
80     }
81     
82     /**
83      * Sets the result of an evaluation, possibly
84      * <code>null</code>.
85      *
86      * @param value result of an evaluation, possibly
87      * <code>null</code>
88      */

89     public void setValue(IJavaValue value) {
90         fValue = value;
91     }
92
93     /**
94      * @see IEvaluationResult#hasProblems()
95      */

96     public boolean hasErrors() {
97         return getErrors().length > 0 || getException() != null;
98     }
99
100     /**
101      * @see IEvaluationResult#getProblems()
102      * @deprecated
103      */

104     public Message[] getErrors() {
105         Message[] messages= new Message[fErrors.size()];
106         int i= 0;
107         for (Iterator JavaDoc iter= fErrors.iterator(); iter.hasNext();) {
108             messages[i++]= new Message((String JavaDoc) iter.next(), -1);
109         }
110         return messages;
111     }
112     
113     /**
114      * @see org.eclipse.jdt.debug.eval.IEvaluationResult#getErrorMessages()
115      */

116     public String JavaDoc[] getErrorMessages() {
117         return (String JavaDoc[])fErrors.toArray(new String JavaDoc[fErrors.size()]);
118     }
119     
120     /**
121      * @see IEvaluationResult#getSnippet()
122      */

123     public String JavaDoc getSnippet() {
124         return fSnippet;
125     }
126     
127     /**
128      * Sets the code snippet that was evaluated.
129      *
130      * @param snippet the source code that was evaluated
131      */

132     private void setSnippet(String JavaDoc snippet) {
133         fSnippet = snippet;
134     }
135
136     /**
137      * @see IEvaluationResult#getException()
138      */

139     public DebugException getException() {
140         return fException;
141     }
142     
143     /**
144      * Sets an exception that occurred while attempting
145      * the associated evaluation.
146      *
147      * @param e exception
148      */

149     public void setException(DebugException e) {
150         fException = e;
151     }
152
153     /**
154      * @see IEvaluationResult#getThread()
155      */

156     public IJavaThread getThread() {
157         return fThread;
158     }
159     
160     /**
161      * Sets the thread this result was generated
162      * from.
163      *
164      * @param thread thread in which the associated
165      * evaluation was executed
166      */

167     private void setThread(IJavaThread thread) {
168         fThread= thread;
169     }
170
171     /**
172      * @see IEvaluationResult#getEvaluationEngine()
173      */

174     public IEvaluationEngine getEvaluationEngine() {
175         return fEngine;
176     }
177     
178     /**
179      * Sets the evaluation that created this result.
180      *
181      * @param engine the evaluation that created this result
182      */

183     private void setEvaluationEngine(IEvaluationEngine engine) {
184         fEngine = engine;
185     }
186     
187     /**
188      * Adds the given message to the list of error messages.
189      */

190     public void addError(String JavaDoc message) {
191         fErrors.add(message);
192     }
193 }
194
195
Popular Tags