Package: VdmEvaluationEngine

VdmEvaluationEngine

nameinstructionbranchcomplexitylinemethod
VdmEvaluationEngine(IVdmThread)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
asyncEvaluate(String, IVdmStackFrame, IVdmEvaluationListener)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
evaluate(String, IVdmStackFrame)
M: 59 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getFromCache(String)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getVdmDebugTarget()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
putToCache(String, IVdmEvaluationResult)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
syncEvaluate(String, IVdmStackFrame)
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.core.model.internal.eval;
23:
24: import org.eclipse.core.runtime.IProgressMonitor;
25: import org.eclipse.core.runtime.IStatus;
26: import org.eclipse.core.runtime.Status;
27: import org.eclipse.core.runtime.jobs.Job;
28: import org.eclipse.osgi.util.NLS;
29: import org.overture.ide.debug.core.dbgp.IDbgpProperty;
30: import org.overture.ide.debug.core.dbgp.IDbgpSession;
31: import org.overture.ide.debug.core.dbgp.commands.IDbgpExtendedCommands;
32: import org.overture.ide.debug.core.model.IVdmDebugTarget;
33: import org.overture.ide.debug.core.model.IVdmStackFrame;
34: import org.overture.ide.debug.core.model.IVdmThread;
35: import org.overture.ide.debug.core.model.IVdmValue;
36: import org.overture.ide.debug.core.model.eval.IVdmEvaluationEngine;
37: import org.overture.ide.debug.core.model.eval.IVdmEvaluationListener;
38: import org.overture.ide.debug.core.model.eval.IVdmEvaluationResult;
39: import org.overture.ide.debug.core.model.internal.VdmDebugTarget;
40: import org.overture.ide.debug.core.model.internal.VdmValue;
41:
42: public class VdmEvaluationEngine implements IVdmEvaluationEngine
43: {
44:         private final IVdmThread thread;
45:
46:         // private int count;
47:         private final/* WeakHashMap */Object cache;
48:
49:         protected void putToCache(String snippet, IVdmEvaluationResult result)
50:         {
51:                 // if (result != null) {
52:                 // cache.put(snippet, result);
53:                 // }
54:         }
55:
56:         protected IVdmEvaluationResult getFromCache(String snippet)
57:         {
58:                 return null;
59:                 // int newCount = thread.getModificationsCount();
60:                 // if (count != newCount) {
61:                 // cache.clear();
62:                 // count = newCount;
63:                 // return null;
64:                 // }
65:                 //
66:                 // return (IVdmEvaluationResult) cache.get(snippet);
67:         }
68:
69:         private IVdmEvaluationResult evaluate(String snippet, IVdmStackFrame frame)
70:         {
71:                 IVdmEvaluationResult result = null;
72:                 try
73:                 {
74:                         final IDbgpSession session = thread.getDbgpSession();
75:
76:                         final IDbgpExtendedCommands extended = session.getExtendedCommands();
77:
78:                         final IDbgpProperty property = extended.evaluate(snippet);
79:
80:•                        if (property != null)
81:                         {
82:                                 IVdmValue value = VdmValue.createValue(frame, property);
83:                                 result = new VdmEvaluationResult(thread, snippet, value);
84:                         } else
85:                         {
86:                                 result = new FailedVdmEvaluationResult(thread, snippet, new String[] { "VdmEvaluationEngine_cantEvaluate" });
87:                         }
88:
89:                 } catch (Exception e)
90:                 {
91:                         // TODO: improve
92:                         result = new FailedVdmEvaluationResult(thread, snippet, new String[] { e.getMessage() });
93:                 }
94:
95:                 return result;
96:         }
97:
98:         public VdmEvaluationEngine(IVdmThread thread)
99:         {
100:                 this.thread = thread;
101:                 // this.count = thread.getModificationsCount();
102:                 this.cache = new Object();// new WeakHashMap();
103:         }
104:
105:         public IVdmDebugTarget getVdmDebugTarget()
106:         {
107:                 return (VdmDebugTarget) thread.getDebugTarget();
108:         }
109:
110:         public IVdmEvaluationResult syncEvaluate(String snippet,
111:                         IVdmStackFrame frame)
112:         {
113:                 snippet = snippet.trim();
114:                 synchronized (cache)
115:                 {
116:                         IVdmEvaluationResult result = getFromCache(snippet);
117:
118:•                        if (result == null)
119:                         {
120:                                 result = evaluate(snippet, frame);
121:                         }
122:
123:                         putToCache(snippet, result);
124:
125:                         return result;
126:                 }
127:         }
128:
129:         public void asyncEvaluate(final String snippet, final IVdmStackFrame frame,
130:                         final IVdmEvaluationListener listener)
131:         {
132:                 Job job = new Job(NLS.bind("VdmEvaluationEngine_evaluationOf", snippet))
133:                 {
134:                         protected IStatus run(IProgressMonitor monitor)
135:                         {
136:                                 if (getVdmDebugTarget().isTerminated())
137:                                 {
138:                                         listener.evaluationComplete(new NoEvaluationResult(snippet, thread));
139:                                 } else
140:                                 {
141:                                         listener.evaluationComplete(syncEvaluate(snippet, frame));
142:                                 }
143:                                 return Status.OK_STATUS;
144:                         }
145:                 };
146:
147:                 job.setSystem(true);
148:                 job.setUser(false);
149:                 job.schedule();
150:         }
151:
152:         public void dispose()
153:         {
154:                 // TODO Auto-generated method stub
155:         }
156: }