Package: DefinitionEqualityChecker

DefinitionEqualityChecker

nameinstructionbranchcomplexitylinemethod
DefinitionEqualityChecker(ITypeCheckerAssistantFactory)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
caseAEqualsDefinition(AEqualsDefinition, Object)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
caseAMultiBindListDefinition(AMultiBindListDefinition, Object)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
caseAMutexSyncDefinition(AMutexSyncDefinition, Object)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
caseAThreadDefinition(AThreadDefinition, Object)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
caseAValueDefinition(AValueDefinition, Object)
M: 47 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(INode, Object)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object, Object)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
defaultPDefinition(PDefinition, Object)
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%
equalsBaseCase(PDefinition, Object)
M: 2 C: 22
92%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 1 C: 4
80%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%~
3: * The VDM Type Checker
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.typechecker.utilities;
23:
24: import java.util.Iterator;
25:
26: import org.overture.ast.analysis.AnalysisException;
27: import org.overture.ast.analysis.QuestionAnswerAdaptor;
28: import org.overture.ast.definitions.AEqualsDefinition;
29: import org.overture.ast.definitions.AMultiBindListDefinition;
30: import org.overture.ast.definitions.AMutexSyncDefinition;
31: import org.overture.ast.definitions.AThreadDefinition;
32: import org.overture.ast.definitions.AValueDefinition;
33: import org.overture.ast.definitions.PDefinition;
34: import org.overture.ast.node.INode;
35: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
36:
37: /**
38: * This class implements a way to check equality of definitions
39: *
40: * @author kel
41: */
42: public class DefinitionEqualityChecker extends
43:                 QuestionAnswerAdaptor<Object, Boolean>
44: {
45:
46:         protected ITypeCheckerAssistantFactory af;
47:
48:         public DefinitionEqualityChecker(ITypeCheckerAssistantFactory af)
49:         {
50:                 this.af = af;
51:         }
52:
53:         @Override
54:         public Boolean caseAEqualsDefinition(AEqualsDefinition node, Object other)
55:                         throws AnalysisException
56:         {
57:•                if (other instanceof AEqualsDefinition)
58:                 {
59:                         return node.toString().equals(other.toString());
60:                 }
61:
62:                 return false;
63:         }
64:
65:         @Override
66:         public Boolean caseAMultiBindListDefinition(AMultiBindListDefinition node,
67:                         Object other) throws AnalysisException
68:         {
69:•                if (other instanceof AMultiBindListDefinition)
70:                 {
71:                         return node.toString().equals(other.toString());
72:                 }
73:
74:                 return false;
75:         }
76:
77:         @Override
78:         public Boolean caseAMutexSyncDefinition(AMutexSyncDefinition node,
79:                         Object other) throws AnalysisException
80:         {
81:•                if (other instanceof AMutexSyncDefinition)
82:                 {
83:                         return node.toString().equals(other.toString());
84:                 }
85:
86:                 return false;
87:         }
88:
89:         @Override
90:         public Boolean caseAThreadDefinition(AThreadDefinition node, Object other)
91:                         throws AnalysisException
92:         {
93:•                if (other instanceof AThreadDefinition)
94:                 {
95:                         AThreadDefinition tho = (AThreadDefinition) other;
96:                         return tho.getOperationName().equals(node.getOperationName());
97:                 }
98:
99:                 return false;
100:         }
101:
102:         @Override
103:         public Boolean caseAValueDefinition(AValueDefinition node, Object other)
104:                         throws AnalysisException
105:         {
106:•                if (other instanceof AValueDefinition)
107:                 {
108:                         AValueDefinition vdo = (AValueDefinition) other;
109:
110:•                        if (node.getDefs().size() == vdo.getDefs().size())
111:                         {
112:                                 Iterator<PDefinition> diter = vdo.getDefs().iterator();
113:
114:•                                for (PDefinition d : node.getDefs())
115:                                 {
116:•                                        if (!af.createPDefinitionAssistant().equals(diter.next(), d))
117:                                         {
118:                                                 return false;
119:                                         }
120:                                 }
121:
122:                                 return true;
123:                         }
124:                 }
125:
126:                 return false;
127:         }
128:
129:         @Override
130:         public Boolean defaultPDefinition(PDefinition node, Object other)
131:                         throws AnalysisException
132:         {
133:                 return equalsBaseCase(node, other);
134:         }
135:
136:         private boolean equalsBaseCase(PDefinition def, Object other) // Used for sets of definitions.
137:         {
138:•                if (other instanceof PDefinition)
139:                 {
140:                         PDefinition odef = (PDefinition) other;
141:•                        return def.getName() != null && odef.getName() != null
142:•                                        && def.getName().equals(odef.getName());
143:                 }
144:                 return false;
145:         }
146:
147:         @Override
148:         public Boolean createNewReturnValue(INode node, Object question)
149:         {
150:                 return false;
151:         }
152:
153:         @Override
154:         public Boolean createNewReturnValue(Object node, Object question)
155:         {
156:                 return false;
157:         }
158: }