Package: UniqueNameGenerator

UniqueNameGenerator

nameinstructionbranchcomplexitylinemethod
UniqueNameGenerator(INode)
M: 0 C: 42
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
getUnique(String)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
handleLocation(ILexLocation)
M: 2 C: 5
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 2
67%
M: 0 C: 1
100%

Coverage

1: package org.overture.pog.utility;
2:
3: import org.overture.ast.definitions.PDefinition;
4: import org.overture.ast.expressions.PExp;
5: import org.overture.ast.intf.lex.ILexLocation;
6: import org.overture.ast.intf.lex.ILexNameToken;
7: import org.overture.ast.lex.LexNameToken;
8: import org.overture.ast.node.INode;
9:
10: /**
11: * A class to create unique names, for use during PO generation. The module/class and location are set during
12: * construction from the node passed in (though must be a PExp or PDefinition to do this).
13: *
14: * @author Nick Battle
15: */
16: public class UniqueNameGenerator
17: {
18:         protected final ILexLocation location;
19:         protected final String module;
20:         protected int counter = 0;
21:
22:         public UniqueNameGenerator(INode node)
23:         {
24:
25:•                if (node instanceof PExp)
26:                 {
27:                         location = ((PExp) node).getLocation();
28:                         module = handleLocation(location);
29:•                } else if (node instanceof PDefinition)
30:                 {
31:                         location = ((PDefinition) node).getLocation();
32:                         module = handleLocation(location);
33:                 } else
34:                 {
35:                         location = null;
36:                         module = null;
37:                 }
38:         }
39:
40:         public ILexNameToken getUnique(String name)
41:         {
42:                 return new LexNameToken(module, name + ++counter, location);
43:         }
44:
45:         // guard against null locations
46:         private String handleLocation(ILexLocation location)
47:         {
48:
49:•                if (location != null)
50:                 {
51:                         return location.getModule();
52:                 } else
53:                 {
54:                         return null;
55:                 }
56:
57:         }
58: }