Package: AdapterFactoryNode

AdapterFactoryNode

nameinstructionbranchcomplexitylinemethod
AdapterFactoryNode()
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%
getAdapter(Object, Class)
M: 37 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getAdapterList()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getIFileFromRootINode(INode)
M: 51 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 10 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.resources;
23:
24: import java.util.List;
25:
26: import org.eclipse.core.resources.IFile;
27: import org.eclipse.core.resources.IProject;
28: import org.eclipse.core.runtime.IAdapterFactory;
29: import org.overture.ast.definitions.SClassDefinition;
30: import org.overture.ast.modules.AModuleModules;
31: import org.overture.ast.node.INode;
32: import org.overture.ide.core.IVdmModel;
33: import org.overture.ide.internal.core.ast.VdmModelManager;
34:
35: public class AdapterFactoryNode implements IAdapterFactory
36: {
37:
38:         @Override
39:         public Object getAdapter(Object adaptableObject,
40:                         @SuppressWarnings("rawtypes") Class adapterType)
41:         {
42:•                if (adapterType == IFile.class)
43:                 {
44:•                        if (adaptableObject instanceof INode)
45:                         {
46:                                 INode node = (INode) adaptableObject;
47:
48:                                 //Search dept is here to protect against loops in the tree
49:                                 int searchDept = 5;
50:•                                while (--searchDept >0 && !(node instanceof SClassDefinition || node instanceof AModuleModules)
51:•                                                && (node = node.parent()) != null)
52:                                         
53:
54:•                                if (node instanceof SClassDefinition|| node instanceof AModuleModules)
55:                                 {
56:                                         return getIFileFromRootINode(node);
57:                                 }
58:                         }
59:                 }
60:                 return null;
61:         }
62:
63:         protected IFile getIFileFromRootINode(INode node)
64:         {
65:                 List<IProject> projects = VdmModelManager.getInstance().getProjects();
66:•                for (IProject iProject : projects)
67:                 {
68:                         IVdmProject p = (IVdmProject) iProject.getAdapter(IVdmProject.class);
69:                         // we know this is ok, but we check anyway
70:•                        if (p != null)
71:                         {
72:                                 IVdmModel model = p.getModel();
73:•                                if (model.getRootElementList().contains(node))
74:                                 {
75:                                         // ok we have the right project
76:•                                        for (IVdmSourceUnit su : model.getSourceUnits())
77:                                         {
78:•                                                if (su.getParseList().contains(node))
79:                                                 {
80:                                                         return su.getFile();
81:                                                 }
82:                                         }
83:                                 }
84:                         }
85:                 }
86:                 return null;
87:         }
88:
89:         @SuppressWarnings("rawtypes")
90:         public Class[] getAdapterList()
91:         {
92:                 return new Class[] { INode.class };
93:         }
94:
95: }