Package: VdmModel

VdmModel

nameinstructionbranchcomplexitylinemethod
VdmModel()
M: 22 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
addVdmSourceUnit(IVdmSourceUnit)
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%
clean()
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
exists()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
fireModelCheckedEvent()
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getAdapter(Class)
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%
getAttribute(String, Class)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getCheckedTime()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getClassList()
M: 39 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getElementType()
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%
getModuleList()
M: 42 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getRootElementList()
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getSourceUnits()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getVdmSourceUnit(IFile)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getWorkingCopy()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
hasAttribute(String)
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%
hasClassList()
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
hasFile(File)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
hasFile(IVdmSourceUnit)
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%
hasModuleList()
M: 18 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
hasWorkingCopies()
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isParseCorrect()
M: 22 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
isTypeChecked()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isTypeCorrect()
M: 10 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
refresh(boolean, IProgressMonitor)
M: 56 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
remove(IVdmSourceUnit)
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%
setAttribute(String, Object)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setIsTypeChecked(boolean)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setTypeCheckedStatus(boolean)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.core
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.core.ast;
23:
24: import java.io.File;
25: import java.io.IOException;
26: import java.util.Date;
27: import java.util.List;
28: import java.util.Map;
29: import java.util.TreeMap;
30: import java.util.Vector;
31:
32: import org.eclipse.core.resources.IFile;
33: import org.eclipse.core.runtime.Assert;
34: import org.eclipse.core.runtime.CoreException;
35: import org.eclipse.core.runtime.IProgressMonitor;
36: import org.eclipse.core.runtime.Platform;
37: import org.overture.ast.definitions.SClassDefinition;
38: import org.overture.ast.modules.AModuleModules;
39: import org.overture.ast.node.INode;
40: import org.overture.ast.util.definitions.ClassList;
41: import org.overture.ast.util.modules.ModuleList;
42: import org.overture.ide.core.ElementChangedEvent;
43: import org.overture.ide.core.IVdmElement;
44: import org.overture.ide.core.IVdmElementDelta;
45: import org.overture.ide.core.IVdmModel;
46: import org.overture.ide.core.VdmCore;
47: import org.overture.ide.core.VdmElementDelta;
48: import org.overture.ide.core.parser.SourceParserManager;
49: import org.overture.ide.core.resources.IVdmSourceUnit;
50:
51: public class VdmModel implements IVdmModel
52: {
53:         // static int count = 0;
54:         // int id;
55:         protected boolean isTypeChecked = false;
56:         protected boolean isTypeCorrect = false;
57:         protected int workingCopyNotCommitedCount = 0;
58:
59:         protected Date checkedTime;
60:
61:         protected List<IVdmSourceUnit> vdmSourceUnits = new Vector<IVdmSourceUnit>();
62:
63:         protected Map<String, Object> state = new TreeMap<String, Object>();
64:
65:         public VdmModel()
66:         {
67:                 // count++;
68:                 // id = count;
69:         }
70:
71:         /*
72:          * (non-Javadoc)
73:          * @see org.overture.ide.core.ast.IVdmElement#getRootElementList()
74:          */
75:         public synchronized List<INode> getRootElementList()
76:         {
77:                 List<INode> list = new Vector<INode>();
78:•                for (IVdmSourceUnit unit : vdmSourceUnits)
79:                 {
80:                         list.addAll(unit.getParseList());
81:                 }
82:                 return list;
83:         }
84:
85:         /*
86:          * (non-Javadoc)
87:          * @see org.overture.ide.core.ast.IVdmElement#getCheckedTime()
88:          */
89:         public synchronized Date getCheckedTime()
90:         {
91:                 return checkedTime;
92:         }
93:
94:         /*
95:          * (non-Javadoc)
96:          * @see org.overture.ide.core.ast.IVdmElement#setChecked(boolean)
97:          */
98:         public synchronized void setTypeCheckedStatus(boolean checked)
99:         {
100:                 this.isTypeChecked = true;
101:                 this.isTypeCorrect = checked;
102:                 this.checkedTime = new Date();
103:•                if (checked)
104:                 {
105:                         fireModelCheckedEvent();
106:                 }
107:         }
108:
109:         protected void fireModelCheckedEvent()
110:         {
111:                 VdmCore.getDeltaProcessor().fire(this, new ElementChangedEvent(new VdmElementDelta(this, IVdmElementDelta.F_TYPE_CHECKED), ElementChangedEvent.DeltaType.POST_RECONCILE));
112:         }
113:
114:         /*
115:          * (non-Javadoc)
116:          * @see org.overture.ide.core.ast.IVdmElement#isChecked()
117:          */
118:         public synchronized boolean isTypeCorrect()
119:         {
120:•                return isTypeCorrect && isTypeChecked;
121:         }
122:
123:         /*
124:          * (non-Javadoc)
125:          * @see org.overture.ide.core.ast.IVdmElement#hasFile(java.io.File)
126:          */
127:         @SuppressWarnings("unused")
128:         public synchronized boolean hasFile(File file)
129:         {
130:                 Assert.isNotNull(null);
131:                 return false;
132:         }
133:
134:         public synchronized boolean hasFile(IVdmSourceUnit file)
135:         {
136:                 return this.vdmSourceUnits.contains(file);
137:
138:         }
139:
140:         /*
141:          * (non-Javadoc)
142:          * @see org.overture.ide.core.ast.IVdmElement#getModuleList()
143:          */
144:         public synchronized ModuleList getModuleList() throws NotAllowedException
145:         {
146:                 ModuleList modules = new ModuleList();
147:•                for (Object definition : getRootElementList())
148:                 {
149:•                        if (definition instanceof AModuleModules)
150:                                 modules.add((AModuleModules) definition);
151:                         else
152:                                 throw new NotAllowedException("Other definition than Module is found: "
153:                                                 + definition.getClass().getName());
154:                 }
155:
156:                 modules.combineDefaults();
157:
158:                 return modules;
159:         }
160:
161:         /*
162:          * (non-Javadoc)
163:          * @see org.overture.ide.core.ast.IVdmElement#getClassList()
164:          */
165:         public synchronized ClassList getClassList() throws NotAllowedException
166:         {
167:                 ClassList classes = new ClassList();
168:•                for (Object definition : getRootElementList())
169:                 {
170:•                        if (definition instanceof SClassDefinition)
171:                                 classes.add((SClassDefinition) definition);
172:                         else
173:                                 throw new NotAllowedException("Other definition than ClassDefinition is found: "
174:                                                 + definition.getClass().getName());
175:                 }
176:                 return classes;
177:         }
178:
179:         /*
180:          * (non-Javadoc)
181:          * @see org.overture.ide.core.ast.IVdmElement#hasClassList()
182:          */
183:         public synchronized boolean hasClassList()
184:         {
185:•                for (Object definition : getRootElementList())
186:                 {
187:•                        if (definition instanceof SClassDefinition)
188:                                 return true;
189:                 }
190:                 return false;
191:         }
192:
193:         /*
194:          * (non-Javadoc)
195:          * @see org.overture.ide.core.ast.IVdmElement#hasModuleList()
196:          */
197:         public synchronized boolean hasModuleList()
198:         {
199:•                for (Object definition : getRootElementList())
200:                 {
201:•                        if (definition instanceof AModuleModules)
202:                                 return true;
203:                 }
204:                 return false;
205:         }
206:
207:         /*
208:          * (non-Javadoc)
209:          * @see org.overture.ide.core.ast.IVdmElement#isParseCorrect()
210:          */
211:         public synchronized boolean isParseCorrect()
212:         {
213:                 boolean isParseCorrect = true;
214:•                for (IVdmSourceUnit source : vdmSourceUnits)
215:                 {
216:•                        if (source.hasParseErrors())
217:                         {
218:                                 isParseCorrect = false;
219:                                 break;
220:                         }
221:                 }
222:                 return isParseCorrect;
223:         }
224:
225:         public boolean exists()
226:         {
227:•                return getRootElementList().size() > 0;
228:         }
229:
230:         public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter)
231:         {
232:                 return Platform.getAdapterManager().getAdapter(this, adapter);
233:         }
234:
235:         public synchronized void addVdmSourceUnit(IVdmSourceUnit unit)
236:         {
237:                 this.isTypeChecked = false;
238:                 this.isTypeCorrect = false;
239:•                if (!vdmSourceUnits.contains(unit))
240:                 {
241:                         this.vdmSourceUnits.add(unit);
242:                 } else
243:                 {
244:                         System.err.println("Add error: " + unit);
245:                 }
246:
247:         }
248:
249:         public synchronized void remove(IVdmSourceUnit unit)
250:         {
251:                 this.isTypeChecked = false;
252:                 this.isTypeCorrect = false;
253:•                if (vdmSourceUnits.contains(unit))
254:                 {
255:                         this.vdmSourceUnits.remove(unit);
256:                 } else
257:                 {
258:                         System.err.println("Remove error: " + unit);
259:                 }
260:         }
261:
262:         public synchronized IVdmSourceUnit getVdmSourceUnit(IFile file)
263:         {
264:•                for (IVdmSourceUnit unit : vdmSourceUnits)
265:                 {
266:•                        if (unit.getFile().equals(file))
267:                                 return unit;
268:                 }
269:                 return null;
270:         }
271:
272:         public int getElementType()
273:         {
274:                 return IVdmElement.VDM_MODEL;
275:         }
276:
277:         public synchronized void clean()
278:         {
279:•                for (IVdmSourceUnit unit : vdmSourceUnits)
280:                 {
281:                         unit.clean();
282:                 }
283:                 // this.parseCurrectTable.clear();
284:                 this.isTypeChecked = false;
285:                 this.isTypeCorrect = false;
286:
287:         }
288:
289:         public void refresh(boolean completeRefresh, IProgressMonitor monitor)
290:         {
291:                 int worked = 1;
292:•                if (monitor != null)
293:                 {
294:                         monitor.beginTask("Refreshing model", vdmSourceUnits.size());
295:                 }
296:•                for (IVdmSourceUnit source : vdmSourceUnits)
297:                 {
298:•                        if (!completeRefresh && source.getParseList().size() > 0)
299:                         {
300:                                 continue;
301:                         }
302:
303:                         try
304:                         {
305:                                 SourceParserManager.parseFile(source);
306:                         } catch (CoreException e)
307:                         {
308:•                                if (VdmCore.DEBUG)
309:                                 {
310:                                         VdmCore.log("Error in VdmModel refresh", e);
311:                                 }
312:                         } catch (IOException e)
313:                         {
314:•                                if (VdmCore.DEBUG)
315:                                 {
316:                                         VdmCore.log("Error in VdmModel refresh", e);
317:                                 }
318:                         }
319:•                        if (monitor != null)
320:                         {
321:                                 monitor.worked(++worked);
322:                         }
323:                 }
324:
325:•                if (monitor != null)
326:                 {
327:                         monitor.done();
328:                 }
329:
330:         }
331:
332:         public List<IVdmSourceUnit> getSourceUnits()
333:         {
334:                 return this.vdmSourceUnits;
335:         }
336:
337:         public synchronized VdmModelWorkingCopy getWorkingCopy()
338:         {
339:                 workingCopyNotCommitedCount++;
340:                 return new VdmModelWorkingCopy(this);
341:         }
342:
343:         public boolean isTypeChecked()
344:         {
345:                 return this.isTypeChecked;
346:         }
347:
348:         public void setIsTypeChecked(boolean checked)
349:         {
350:                 this.isTypeChecked = checked;
351:         }
352:
353:         public synchronized boolean hasWorkingCopies()
354:         {
355:•                return workingCopyNotCommitedCount > 0;
356:         }
357:
358:         public boolean hasAttribute(String attributeName)
359:         {
360:                 return state.containsKey(attributeName);
361:         }
362:
363:         
364:         @SuppressWarnings("unchecked")
365:         public <K> K getAttribute(String key, Class<K> valClass)
366:         {
367:                 Object val = state.get(key);
368:•                if (val == null){
369:                         return null;
370:                 }
371:                 return (K) val;
372:
373:         }
374:
375:         public <K> void setAttribute(String attributeName, K value)
376:         {
377:                 state.put(attributeName, value);
378:         }
379:
380: }