Method: toString()

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.definitions;
23:
24: import java.io.File;
25: import java.util.Collection;
26: import java.util.HashMap;
27: import java.util.HashSet;
28: import java.util.Map;
29: import java.util.Set;
30: import java.util.Vector;
31:
32: import org.overture.ast.definitions.ABusClassDefinition;
33: import org.overture.ast.definitions.ACpuClassDefinition;
34: import org.overture.ast.definitions.SClassDefinition;
35:
36: /**
37: * A class for holding a list of ClassDefinitions.
38: */
39:
40: public class ClassList extends Vector<SClassDefinition>
41: {
42:         private static final long serialVersionUID = 1L;
43:
44:         protected static Map<String, SClassDefinition> map = new HashMap<String, SClassDefinition>();
45:
46:         public ClassList()
47:         {
48:                 super();
49:         }
50:
51:         public ClassList(SClassDefinition definition)
52:         {
53:                 add(definition);
54:         }
55:
56:         @Override
57:         public boolean add(SClassDefinition cdef)
58:         {
59:                 map.put(cdef.getName().getName(), cdef);
60:
61:                 return super.add(cdef);
62:         }
63:
64:         @Override
65:         public boolean addAll(Collection<? extends SClassDefinition> clist)
66:         {
67:                 for (SClassDefinition cls : clist)
68:                 {
69:                         add(cls);
70:                 }
71:
72:                 return true;
73:         }
74:
75:         public void remap()
76:         {
77:                 map.clear();
78:
79:                 for (SClassDefinition d : this)
80:                 {
81:                         map.put(d.getName().getName(), d);
82:                 }
83:         }
84:
85:         public Set<File> getSourceFiles()
86:         {
87:                 Set<File> files = new HashSet<File>();
88:
89:                 for (SClassDefinition def : this)
90:                 {
91:                         if (!(def instanceof ACpuClassDefinition || def instanceof ABusClassDefinition))
92:                         {
93:                                 files.add(def.getLocation().getFile());
94:                         }
95:                 }
96:
97:                 return files;
98:         }
99:
100:         // public void implicitDefinitions(Environment env)
101:         // {
102:         // for (SClassDefinition d: this)
103:         // {
104:         // d.implicitDefinitions(env);
105:         // }
106:         // }
107:
108:         // public void setLoaded()
109:         // {
110:         // for (SClassDefinition d: this)
111:         // {
112:         // d.typechecked = true;
113:         // }
114:         // }
115:
116:         // public int notLoaded()
117:         // {
118:         // int count = 0;
119:         //
120:         // for (SClassDefinition d: this)
121:         // {
122:         // if (!d.typechecked) count++;
123:         // }
124:         //
125:         // return count;
126:         // }
127:
128:         // public void unusedCheck()
129:         // {
130:         // for (SClassDefinition d: this)
131:         // {
132:         // d.unusedCheck();
133:         // }
134:         // }
135:
136:         @Override
137:         public String toString()
138:         {
139:                 StringBuilder sb = new StringBuilder();
140:
141:•                for (SClassDefinition c : this)
142:                 {
143:                         sb.append(c.toString());
144:                         sb.append("\n");
145:                 }
146:
147:                 return sb.toString();
148:         }
149:
150:         // public ProofObligationList getProofObligations()
151:         // {
152:         // ProofObligationList obligations = new ProofObligationList();
153:         //
154:         // for (SClassDefinition c: this)
155:         // {
156:         // obligations.addAll(c.getProofObligations(new POContextStack()));
157:         // }
158:         //
159:         // obligations.trivialCheck();
160:         // return obligations;
161:         // }
162: }