Package: NameGen

NameGen

nameinstructionbranchcomplexitylinemethod
NameGen()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getName(String)
M: 55 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.ide.ui.templates;
2:
3: import java.util.HashSet;
4: import java.util.Set;
5:
6: /**
7: *TODO Temp class which has to be removed and replaced with the NameGen from package org.overture.codegen.vdm2jml.util; since it duplicates functionality
8: *
9: * @author mlp
10: */
11: public class NameGen
12: {
13:         private Set<String> toAvoid;
14:         
15:         public NameGen()
16:         {
17:                 this.toAvoid = new HashSet<String>();
18:         }
19:         
20:         public String getName(String suggestion)
21:         {
22:•                if (!toAvoid.contains(suggestion))
23:                 {
24:                         toAvoid.add(suggestion);
25:                         return suggestion;
26:                 } else
27:                 {
28:                         int counter = 1;
29:
30:                         String prefix = suggestion + "_";
31:                         
32:                         String newSuggestion = prefix + counter;
33:
34:•                        while (toAvoid.contains(newSuggestion))
35:                         {
36:                                 counter++;
37:                                 newSuggestion = prefix + counter;
38:                         }
39:                         
40:                         toAvoid.add(newSuggestion);
41:                         return newSuggestion;
42:                 }
43:         }
44: }