Package: SafeBuilder

SafeBuilder

nameinstructionbranchcomplexitylinemethod
SafeBuilder(IVdmProject, IProgressMonitor)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
clearProblemMarkers(IProject)
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%
run()
M: 53 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 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.builder;
23:
24: import org.eclipse.core.resources.IMarker;
25: import org.eclipse.core.resources.IProject;
26: import org.eclipse.core.resources.IResource;
27: import org.eclipse.core.runtime.CoreException;
28: import org.eclipse.core.runtime.IConfigurationElement;
29: import org.eclipse.core.runtime.IProgressMonitor;
30: import org.eclipse.core.runtime.ISafeRunnable;
31: import org.eclipse.core.runtime.IStatus;
32: import org.eclipse.core.runtime.Platform;
33: import org.eclipse.core.runtime.SafeRunner;
34: import org.overture.ide.core.ICoreConstants;
35: import org.overture.ide.core.IVdmModel;
36: import org.overture.ide.core.VdmCore;
37: import org.overture.ide.core.ast.VdmModelWorkingCopy;
38: import org.overture.ide.core.parser.SourceParserManager;
39: import org.overture.ide.core.resources.IVdmProject;
40:
41: public class SafeBuilder extends Thread
42: {
43:
44:         final IVdmProject currentProject;
45:
46:         final IProgressMonitor monitor;
47:
48:         public SafeBuilder(final IVdmProject currentProject,
49:                         final IProgressMonitor monitor)
50:         {
51:                 this.currentProject = currentProject;
52:
53:                 this.monitor = monitor;
54:                 this.setName("VDM Safe Builder");
55:                 this.setDaemon(true);
56:         }
57:
58:         @Override
59:         public void run()
60:         {
61:                 try
62:                 {
63:                         IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(ICoreConstants.EXTENSION_BUILDER_ID);
64:•                        for (IConfigurationElement e : config)
65:                         {
66:•                                if (currentProject.getVdmNature().equals(e.getAttribute("nature")))
67:                                 {
68:                                         final Object o = e.createExecutableExtension("class");
69:•                                        if (o instanceof AbstractVdmBuilder)
70:                                         {
71:                                                 ISafeRunnable runnable = new ISafeRunnable()
72:                                                 {
73:
74:                                                         public void handleException(Throwable e)
75:                                                         {
76:                                                                 VdmCore.log("SafeBuilder", e);
77:                                                         }
78:
79:                                                         public void run() throws Exception
80:                                                         {
81:                                                                 AbstractVdmBuilder builder = (AbstractVdmBuilder) o;
82:
83:                                                                 final IVdmModel model = currentProject.getModel();
84:
85:                                                                 if (model != null)
86:                                                                 {
87:                                                                         clearProblemMarkers((IProject) currentProject.getAdapter(IProject.class));
88:                                                                         //first fix source model
89:                                                                         SourceParserManager.parseMissingFiles(currentProject, model, monitor);
90:                                                                         //create working copy from source model to be checked
91:                                                                         VdmModelWorkingCopy workingModel = model.getWorkingCopy();
92:                                                                         
93:                                                                         // if the project is parsed with no errors
94:                                                                         if (model.isParseCorrect())
95:                                                                         {
96:                                                                                 try
97:                                                                                 {
98:                                                                                         if (VdmCore.DEBUG)
99:                                                                                         {
100:                                                                                                 System.out.println("Type Checking: "
101:                                                                                                                 + currentProject.getName());
102:                                                                                         }
103:                                                                                         monitor.subTask("Type checking: "
104:                                                                                                         + currentProject);
105:                                                                                         IStatus status = builder.buildModel(currentProject, workingModel);
106:                                                                                         // mark ast root as type checked
107:                                                                                         if (workingModel != null)
108:                                                                                         {
109:                                                                                                 workingModel.setTypeCheckedStatus(status.isOK());
110:                                                                                                 //override any existing model and source units
111:                                                                                                 workingModel.commit();
112:                                                                                         }
113:                                                                                         
114:                                                                                         if(!status.isOK())
115:                                                                                         {
116:                                                                                                 if(status.getException()!=null)
117:                                                                                                 {
118:                                                                                                         handleException(status.getException());
119:                                                                                                 }
120:                                                                                         }
121:                                                                                 } catch (Exception e)
122:                                                                                 {
123:                                                                                         workingModel.discard();
124:                                                                                         throw e;
125:                                                                                 } finally
126:                                                                                 {
127:                                                                                         monitor.done();
128:                                                                                 }
129:                                                                                 return;
130:                                                                         } else
131:                                                                         {
132:                                                                                 workingModel.discard();
133:                                                                         }
134:                                                                 }
135:                                                         }
136:                                                 };
137:                                                 SafeRunner.run(runnable);
138:                                                 break;
139:                                         }
140:                                 }
141:                         }
142:                 } catch (Exception ex)
143:                 {
144:                         System.out.println(ex.getMessage());
145:                         VdmCore.log(ex);
146:                 }
147:
148:         }
149:
150:         /***
151:          * This method removed all problem markers and its sub-types from the project. It is called before an instance of
152:          * the AbstractBuilder is created
153:          *
154:          * @param project
155:          * The project which should be build.
156:          */
157:         public static void clearProblemMarkers(IProject project)
158:         {
159:                 try
160:                 {
161:                         project.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
162:
163:                 } catch (CoreException e)
164:                 {
165:                         VdmCore.log("VdmCoreBuilder:clearProblemMarkers", e);
166:                 }
167:
168:         }
169: }