Package: Vdm2JavaCommand

Vdm2JavaCommand

nameinstructionbranchcomplexitylinemethod
Vdm2JavaCommand()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
deleteMarkers(IProject)
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
execute(ExecutionEvent)
M: 132 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 39 C: 0
0%
M: 1 C: 0
0%
generateJava(IVdmProject, IVdmModel, JavaCodeGen)
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
generateJml(IVdmProject)
M: 14 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIrSettings(IProject)
M: 25 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getJavaSettings(IProject, List)
M: 44 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getJmlSettings()
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getPrefs()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
handleInvalidNames(InvalidNamesResult)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
handleUnexpectedException(Exception)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
outputQuotes(IVdmProject, File, JavaCodeGen, List)
M: 34 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
outputRenamings(List)
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%
outputRuntimeBinaries(File)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
outputRuntimeSources(File)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
outputSkippedClasses(List)
M: 31 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
outputUserSpecifiedSkippedClasses(List)
M: 35 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
outputUserspecifiedModules(File, List)
M: 191 C: 0
0%
M: 20 C: 0
0%
M: 11 C: 0
0%
M: 36 C: 0
0%
M: 1 C: 0
0%
outputVdm2JmlBinaries(File)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
outputVdm2JmlSources(File)
M: 19 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
outputWarnings(List)
M: 29 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * Code Generator Plugin
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.plugins.javagen.commands;
23:
24: import java.io.File;
25: import java.util.List;
26: import java.util.Set;
27:
28: import org.apache.commons.lang.SystemUtils;
29: import org.eclipse.core.commands.AbstractHandler;
30: import org.eclipse.core.commands.ExecutionEvent;
31: import org.eclipse.core.commands.ExecutionException;
32: import org.eclipse.core.resources.IProject;
33: import org.eclipse.core.resources.IResource;
34: import org.eclipse.core.runtime.CoreException;
35: import org.eclipse.core.runtime.IProgressMonitor;
36: import org.eclipse.core.runtime.IStatus;
37: import org.eclipse.core.runtime.NullProgressMonitor;
38: import org.eclipse.core.runtime.Status;
39: import org.eclipse.core.runtime.jobs.Job;
40: import org.eclipse.core.runtime.preferences.InstanceScope;
41: import org.eclipse.jface.viewers.ISelection;
42: import org.eclipse.jface.viewers.IStructuredSelection;
43: import org.eclipse.ui.handlers.HandlerUtil;
44: import org.osgi.service.prefs.Preferences;
45: import org.overture.ast.analysis.AnalysisException;
46: import org.overture.ast.lex.Dialect;
47: import org.overture.codegen.analysis.vdm.Renaming;
48: import org.overture.codegen.analysis.violations.InvalidNamesResult;
49: import org.overture.codegen.analysis.violations.Violation;
50: import org.overture.codegen.assistant.AssistantManager;
51: import org.overture.codegen.assistant.LocationAssistantIR;
52: import org.overture.codegen.ir.IRSettings;
53: import org.overture.codegen.ir.IrNodeInfo;
54: import org.overture.codegen.ir.VdmNodeInfo;
55: import org.overture.codegen.utils.AnalysisExceptionIR;
56: import org.overture.codegen.utils.GeneralCodeGenUtils;
57: import org.overture.codegen.utils.GeneralUtils;
58: import org.overture.codegen.utils.GeneratedData;
59: import org.overture.codegen.utils.GeneratedModule;
60: import org.overture.codegen.vdm2java.IJavaConstants;
61: import org.overture.codegen.vdm2java.JavaCodeGen;
62: import org.overture.codegen.vdm2java.JavaCodeGenUtil;
63: import org.overture.codegen.vdm2java.JavaSettings;
64: import org.overture.codegen.vdm2jml.JmlGenerator;
65: import org.overture.codegen.vdm2jml.JmlSettings;
66: import org.overture.config.Settings;
67: import org.overture.ide.core.IVdmModel;
68: import org.overture.ide.core.resources.IVdmProject;
69: import org.overture.ide.plugins.javagen.Activator;
70: import org.overture.ide.plugins.javagen.CodeGenConsole;
71: import org.overture.ide.plugins.javagen.ICodeGenConstants;
72: import org.overture.ide.plugins.javagen.util.PluginVdm2JavaUtil;
73: import org.overture.ide.ui.utility.VdmTypeCheckerUi;
74:
75: public class Vdm2JavaCommand extends AbstractHandler
76: {
77:         private AssistantManager assistantManager;
78:
79:         public Vdm2JavaCommand()
80:         {
81:                 this.assistantManager = new AssistantManager();
82:         }
83:
84:         public Object execute(ExecutionEvent event) throws ExecutionException
85:         {
86:                 // Validate project
87:                 ISelection selection = HandlerUtil.getCurrentSelection(event);
88:
89:•                if (!(selection instanceof IStructuredSelection))
90:                 {
91:                         return null;
92:                 }
93:
94:                 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
95:
96:                 Object firstElement = structuredSelection.getFirstElement();
97:
98:•                if (!(firstElement instanceof IProject))
99:                 {
100:                         return null;
101:                 }
102:
103:                 final IProject project = (IProject) firstElement;
104:                 final IVdmProject vdmProject = (IVdmProject) project.getAdapter(IVdmProject.class);
105:
106:                 try
107:                 {
108:                         Settings.release = vdmProject.getLanguageVersion();
109:                         Settings.dialect = vdmProject.getDialect();
110:                 } catch (CoreException e)
111:                 {
112:                         Activator.log("Problems setting VDM language version and dialect", e);
113:                         e.printStackTrace();
114:                 }
115:
116:                 CodeGenConsole.GetInstance().activate();
117:                 CodeGenConsole.GetInstance().clearConsole();
118:                 
119:                 deleteMarkers(project);
120:
121:                 final IVdmModel model = vdmProject.getModel();
122:
123:•                if (model == null)
124:                 {
125:                         CodeGenConsole.GetInstance().println("Could not get model for project: "
126:                                         + project.getName());
127:                         return null;
128:                 }
129:
130:•                if (!model.isParseCorrect())
131:                 {
132:                         CodeGenConsole.GetInstance().println("Could not parse model: "
133:                                         + project.getName());
134:                         return null;
135:                 }
136:
137:•                if (!model.isTypeChecked())
138:                 {
139:                         VdmTypeCheckerUi.typeCheck(HandlerUtil.getActiveShell(event), vdmProject);
140:                 }
141:
142:•                if (!model.isTypeCorrect())
143:                 {
144:                         CodeGenConsole.GetInstance().println("Could not type check model: "
145:                                         + project.getName());
146:                         return null;
147:                 }
148:                 
149:                 CodeGenConsole.GetInstance().println("Starting VDM to Java code generation...\n");
150:                 
151:                 final List<String> classesToSkip = PluginVdm2JavaUtil.getClassesToSkip();
152:                 final JavaSettings javaSettings = getJavaSettings(project, classesToSkip);
153:                 
154:                 final IRSettings irSettings = getIrSettings(project);
155:                 
156:                 Job codeGenerate = new Job("VDM to Java code generation")
157:                 {
158:                         @Override
159:                         protected IStatus run(IProgressMonitor monitor)
160:                         {
161:                                 if(javaSettings == null)
162:                                 {
163:                                         return Status.CANCEL_STATUS;
164:                                 }
165:                                 
166:                                 // Begin code generation
167:                                 final JavaCodeGen vdm2java = new JavaCodeGen();
168:                                 vdm2java.setSettings(irSettings);
169:                                 vdm2java.setJavaSettings(javaSettings);
170:
171:                                 try
172:                                 {
173:                                         File eclipseProjectFolder = PluginVdm2JavaUtil.getEclipseProjectFolder(vdmProject);
174:                                         
175:                                         // Clean folder with generated Java code
176:                                         GeneralUtils.deleteFolderContents(eclipseProjectFolder, true);
177:
178:                                         // Generate user specified classes
179:                                         GeneratedData generatedData = generateJava(vdmProject, model, vdm2java);
180:                                         
181:                                         outputUserSpecifiedSkippedClasses(classesToSkip);
182:                                         outputSkippedClasses(generatedData.getSkippedClasses());
183:                                         
184:                                         File javaCodeOutputFolder = PluginVdm2JavaUtil.getJavaCodeOutputFolder(vdmProject, javaSettings);
185:                                         
186:                                         try
187:                                         {
188:                                                 vdm2java.genJavaSourceFiles(javaCodeOutputFolder, generatedData.getClasses());
189:
190:                                                 CodeGenConsole.GetInstance().println("Project dialect: " + PluginVdm2JavaUtil.dialect2Str(vdmProject.getDialect()));
191:                                                 
192:                                                 if(vdmProject.getDialect() == Dialect.VDM_RT)
193:                                                 {
194:                                                         CodeGenConsole.GetInstance().println("The current version of the Java code generator does not support the distributed aspects of the VDM-RT.");
195:                                                         CodeGenConsole.GetInstance().println("Ignoring deployment as well as cycles and duration statements...\n");
196:                                                 }
197:                                                 else
198:                                                 {
199:                                                         CodeGenConsole.GetInstance().println("");
200:                                                 }
201:                                                 
202:                                         } catch (Exception e)
203:                                         {
204:                                                 CodeGenConsole.GetInstance().errorln("Problems saving the code generated Java source files to disk.");
205:                                                 CodeGenConsole.GetInstance().errorln("Try to run Overture with write permissions.\n");
206:                                                 
207:                                                 if(SystemUtils.IS_OS_WINDOWS)
208:                                                 {
209:                                                         CodeGenConsole.GetInstance().println("Operating System: Windows.");
210:                                                         CodeGenConsole.GetInstance().println("If you installed Overture in a location such as \"C:\\Program Files\\Overture\"");
211:                                                         CodeGenConsole.GetInstance().println("you may need to give Overture permissions to write to the file system. You can try");
212:                                                         CodeGenConsole.GetInstance().println("run Overture as administrator and see if this solves the problem.");
213:                                                 }
214:                                                 
215:                                                 return Status.CANCEL_STATUS;
216:                                         }
217:                                         
218:                                         File libFolder = PluginVdm2JavaUtil.getCodeGenRuntimeLibFolder(vdmProject);
219:                                         
220:                                         try
221:                                         {
222:                                                 PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.CODEGEN_RUNTIME_BIN_FILE, libFolder);
223:                                                 outputRuntimeBinaries(libFolder);
224:                                         }
225:                                         catch(Exception e)
226:                                         {
227:                                                 CodeGenConsole.GetInstance().errorln("Problems copying the Java code generator runtime library to " + libFolder.getAbsolutePath());
228:                                                 CodeGenConsole.GetInstance().errorln("Reason: " + e.getMessage());
229:                                         }
230:                                         
231:                                         try
232:                                         {
233:                                                 PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.CODEGEN_RUNTIME_SOURCES_FILE, libFolder);
234:                                                 outputRuntimeSources(libFolder);
235:                                         }
236:                                         catch(Exception e)
237:                                         {
238:                                                 CodeGenConsole.GetInstance().errorln("Problems copying the Java code generator runtime library sources to " + libFolder.getAbsolutePath());
239:                                                 CodeGenConsole.GetInstance().errorln("Reason: " + e.getMessage());
240:                                         }
241:                                         
242:                                         if(generateJml(vdmProject))
243:                                         {
244:                                                 try
245:                                                 {
246:                                                         PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.VDM2JML_RUNTIME_BIN_FILE, libFolder);
247:                                                         outputVdm2JmlBinaries(libFolder);
248:                                                 }
249:                                                 catch(Exception e)
250:                                                 {
251:                                                         CodeGenConsole.GetInstance().errorln("Problems copying the VDM-to-JML runtime library to " + libFolder.getAbsolutePath());
252:                                                         CodeGenConsole.GetInstance().errorln("Reason: " + e.getMessage());
253:                                                 }
254:                                                 
255:                                                 try
256:                                                 {
257:                                                         PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.VDM2JML_RUNTIME_SOURCES_FILE, libFolder);
258:                                                         outputVdm2JmlSources(libFolder);
259:                                                 }
260:                                                 catch(Exception e)
261:                                                 {
262:                                                         CodeGenConsole.GetInstance().errorln("Problems copying the VDM-to-JML runtime library sources to " + libFolder.getAbsolutePath());
263:                                                         CodeGenConsole.GetInstance().errorln("Reason: " + e.getMessage());
264:                                                 }
265:                                         }
266:                                         
267:                                         try
268:                                         {
269:                                                 PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.ECLIPSE_RES_FILES_FOLDER + "/"
270:                                                                 + PluginVdm2JavaUtil.ECLIPSE_PROJECT_TEMPLATE_FILE, PluginVdm2JavaUtil.ECLIPSE_PROJECT_FILE, eclipseProjectFolder);
271:                                                 
272:                                                 GeneralCodeGenUtils.replaceInFile(new File(eclipseProjectFolder, PluginVdm2JavaUtil.ECLIPSE_PROJECT_FILE), "%s", project.getName());
273:                                                 
274:                                                 
275:                                                 PluginVdm2JavaUtil.copyCodeGenFile(PluginVdm2JavaUtil.ECLIPSE_RES_FILES_FOLDER + "/"
276:                                                                 + PluginVdm2JavaUtil.ECLIPSE_CLASSPATH_TEMPLATE_FILE, PluginVdm2JavaUtil.ECLIPSE_CLASSPATH_FILE, eclipseProjectFolder);
277:                                                 
278:                                                 // Always imports codegen-runtime.jar
279:                                                 String classPathEntries = PluginVdm2JavaUtil.RUNTIME_CLASSPATH_ENTRY;
280:                                                 
281:                                                 if(generateJml(vdmProject))
282:                                                 {
283:                                                         // Import the VDM-to-JML runtime
284:                                                         classPathEntries += PluginVdm2JavaUtil.VDM2JML_CLASSPATH_ENTRY;
285:                                                 }
286:                                                 
287:                                                 GeneralCodeGenUtils.replaceInFile(new File(eclipseProjectFolder, PluginVdm2JavaUtil.ECLIPSE_CLASSPATH_FILE), "%s", classPathEntries);
288:                                                 
289:                                                 
290:                                                 CodeGenConsole.GetInstance().println("Generated Eclipse project with Java generated code.\n");
291:
292:                                         } catch (Exception e)
293:                                         {
294:                                                 e.printStackTrace();
295:                                                 CodeGenConsole.GetInstance().errorln("Problems generating the eclipse project with the generated Java code");
296:                                                 CodeGenConsole.GetInstance().errorln("Reason: "
297:                                                                 + e.getMessage());
298:                                         }
299:                                         
300:                                         outputUserspecifiedModules(javaCodeOutputFolder, generatedData.getClasses());
301:
302:                                         // Quotes generation
303:                                         outputQuotes(vdmProject, javaCodeOutputFolder, vdm2java, generatedData.getQuoteValues());
304:
305:                                         // Renaming of variables shadowing other variables
306:                                         outputRenamings(generatedData.getAllRenamings());
307:                                         
308:                                         InvalidNamesResult invalidNames = generatedData.getInvalidNamesResult();
309:
310:                                         if (invalidNames != null && !invalidNames.isEmpty())
311:                                         {
312:                                                 handleInvalidNames(invalidNames);
313:                                         }
314:                                         
315:                                         // Output any warnings such as problems with the user's launch configuration
316:                                         outputWarnings(generatedData.getWarnings());
317:
318:                                         
319:                                         // Summarize the code generation process
320:                                         int noOfClasses = generatedData.getClasses().size();
321:                                         
322:                                         String msg = String.format("...finished Java code generation (generated %s %s).",
323:                                                         noOfClasses,
324:                                                         noOfClasses == 1 ? "class" : "classes");
325:                                         
326:                                         CodeGenConsole.GetInstance().println(msg);
327:
328:                                         project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
329:
330:                                 } catch (AnalysisExceptionIR ex)
331:                                 {
332:                                         CodeGenConsole.GetInstance().println("Could not code generate VDM model: "
333:                                                         + ex.getMessage());
334:                                 } catch (Exception ex)
335:                                 {
336:                                         handleUnexpectedException(ex);
337:                                 }
338:
339:                                 return Status.OK_STATUS;
340:                         }
341:                 };
342:
343:                 codeGenerate.schedule();
344:
345:                 return null;
346:         }
347:         
348:         public GeneratedData generateJava(final IVdmProject project,
349:                         final IVdmModel model, final JavaCodeGen vdm2java)
350:                         throws AnalysisException
351:         {
352:•                if(project.getDialect() != Dialect.VDM_SL)
353:                 {
354:                         return vdm2java.generate(PluginVdm2JavaUtil.getNodes(model.getSourceUnits()));                        
355:                 }
356:                 else
357:                 {
358:•                        if (generateJml(project))
359:                         {
360:                                 JmlSettings jmlSettings = getJmlSettings();
361:                                 
362:                                 JmlGenerator jmlGen = new JmlGenerator(vdm2java);
363:                                 jmlGen.setJmlSettings(jmlSettings);
364:                                 
365:                                 return jmlGen.generateJml(PluginVdm2JavaUtil.getModules(model.getSourceUnits()));
366:                         } else
367:                         {
368:                                 return vdm2java.generate(PluginVdm2JavaUtil.getNodes(model.getSourceUnits()));
369:                         }
370:                 }
371:         }
372:
373:
374:         private boolean generateJml(IVdmProject project)
375:         {
376:•                return project.getDialect() == Dialect.VDM_SL && getPrefs().getBoolean(ICodeGenConstants.GENERATE_JML, ICodeGenConstants.GENERATE_JML_DEFAULT);
377:         }
378:         
379:         private JmlSettings getJmlSettings()
380:         {
381:                 Preferences preferences = getPrefs();
382:                 
383:                 boolean useInvFor = preferences.getBoolean(ICodeGenConstants.JML_USE_INVARIANT_FOR, ICodeGenConstants.JML_USE_INVARIANT_FOR_DEFAULT);;
384:                 
385:                 JmlSettings jmlSettings = new JmlSettings();
386:                 jmlSettings.setGenInvariantFor(useInvFor);
387:                 
388:                 return jmlSettings;
389:         }
390:         
391:         public IRSettings getIrSettings(final IProject project)
392:         {
393:                 Preferences preferences = getPrefs();
394:                 
395:                 boolean generateCharSeqsAsStrings = preferences.getBoolean(ICodeGenConstants.GENERATE_CHAR_SEQUENCES_AS_STRINGS, ICodeGenConstants.GENERATE_CHAR_SEQUENCES_AS_STRING_DEFAULT);
396:                 boolean generateConcMechanisms = preferences.getBoolean(ICodeGenConstants.GENERATE_CONCURRENCY_MECHANISMS, ICodeGenConstants.GENERATE_CONCURRENCY_MECHANISMS_DEFAULT);
397:                 
398:                 IRSettings irSettings = new IRSettings();
399:                 irSettings.setCharSeqAsString(generateCharSeqsAsStrings);
400:                 irSettings.setGenerateConc(generateConcMechanisms);
401:                 
402:                 return irSettings;
403:         }
404:
405:         private Preferences getPrefs()
406:         {
407:                 Preferences preferences = InstanceScope.INSTANCE.getNode(ICodeGenConstants.PLUGIN_ID);
408:                 return preferences;
409:         }
410:         
411:         public JavaSettings getJavaSettings(final IProject project, List<String> classesToSkip)
412:         {
413:                 Preferences preferences = getPrefs();
414:                 
415:                 boolean disableCloning = preferences.getBoolean(ICodeGenConstants.DISABLE_CLONING, ICodeGenConstants.DISABLE_CLONING_DEFAULT);
416:                 String javaPackage = preferences.get(ICodeGenConstants.JAVA_PACKAGE, ICodeGenConstants.JAVA_PACKAGE_DEFAULT);
417:                 boolean genVdmLoc = preferences.getBoolean(ICodeGenConstants.GENERATE_VDM_LOCATIONS_INFO, ICodeGenConstants.GENERATE_VDM_LOCATIONS_INFO_DEFAULT);
418:                 
419:                 JavaSettings javaSettings = new JavaSettings();
420:                 javaSettings.setDisableCloning(disableCloning);
421:                 javaSettings.setModulesToSkip(classesToSkip);
422:                 javaSettings.setJavaRootPackage(javaPackage);
423:                 javaSettings.setPrintVdmLocations(genVdmLoc);
424:                 
425:•                if (!JavaCodeGenUtil.isValidJavaPackage(javaSettings.getJavaRootPackage()))
426:                 {
427:                         javaSettings.setJavaRootPackage(project.getName());
428:                 }
429:                 
430:                 return javaSettings;
431:         }
432:         
433:         private void deleteMarkers(IProject project)
434:         {
435:•                if (project == null)
436:                 {
437:                         return;
438:                 }
439:
440:                 try
441:                 {
442:                         project.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
443:                 } catch (CoreException ex)
444:                 {
445:                         Activator.log("Could not delete markers for project: "
446:                                         + project.toString(), ex);
447:                         ex.printStackTrace();
448:                 }
449:         }
450:
451:         private void outputWarnings(List<String> warnings)
452:         {
453:•                if(warnings != null && !warnings.isEmpty())
454:                 {
455:•                        for(String warning : warnings)
456:                         {
457:                                 CodeGenConsole.GetInstance().println(PluginVdm2JavaUtil.WARNING + " " + warning);
458:                         }
459:                         
460:                         CodeGenConsole.GetInstance().errorln("");
461:                 }
462:         }
463:         
464:         private void outputUserSpecifiedSkippedClasses(
465:                         List<String> userspecifiedSkippedClasses)
466:         {
467:•                if (!userspecifiedSkippedClasses.isEmpty())
468:                 {
469:                         CodeGenConsole.GetInstance().print("User specified filtered classes: ");
470:
471:•                        for (String skippedClass : userspecifiedSkippedClasses)
472:                         {
473:                                 CodeGenConsole.GetInstance().print(skippedClass + " ");
474:                         }
475:
476:                         CodeGenConsole.GetInstance().println("\n");
477:                 }
478:                 else
479:                 {
480:                         CodeGenConsole.GetInstance().println("No user specified classes to skip.\n");
481:                 }
482:         }
483:
484:         private void outputSkippedClasses(List<String> skippedClasses)
485:         {
486:•                if (!skippedClasses.isEmpty())
487:                 {
488:                         CodeGenConsole.GetInstance().print("Skipping classes (user specified and library named): ");
489:
490:•                        for (String skippedClass : skippedClasses)
491:                         {
492:                                 CodeGenConsole.GetInstance().print(skippedClass + " ");
493:                         }
494:
495:                         CodeGenConsole.GetInstance().println("\n");
496:                 }
497:         }
498:         
499:         private void outputRenamings(List<Renaming> allRenamings)
500:         {
501:•                if(!allRenamings.isEmpty())
502:                 {
503:                         CodeGenConsole.GetInstance().println("Due to variable shadowing or normalisation of Java identifiers the following renamings of variables have been made:");
504:                         CodeGenConsole.GetInstance().println(GeneralCodeGenUtils.constructVarRenamingString(allRenamings));;
505:                 }
506:         }
507:         
508:         private void outputRuntimeBinaries(File outputFolder)
509:         {
510:                 File runtime = new File(outputFolder, PluginVdm2JavaUtil.CODEGEN_RUNTIME_BIN_FILE);
511:                 CodeGenConsole.GetInstance().println("Copied the Java code generator runtime library to " + runtime.getAbsolutePath());
512:         }
513:         
514:         private void outputRuntimeSources(File outputFolder)
515:         {
516:                 File runtime = new File(outputFolder, PluginVdm2JavaUtil.CODEGEN_RUNTIME_SOURCES_FILE);
517:                 CodeGenConsole.GetInstance().println("Copied the Java code generator runtime library sources to " + runtime.getAbsolutePath() + "\n");
518:         }
519:         
520:         private void outputVdm2JmlBinaries(File outputFolder)
521:         {
522:                 File vdm2jmlRuntime = new File(outputFolder, PluginVdm2JavaUtil.VDM2JML_RUNTIME_BIN_FILE);
523:                 CodeGenConsole.GetInstance().println("Copied the VDM-to-JML runtime library to " + vdm2jmlRuntime.getAbsolutePath());
524:         }
525:         
526:         private void outputVdm2JmlSources(File outputFolder)
527:         {
528:                 File vdm2jmlSources = new File(outputFolder, PluginVdm2JavaUtil.VDM2JML_RUNTIME_BIN_FILE);
529:                 CodeGenConsole.GetInstance().println("Copied the VDM-to-JML runtime library sources to " + vdm2jmlSources.getAbsolutePath() + "\n");
530:         }        
531:
532:         private void outputUserspecifiedModules(File outputFolder,
533:                         List<GeneratedModule> userspecifiedClasses)
534:         {
535:•                for (GeneratedModule generatedModule : userspecifiedClasses)
536:                 {
537:•                        if (generatedModule.hasMergeErrors())
538:                         {
539:                                 CodeGenConsole.GetInstance().errorln(String.format("Could not generate Java for class %s. Following errors were found:", generatedModule.getName()));
540:
541:                                 List<Exception> mergeErrors = generatedModule.getMergeErrors();
542:
543:•                                for (Exception error : mergeErrors)
544:                                 {
545:                                         CodeGenConsole.GetInstance().errorln(error.toString());
546:                                 }
547:•                        } else if (!generatedModule.canBeGenerated())
548:                         {
549:                                 CodeGenConsole.GetInstance().println("Could not code generate class: "
550:                                                 + generatedModule.getName() + ".");
551:                                 
552:•                                if(generatedModule.hasUnsupportedIrNodes())
553:                                 {
554:                                         LocationAssistantIR locationAssistant = assistantManager.getLocationAssistant();
555:
556:                                         List<VdmNodeInfo> unsupportedInIr = locationAssistant.getVdmNodeInfoLocationSorted(generatedModule.getUnsupportedInIr());
557:                                         CodeGenConsole.GetInstance().println("Following VDM constructs are not supported by the code generator:");
558:
559:•                                        for (VdmNodeInfo nodeInfo : unsupportedInIr)
560:                                         {
561:                                                 String message = PluginVdm2JavaUtil.formatNodeString(nodeInfo, locationAssistant);
562:                                                 CodeGenConsole.GetInstance().println(message);
563:
564:                                                 PluginVdm2JavaUtil.addMarkers(nodeInfo, locationAssistant);
565:                                         }
566:                                 }
567:                                 
568:•                                if(generatedModule.hasUnsupportedTargLangNodes())
569:                                 {
570:                                         Set<IrNodeInfo> unsupportedInTargLang = generatedModule.getUnsupportedInTargLang();
571:                                         CodeGenConsole.GetInstance().println("Following constructs are not supported by the code generator:");
572:
573:•                                        for (IrNodeInfo nodeInfo : unsupportedInTargLang)
574:                                         {
575:                                                 CodeGenConsole.GetInstance().println(nodeInfo.toString());
576:                                         }
577:                                 }
578:                                 
579:                         } else
580:                         {
581:                                 File javaFile = new File(outputFolder, generatedModule.getName()
582:                                                 + IJavaConstants.JAVA_FILE_EXTENSION);
583:                                 CodeGenConsole.GetInstance().println("Generated class: "
584:                                                 + generatedModule.getName());
585:                                 CodeGenConsole.GetInstance().println("Java source file: "
586:                                                 + javaFile.getAbsolutePath());
587:                                 
588:                                 Set<IrNodeInfo> warnings = generatedModule.getTransformationWarnings();
589:                                 
590:•                                if(!warnings.isEmpty())
591:                                 {
592:                                         CodeGenConsole.GetInstance().println("The following warnings were found for class " + generatedModule.getName() + ":");
593:
594:•                                        for (IrNodeInfo nodeInfo : warnings)
595:                                         {
596:                                                 CodeGenConsole.GetInstance().println(nodeInfo.getReason());
597:                                         }
598:                                 }
599:
600:                         }
601:
602:                         CodeGenConsole.GetInstance().println("");
603:                 }
604:         }
605:
606:         private void outputQuotes(IVdmProject vdmProject, File outputFolder,
607:                         JavaCodeGen vdm2java, List<GeneratedModule> quotes) throws CoreException
608:         {
609:•                if (quotes != null && !quotes.isEmpty())
610:                 {
611:•                        for(GeneratedModule q : quotes)
612:                         {
613:                                 vdm2java.genJavaSourceFile(outputFolder, q);
614:                         }
615:
616:                         CodeGenConsole.GetInstance().println("Quotes generated to folder: "
617:                                         + outputFolder.getAbsolutePath());
618:                         CodeGenConsole.GetInstance().println("");
619:                 }
620:         }
621:
622:         private void handleUnexpectedException(Exception ex)
623:         {
624:                 String errorMessage =
625:                                 "Unexpected problem encountered when attempting to code generate the VDM model.\n"
626:                                 + "The details of this problem have been reported in the Error Log.";
627:
628:                 Activator.log(errorMessage, ex);
629:                 CodeGenConsole.GetInstance().errorln(errorMessage);
630:                 ex.printStackTrace();
631:         }
632:
633:         private void handleInvalidNames(InvalidNamesResult invalidNames)
634:         {
635:                 String message = "The model either uses words that are reserved by Java, declares VDM types"
636:                                 + " that uses Java type names or uses variable names that potentially"
637:                                 + " conflict with code generated temporary variable names";
638:
639:                 CodeGenConsole.GetInstance().println("Warning: " + message);
640:
641:                 String violationStr = GeneralCodeGenUtils.constructNameViolationsString(invalidNames);
642:                 CodeGenConsole.GetInstance().println(violationStr);
643:
644:                 Set<Violation> typeNameViolations = invalidNames.getTypenameViolations();
645:                 PluginVdm2JavaUtil.addMarkers("Type name violation", typeNameViolations);
646:
647:                 Set<Violation> reservedWordViolations = invalidNames.getReservedWordViolations();
648:                 PluginVdm2JavaUtil.addMarkers("Reserved word violations", reservedWordViolations);
649:         }
650: }