Package: LexNameToken

LexNameToken

nameinstructionbranchcomplexitylinemethod
LexNameToken(String, ILexIdentifierToken)
M: 0 C: 26
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
LexNameToken(String, String, ILexLocation)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
LexNameToken(String, String, ILexLocation, boolean, boolean)
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
apply(IAnalysis)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
apply(IAnswer)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
apply(IQuestion, Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
apply(IQuestionAnswer, Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
clone()
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%
compareTo(ILexNameToken)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
copy()
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
equals(Object)
M: 0 C: 33
100%
M: 2 C: 12
86%
M: 2 C: 6
75%
M: 0 C: 8
100%
M: 0 C: 1
100%
getChildren(Boolean)
M: 40 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getClassName()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getEqName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getExplicit()
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%
getExplicit(boolean)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getFullName()
M: 0 C: 36
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getIdentifier()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getInitName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getInvName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLocation()
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%
getMaxName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMeasureName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMinName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getModifiedName(List)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getModifiedName(String)
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getModule()
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%
getName()
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%
getNewName()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOld()
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%
getOldName()
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOrdName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getPerName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getPostName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getPreName(ILexLocation)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSelfName()
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getSimpleName()
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%
getThreadName()
M: 16 C: 21
57%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 3 C: 4
57%
M: 0 C: 1
100%
getThreadName(ILexLocation)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getTypeQualifier()
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%
hashCode()
M: 0 C: 32
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
isOld()
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%
isReserved()
M: 0 C: 44
100%
M: 2 C: 14
88%
M: 2 C: 7
78%
M: 0 C: 9
100%
M: 0 C: 1
100%
matches(ILexNameToken)
M: 0 C: 21
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setTypeQualifier(List)
M: 17 C: 20
54%
M: 2 C: 8
80%
M: 2 C: 4
67%
M: 1 C: 5
83%
M: 0 C: 1
100%
toString()
M: 0 C: 26
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
typeQualifier()
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%

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.lex;
23:
24: import java.io.Serializable;
25: import java.util.HashMap;
26: import java.util.List;
27: import java.util.Map;
28: import java.util.Vector;
29:
30: import org.overture.ast.analysis.AnalysisException;
31: import org.overture.ast.analysis.intf.IAnalysis;
32: import org.overture.ast.analysis.intf.IAnswer;
33: import org.overture.ast.analysis.intf.IQuestion;
34: import org.overture.ast.analysis.intf.IQuestionAnswer;
35: import org.overture.ast.intf.lex.ILexIdentifierToken;
36: import org.overture.ast.intf.lex.ILexLocation;
37: import org.overture.ast.intf.lex.ILexNameToken;
38: import org.overture.ast.messages.InternalException;
39: import org.overture.ast.types.PType;
40: import org.overture.ast.util.Utils;
41:
42: public class LexNameToken extends LexToken implements ILexNameToken,
43:                 Serializable
44: {
45:         private static final long serialVersionUID = 1L;
46:
47:         public final String module;
48:         public final String name;
49:         public final boolean old;
50:         public final boolean explicit; // Name has an explicit module/class
51:
52:         public List<PType> typeQualifier = null;
53:
54:         private int hashcode = 0;
55:
56:         @Override
57:         public boolean getExplicit()
58:         {
59:                 return explicit;
60:         }
61:
62:         public String getName()
63:         {
64:                 return name;
65:         }
66:
67:         @Override
68:         public boolean getOld()
69:         {
70:                 return old;
71:         }
72:
73:         @Override
74:         public List<PType> typeQualifier()
75:         {
76:                 return typeQualifier;
77:         }
78:
79:         public LexNameToken(String module, String name, ILexLocation location,
80:                         boolean old, boolean explicit)
81:         {
82:                 super(location, VDMToken.NAME);
83:                 this.module = module;
84:                 this.name = name;
85:                 this.old = old;
86:                 this.explicit = explicit;
87:         }
88:
89:         public LexNameToken(String module, String name, ILexLocation location)
90:         {
91:                 this(module, name, location, false, false);
92:         }
93:
94:         public LexNameToken(String module, ILexIdentifierToken id)
95:         {
96:                 super(id.getLocation(), VDMToken.NAME);
97:                 this.module = module;
98:                 this.name = id.getName();
99:                 this.old = id.isOld();
100:                 this.explicit = false;
101:         }
102:
103:         public LexIdentifierToken getIdentifier()
104:         {
105:                 return new LexIdentifierToken(name, old, location);
106:         }
107:
108:         public LexNameToken getExplicit(boolean b)
109:         {
110:                 LexNameToken ex = new LexNameToken(module, name, location, old, b);
111:                 ex.setTypeQualifier(typeQualifier);
112:                 return ex;
113:         }
114:
115:         public LexNameToken getOldName()
116:         {
117:                 return new LexNameToken(module, new LexIdentifierToken(name, true, location));
118:         }
119:
120:         public String getFullName()
121:         {
122:                 // Flat specifications have blank module names
123:•                return (explicit ? module.length() > 0 ? module + "`" : "" : "") + name
124:                                 + (old ? "~" : ""); // NB. No qualifier
125:         }
126:
127:         public LexNameToken getNewName()
128:         {
129:                 return new LexNameToken(module, new LexIdentifierToken(name, false, location));
130:         }
131:
132:         public String getSimpleName()
133:         {
134:                 return name;
135:         }
136:
137:         public LexNameToken getPreName(ILexLocation l)
138:         {
139:                 return new LexNameToken(module, "pre_" + name, l);
140:         }
141:
142:         public LexNameToken getPostName(ILexLocation l)
143:         {
144:                 return new LexNameToken(module, "post_" + name, l);
145:         }
146:
147:         public LexNameToken getInvName(ILexLocation l)
148:         {
149:                 return new LexNameToken(module, "inv_" + name, l);
150:         }
151:
152:         public LexNameToken getOrdName(ILexLocation l)
153:         {
154:                 return new LexNameToken(module, "ord_" + name, l);
155:         }
156:
157:         public LexNameToken getEqName(ILexLocation l)
158:         {
159:                 return new LexNameToken(module, "eq_" + name, l);
160:         }
161:
162:         public LexNameToken getMinName(ILexLocation l)
163:         {
164:                 return new LexNameToken(module, "min_" + name, l);
165:         }
166:
167:         public LexNameToken getMaxName(ILexLocation l)
168:         {
169:                 return new LexNameToken(module, "max_" + name, l);
170:         }
171:
172:         public LexNameToken getInitName(ILexLocation l)
173:         {
174:                 return new LexNameToken(module, "init_" + name, l);
175:         }
176:         
177:         public boolean isReserved()
178:         {
179:                 return
180:•                        name.startsWith("pre_") ||
181:•                        name.startsWith("post_") ||
182:•                        name.startsWith("inv_") ||
183:•                        name.startsWith("eq_") ||
184:•                        name.startsWith("ord_") ||
185:•                        name.startsWith("min_") ||
186:•                        name.startsWith("max_") ||
187:•                        name.startsWith("init_");
188:         }
189:
190:         public LexNameToken getModifiedName(String classname)
191:         {
192:                 LexNameToken mod = new LexNameToken(classname, name, location, old, explicit);
193:                 mod.setTypeQualifier(typeQualifier);
194:                 return mod;
195:         }
196:
197:         public LexNameToken getModifiedName(List<PType> qualifier)
198:         {
199:                 LexNameToken mod = new LexNameToken(module, name, location, old, explicit);
200:                 mod.setTypeQualifier(qualifier);
201:                 return mod;
202:         }
203:
204:         public LexNameToken getSelfName()
205:         {
206:•                if (module.equals("CLASS"))
207:                 {
208:                         return new LexNameToken(name, "self", location);
209:                 } else
210:                 {
211:                         return new LexNameToken(module, "self", location);
212:                 }
213:         }
214:
215:         public LexNameToken getThreadName()
216:         {
217:•                if (module.equals("CLASS"))
218:                 {
219:                         LexNameToken thread = new LexNameToken(name, "thread", location);
220:                         thread.setTypeQualifier(new Vector<PType>());
221:                         return thread;
222:                 }
223:                 else
224:                 {
225:                         LexNameToken thread = new LexNameToken(module, "thread", location);
226:                         thread.setTypeQualifier(new Vector<PType>());
227:                         return thread;
228:                 }
229:         }
230:
231:         public LexNameToken getThreadName(ILexLocation loc)
232:         {
233:                 LexNameToken thread = new LexNameToken(loc.getModule(), "thread", loc);
234:                 thread.setTypeQualifier(new Vector<PType>());
235:                 return thread;
236:         }
237:
238:         public LexNameToken getPerName(ILexLocation loc)
239:         {
240:                 return new LexNameToken(module, "per_" + name, loc);
241:         }
242:
243:         @Override
244:         public ILexNameToken getMeasureName(ILexLocation loc)
245:         {
246:                 return new LexNameToken(getModule(), "measure_" + name, loc);
247:         }
248:
249:         public LexNameToken getClassName()
250:         {
251:                 return new LexNameToken("CLASS", name, location);
252:         }
253:
254:         public void setTypeQualifier(List<PType> types)
255:         {
256:•                if (hashcode != 0)
257:                 {
258:•                        if (typeQualifier == null && types != null || typeQualifier != null
259:•                                        && !typeQualifier.equals(types))
260:                         {
261:                                 throw new InternalException(2, "Cannot change type qualifier: "
262:                                                 + this + " to " + types);
263:                         }
264:                 }
265:
266:                 typeQualifier = types;
267:         }
268:
269:         /**
270:          * Basic equals method for LexNameTokens. This method does not handle type qualifiers in that case use
271:          * {@link HackLexNameToken}
272:          */
273:         @SuppressWarnings("javadoc")
274:         @Override
275:         public boolean equals(Object other)
276:         {
277:•                if (!(other instanceof ILexNameToken))
278:                 {
279:                         return false;
280:                 }
281:
282:                 ILexNameToken lother = (ILexNameToken) other;
283:
284:•                if (typeQualifier != null && lother.getTypeQualifier() != null)
285:                 {
286:                         // For testing purpose the following line can be uncommented. The Type Checker is not supose to rely on this
287:                         // equal method but use the HelpLexNameToken class for that
288:                         // throw new InternalException(-1, "Use HelpLexNameToken.isEqual to compare");
289:
290:•                } else if (typeQualifier != null && lother.getTypeQualifier() == null
291:•                                || typeQualifier == null && lother.getTypeQualifier() != null)
292:                 {
293:                         return false;
294:                 }
295:
296:                 return matches(lother);
297:         }
298:
299:         public boolean matches(ILexNameToken other)
300:         {
301:•                return module.equals(other.getModule()) && name.equals(other.getName())
302:•                                && old == other.getOld();
303:         }
304:
305:         @Override
306:         // what does this overrides?
307:         public int hashCode()
308:         {
309:•                if (hashcode == 0)
310:                 {
311:                         hashcode = module.hashCode()
312:•                                        + name.hashCode()
313:                                         + (old ? 1 : 0)
314:                                         + (typeQualifier == null ? 0
315:                                                         : typeQualifier.toString().hashCode());
316:
317:                 }
318:
319:                 return hashcode;
320:         }
321:
322:         @Override
323:         public String toString()
324:         {
325:•                return getFullName()
326:                                 + (typeQualifier == null ? "" : "("
327:                                                 + Utils.listToString(typeQualifier) + ")");
328:         }
329:
330:         public LexNameToken copy()
331:         {
332:                 LexNameToken c = new LexNameToken(module, name, location, old, explicit);
333:                 c.setTypeQualifier(typeQualifier);
334:                 return c;
335:         }
336:
337:         public int compareTo(ILexNameToken o)
338:         {
339:                 return toString().compareTo(o.toString());
340:         }
341:
342:         public ILexLocation getLocation()
343:         {
344:                 return location;
345:         }
346:
347:         public String getModule()
348:         {
349:                 return module;
350:         }
351:
352:         @Override
353:         public ILexNameToken clone()
354:         {
355:                 return copy();
356:         }
357:
358:         public List<PType> getTypeQualifier()
359:         {
360:                 return typeQualifier;
361:         }
362:
363:         public boolean isOld()
364:         {
365:                 return old;
366:         }
367:
368:         @Override
369:         public void apply(IAnalysis analysis) throws AnalysisException
370:         {
371:                 analysis.caseILexNameToken(this);
372:         }
373:
374:         @Override
375:         public <A> A apply(IAnswer<A> caller) throws AnalysisException
376:         {
377:                 return caller.caseILexNameToken(this);
378:         }
379:
380:         @Override
381:         public <Q> void apply(IQuestion<Q> caller, Q question)
382:                         throws AnalysisException
383:         {
384:                 caller.caseILexNameToken(this, question);
385:         }
386:
387:         @Override
388:         public <Q, A> A apply(IQuestionAnswer<Q, A> caller, Q question)
389:                         throws AnalysisException
390:         {
391:                 return caller.caseILexNameToken(this, question);
392:         }
393:
394:         /**
395:          * Creates a map of all field names and their value
396:          *
397:          * @param includeInheritedFields
398:          * if true all inherited fields are included
399:          * @return a a map of names to values of all fields
400:          */
401:         @Override
402:         public Map<String, Object> getChildren(Boolean includeInheritedFields)
403:         {
404:                 Map<String, Object> fields = new HashMap<String, Object>();
405:•                if (includeInheritedFields)
406:                 {
407:                         fields.putAll(super.getChildren(includeInheritedFields));
408:                 }
409:                 fields.put("module", this.module);
410:                 fields.put("name", this.name);
411:                 fields.put("old", this.old);
412:                 fields.put("explicit", this.explicit);
413:                 return fields;
414:         }
415: }