Package: Vdm2UmlCommand

Vdm2UmlCommand

nameinstructionbranchcomplexitylinemethod
Vdm2UmlCommand()
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%
execute(ExecutionEvent)
M: 121 C: 0
0%
M: 18 C: 0
0%
M: 10 C: 0
0%
M: 32 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * UML2 Translator
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.uml2.commands;
23:
24: import java.io.IOException;
25:
26: import org.eclipse.core.commands.AbstractHandler;
27: import org.eclipse.core.commands.ExecutionEvent;
28: import org.eclipse.core.commands.ExecutionException;
29: import org.eclipse.core.resources.IProject;
30: import org.eclipse.core.resources.IResource;
31: import org.eclipse.core.runtime.CoreException;
32: import org.eclipse.core.runtime.NullProgressMonitor;
33: import org.eclipse.emf.common.util.URI;
34: import org.eclipse.jface.preference.IPreferenceStore;
35: import org.eclipse.jface.viewers.ISelection;
36: import org.eclipse.jface.viewers.IStructuredSelection;
37: import org.eclipse.ui.handlers.HandlerUtil;
38: import org.overture.ast.lex.Dialect;
39: import org.overture.ide.core.IVdmModel;
40: import org.overture.ide.core.ast.NotAllowedException;
41: import org.overture.ide.core.resources.IVdmProject;
42: import org.overture.ide.plugins.uml2.Activator;
43: import org.overture.ide.plugins.uml2.IUml2Constants;
44: import org.overture.ide.plugins.uml2.vdm2uml.Vdm2Uml;
45: import org.overture.ide.ui.utility.VdmTypeCheckerUi;
46:
47: public class Vdm2UmlCommand extends AbstractHandler
48: {
49:
50:         public Object execute(ExecutionEvent event) throws ExecutionException
51:         {
52:
53:                 ISelection selection = HandlerUtil.getCurrentSelection(event);
54:
55:•                if (selection instanceof IStructuredSelection)
56:                 {
57:                         IStructuredSelection structuredSelection = (IStructuredSelection) selection;
58:
59:                         Object firstElement = structuredSelection.getFirstElement();
60:•                        if (firstElement instanceof IProject)
61:                         {
62:                                 IProject project = (IProject) firstElement;
63:                                 IVdmProject vdmProject = (IVdmProject) project.getAdapter(IVdmProject.class);
64:
65:•                                if (vdmProject == null)
66:                                 {
67:                                         return null;
68:                                 }
69:
70:                                 final IVdmModel model = vdmProject.getModel();
71:•                                if (model.isParseCorrect())
72:                                 {
73:
74:•                                        if (model == null || !model.isTypeCorrect())
75:                                         {
76:                                                 VdmTypeCheckerUi.typeCheck(HandlerUtil.getActiveShell(event), vdmProject);
77:                                         }
78:
79:•                                        if (model.isTypeCorrect()
80:•                                                        && (vdmProject.getDialect() == Dialect.VDM_PP || vdmProject.getDialect() == Dialect.VDM_RT))
81:                                         {
82:                                                 IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
83:                                                 boolean preferAssociations = preferences.getBoolean(IUml2Constants.PREFER_ASSOCIATIONS_PREFERENCE);
84:                                                 boolean deployArtifactsOutsideNodes = preferences.getBoolean(IUml2Constants.DISABLE_NESTED_ARTIFACTS_PREFERENCE);
85:                                                 Vdm2Uml vdm2uml = new Vdm2Uml(preferAssociations, deployArtifactsOutsideNodes);
86:                                                 try
87:                                                 {
88:                                                         vdm2uml.convert(project.getName(), model.getClassList());
89:                                                 } catch (NotAllowedException e1)
90:                                                 {
91:                                                         Activator.log("Faild converting VDM to UML", e1);
92:                                                 }
93:
94:                                                 // IFile iFile =
95:                                                 // vdmProject.getModelBuildPath().getOutput().getLocationURI()..getFile(project.getName());
96:                                                 java.net.URI absolutePath = vdmProject.getModelBuildPath().getOutput().getLocationURI();// iFile.getLocationURI();
97:                                                 URI uri = URI.createFileURI(absolutePath.getPath()
98:                                                                 + "/" + project.getName());
99:                                                 try
100:                                                 {
101:                                                         vdm2uml.save(uri);
102:                                                         project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
103:                                                 } catch (IOException e)
104:                                                 {
105:                                                         // TODO Auto-generated catch block
106:                                                         e.printStackTrace();
107:                                                 } catch (CoreException e)
108:                                                 {
109:                                                         // TODO Auto-generated catch block
110:                                                         e.printStackTrace();
111:                                                 }
112:
113:                                         }
114:
115:                                 }
116:
117:                         }
118:
119:                 }
120:
121:                 return null;
122:         }
123:
124: }