Package: VdmAstAnalysis$ViolationAnalysisApplication

VdmAstAnalysis$ViolationAnalysisApplication

nameinstructionbranchcomplexitylinemethod
VdmAstAnalysis.ViolationAnalysisApplication(VdmAstAnalysis, ViolationAnalysis)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
applyViolationVisitor(INode, ViolationAnalysis)
M: 3 C: 7
70%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 3
60%
M: 0 C: 1
100%
execute(INode)
M: 0 C: 6
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.HashSet;
25: import java.util.List;
26: import java.util.Set;
27:
28: import org.overture.ast.analysis.AnalysisException;
29: import org.overture.ast.node.INode;
30: import org.overture.codegen.assistant.AssistantManager;
31:
32: public class VdmAstAnalysis
33: {
34:         private AssistantManager assistantManager;
35:
36:         public VdmAstAnalysis(AssistantManager assistantManager)
37:         {
38:                 this.assistantManager = assistantManager;
39:         }
40:
41:         public Set<Violation> usesIllegalNames(List<? extends INode> nodes,
42:                         NamingComparison comparison) throws AnalysisException
43:         {
44:                 NameViolationAnalysis namingAnalysis = new NameViolationAnalysis(assistantManager, comparison);
45:                 ViolationAnalysisApplication application = new ViolationAnalysisApplication(namingAnalysis);
46:
47:                 return findViolations(nodes, application);
48:         }
49:
50:         private Set<Violation> findViolations(List<? extends INode> nodes,
51:                         ViolationAnalysisApplication application) throws AnalysisException
52:         {
53:                 Set<Violation> allViolations = new HashSet<Violation>();
54:
55:                 for (INode currentNode : nodes)
56:                 {
57:                         List<Violation> currentViolations = application.execute(currentNode);
58:
59:                         if (!currentViolations.isEmpty())
60:                         {
61:                                 allViolations.addAll(currentViolations);
62:                         }
63:                 }
64:
65:                 return allViolations;
66:         }
67:
68:         private class ViolationAnalysisApplication
69:         {
70:                 private ViolationAnalysis violationAnalysis;
71:
72:                 public ViolationAnalysisApplication(ViolationAnalysis violationAnalysis)
73:                 {
74:                         this.violationAnalysis = violationAnalysis;
75:                 }
76:
77:                 public List<Violation> execute(INode node) throws AnalysisException
78:                 {
79:                         return applyViolationVisitor(node, violationAnalysis);
80:                 }
81:
82:                 private List<Violation> applyViolationVisitor(INode node,
83:                                 ViolationAnalysis analysis) throws AnalysisException
84:                 {
85:                         try
86:                         {
87:                                 node.apply(analysis);
88:                         } catch (AnalysisException e)
89:                         {
90:                                 throw e;
91:                         }
92:
93:                         return analysis.getViolations();
94:                 }
95:         }
96: }