Package: NameViolationAnalysis

NameViolationAnalysis

nameinstructionbranchcomplexitylinemethod
NameViolationAnalysis(AssistantManager, NamingComparison)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
defaultInINode(INode)
M: 0 C: 67
100%
M: 2 C: 12
86%
M: 2 C: 6
75%
M: 0 C: 16
100%
M: 0 C: 1
100%
moduleNeedsHandling(SClassDefinition)
M: 1 C: 11
92%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 2
100%
M: 0 C: 1
100%
registerViolation(String, ILexLocation)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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 org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.definitions.SClassDefinition;
26: import org.overture.ast.intf.lex.ILexLocation;
27: import org.overture.ast.intf.lex.ILexNameToken;
28: import org.overture.ast.lex.LexIdentifierToken;
29: import org.overture.ast.node.INode;
30: import org.overture.codegen.assistant.AssistantManager;
31:
32: public class NameViolationAnalysis extends ViolationAnalysis
33: {
34:         private NamingComparison comparison;
35:
36:         public NameViolationAnalysis(AssistantManager assistantManager,
37:                         NamingComparison comparison)
38:         {
39:                 super(assistantManager);
40:                 this.comparison = comparison;
41:         }
42:
43:         @Override
44:         public void defaultInINode(INode node) throws AnalysisException
45:         {
46:•                if (node instanceof ILexNameToken)
47:                 {
48:                         ILexNameToken nameToken = (ILexNameToken) node;
49:
50:•                        if (comparison.mustHandleNameToken(nameToken))
51:                         {
52:                                 comparison.correctNameToken(nameToken);
53:
54:                                 SClassDefinition enclosingClass = node.getAncestor(SClassDefinition.class);
55:
56:•                                if (moduleNeedsHandling(enclosingClass))
57:                                 {
58:•                                        if (!comparison.isModuleViolation(nameToken))
59:                                         {
60:                                                 registerViolation(nameToken.getName(), nameToken.getLocation());
61:                                         }
62:                                 }
63:                         }
64:•                } else if (node instanceof LexIdentifierToken)
65:                 {
66:                         LexIdentifierToken lexId = (LexIdentifierToken) node;
67:
68:•                        if (comparison.mustHandleLexIdentifierToken(lexId))
69:                         {
70:                                 comparison.correctLexIdentifierToken(lexId);
71:
72:                                 SClassDefinition enclosingClass = node.getAncestor(SClassDefinition.class);
73:
74:•                                if (moduleNeedsHandling(enclosingClass))
75:                                 {
76:                                         registerViolation(lexId.getName(), lexId.getLocation());
77:                                 }
78:                         }
79:                 }
80:         }
81:
82:         private boolean moduleNeedsHandling(SClassDefinition enclosingClass)
83:         {
84:•                return enclosingClass != null
85:•                                && !assistantManager.getDeclAssistant().isLibrary(enclosingClass);
86:         }
87:
88:         private void registerViolation(String name, ILexLocation location)
89:         {
90:                 Violation violation = new Violation(name, location, assistantManager.getLocationAssistant());
91:                 addViolation(violation);
92:         }
93: }