Package: NamingComparison

NamingComparison

nameinstructionbranchcomplexitylinemethod
NamingComparison(String[], IRInfo, String)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
correctLexIdentifierToken(LexIdentifierToken)
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
correctNameToken(ILexNameToken)
M: 0 C: 62
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
getNames()
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%
isModuleViolation(ILexNameToken)
M: 0 C: 2
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: * VDM Code Generator
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.codegen.analysis.violations;
23:
24: import java.util.Arrays;
25: import java.util.List;
26:
27: import org.overture.ast.intf.lex.ILexLocation;
28: import org.overture.ast.intf.lex.ILexNameToken;
29: import org.overture.ast.lex.LexIdentifierToken;
30: import org.overture.ast.lex.LexNameToken;
31: import org.overture.codegen.ir.IRInfo;
32:
33: public abstract class NamingComparison
34: {
35:         protected List<String> names;
36:         protected IRInfo irInfo;
37:         protected String correctionPrefix;
38:
39:         public NamingComparison(String[] names, IRInfo irInfo,
40:                         String correctionPrefix)
41:         {
42:                 this.names = Arrays.asList(names);
43:                 this.irInfo = irInfo;
44:                 this.correctionPrefix = correctionPrefix;
45:         }
46:
47:         public abstract boolean mustHandleNameToken(ILexNameToken nameToken);
48:
49:         public abstract boolean mustHandleLexIdentifierToken(
50:                         LexIdentifierToken lexId);
51:
52:         public boolean isModuleViolation(ILexNameToken nameToken)
53:         {
54:                 return false;
55:         }
56:
57:         public void correctNameToken(ILexNameToken nameToken)
58:         {
59:                 String newModule = nameToken.getModule();
60:•                if (names.contains(nameToken.getModule()))
61:                 {
62:                         newModule = correctionPrefix + newModule;
63:                 }
64:
65:                 String newName = nameToken.getName();
66:•                if (names.contains(nameToken.getName()))
67:                 {
68:                         newName = correctionPrefix + newName;
69:                 }
70:
71:                 ILexLocation location = nameToken.getLocation();
72:                 boolean old = nameToken.getOld();
73:                 boolean explicit = nameToken.getExplicit();
74:
75:                 LexNameToken replaceMent = new LexNameToken(newModule, newName, location, old, explicit);
76:                 nameToken.parent().replaceChild(nameToken, replaceMent);
77:         }
78:
79:         public List<String> getNames()
80:         {
81:                 return this.names;
82:         }
83:
84:         public void correctLexIdentifierToken(LexIdentifierToken lexId)
85:         {
86:                 String newName = correctionPrefix + lexId.getName();
87:
88:                 boolean old = lexId.getOld();
89:                 ILexLocation location = lexId.getLocation();
90:
91:                 LexIdentifierToken replacement = new LexIdentifierToken(newName, old, location);
92:                 lexId.parent().replaceChild(lexId, replacement);
93:         }
94: }