Package: ModuleList

ModuleList

nameinstructionbranchcomplexitylinemethod
ModuleList()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
ModuleList(List)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
combineDefaults()
M: 0 C: 66
100%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 0 C: 15
100%
M: 0 C: 1
100%
findModule(LexIdentifierToken)
M: 3 C: 17
85%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 3
60%
M: 0 C: 1
100%
findTraceDefinition(LexNameToken)
M: 38 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getFlatModules()
M: 0 C: 28
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 6
100%
M: 0 C: 1
100%
getSourceFiles()
M: 22 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
importAll(ILexIdentifierToken)
M: 0 C: 45
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
toString()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * The Overture Abstract Syntax Tree
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.ast.util.modules;
23:
24: import java.io.File;
25: import java.util.HashSet;
26: import java.util.List;
27: import java.util.Set;
28: import java.util.Vector;
29:
30: import org.overture.ast.definitions.ANamedTraceDefinition;
31: import org.overture.ast.definitions.PDefinition;
32: import org.overture.ast.factory.AstFactory;
33: import org.overture.ast.intf.lex.ILexIdentifierToken;
34: import org.overture.ast.intf.lex.ILexNameToken;
35: import org.overture.ast.lex.LexIdentifierToken;
36: import org.overture.ast.lex.LexNameToken;
37: import org.overture.ast.modules.AAllImport;
38: import org.overture.ast.modules.AFromModuleImports;
39: import org.overture.ast.modules.AModuleModules;
40: import org.overture.ast.modules.PImport;
41: import org.overture.ast.util.Utils;
42: import org.overture.config.Release;
43: import org.overture.config.Settings;
44:
45: @SuppressWarnings("serial")
46: public class ModuleList extends Vector<AModuleModules>
47: {
48:         public ModuleList()
49:         {
50:                 // empty
51:         }
52:
53:         public ModuleList(List<AModuleModules> modules)
54:         {
55:                 addAll(modules);
56:         }
57:
58:         @Override
59:         public String toString()
60:         {
61:                 return Utils.listToString(this);
62:         }
63:
64:         public Set<File> getSourceFiles()
65:         {
66:                 Set<File> files = new HashSet<File>();
67:
68:•                for (AModuleModules def : this)
69:                 {
70:                         files.addAll(def.getFiles());
71:                 }
72:
73:                 return files;
74:         }
75:
76:         public AModuleModules findModule(LexIdentifierToken sought)
77:         {
78:•                for (AModuleModules m : this)
79:                 {
80:•                        if (m.getName().equals(sought))
81:                         {
82:                                 return m;
83:                         }
84:                 }
85:
86:                 return null;
87:         }
88:
89:         public int combineDefaults()
90:         {
91:                 int rv = 0;
92:
93:•                if (!isEmpty())
94:                 {
95:                         CombinedDefaultModule def = new CombinedDefaultModule(getFlatModules());
96:
97:•                        if (Settings.release == Release.VDM_10)
98:                         {
99:                                 // In VDM-10, we implicitly import all from the other
100:                                 // modules included with the flat specifications (if any).
101:
102:                                 List<AFromModuleImports> imports = new Vector<AFromModuleImports>();
103:
104:•                                for (AModuleModules m : this)
105:                                 {
106:•                                        if (!m.getIsFlat())
107:                                         {
108:                                                 imports.add(importAll(m.getName().clone()));
109:                                         }
110:                                 }
111:
112:•                                if (!imports.isEmpty())
113:                                 {
114:                                         def.setImports(AstFactory.newAModuleImports(def.getName().clone(), imports));
115:                                 }
116:                         }
117:
118:•                        if (!def.getModules().isEmpty())
119:                         {
120:                                 removeAll(getFlatModules());
121:                                 add(def);
122:                         }
123:                 }
124:
125:                 return rv;
126:         }
127:
128:         private Set<AModuleModules> getFlatModules()
129:         {
130:                 Set<AModuleModules> flats = new HashSet<AModuleModules>();
131:
132:•                for (AModuleModules m : this)
133:                 {
134:•                        if (m.getIsFlat() && !(m instanceof CombinedDefaultModule))
135:                         {
136:                                 flats.add(m);
137:                         }
138:                 }
139:
140:                 return flats;
141:         }
142:
143:         public ANamedTraceDefinition findTraceDefinition(LexNameToken name)
144:         {
145:•                for (AModuleModules m : this)
146:                 {
147:•                        for (PDefinition d : m.getDefs())
148:                         {
149:•                                if (name.equals(d.getName()))
150:                                 {
151:•                                        if (d instanceof ANamedTraceDefinition)
152:                                         {
153:                                                 return (ANamedTraceDefinition) d;
154:                                         } else
155:                                         {
156:                                                 return null;
157:                                         }
158:                                 }
159:                         }
160:                 }
161:
162:                 return null;
163:         }
164:
165:         // This function is copied from the module reader
166:         private AFromModuleImports importAll(ILexIdentifierToken from)
167:         {
168:                 List<List<PImport>> types = new Vector<List<PImport>>();
169:                 ILexNameToken all = new LexNameToken(from.getName(), "all", from.getLocation());
170:                 List<PImport> impAll = new Vector<PImport>();
171:                 AAllImport iport = AstFactory.newAAllImport(all);
172:                 iport.setLocation(all.getLocation());
173:                 iport.setName(all);
174:                 iport.setRenamed(all);
175:                 iport.setFrom(null);
176:                 impAll.add(iport);
177:                 types.add(impAll);
178:                 return AstFactory.newAFromModuleImports(from, types);
179:         }
180: }