Package: AlwaysMatchingPatternChecker

AlwaysMatchingPatternChecker

nameinstructionbranchcomplexitylinemethod
AlwaysMatchingPatternChecker(ITypeCheckerAssistantFactory, String)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseAConcatenationPattern(AConcatenationPattern)
M: 23 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
caseAIdentifierPattern(AIdentifierPattern)
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%
caseAIgnorePattern(AIgnorePattern)
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%
caseARecordPattern(ARecordPattern)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseATuplePattern(ATuplePattern)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseAUnionPattern(AUnionPattern)
M: 1 C: 22
96%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 2
100%
M: 0 C: 1
100%
createNewReturnValue(INode)
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)
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%
defaultPPattern(PPattern)
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%

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.pattern;
23:
24: import org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.analysis.AnswerAdaptor;
26: import org.overture.ast.node.INode;
27: import org.overture.ast.patterns.AConcatenationPattern;
28: import org.overture.ast.patterns.AIdentifierPattern;
29: import org.overture.ast.patterns.AIgnorePattern;
30: import org.overture.ast.patterns.ARecordPattern;
31: import org.overture.ast.patterns.ATuplePattern;
32: import org.overture.ast.patterns.AUnionPattern;
33: import org.overture.ast.patterns.PPattern;
34: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
35:
36: /**
37: * Used to check if a given pattern always matches with its type.
38: *
39: * @author kel
40: */
41: public class AlwaysMatchingPatternChecker extends AnswerAdaptor<Boolean>
42: {
43:         protected final ITypeCheckerAssistantFactory af;
44:         protected final String fromModule;
45:
46:         public AlwaysMatchingPatternChecker(ITypeCheckerAssistantFactory af, String fromModule)
47:         {
48:                 this.af = af;
49:                 this.fromModule = fromModule;
50:         }
51:
52:         @Override
53:         public Boolean caseARecordPattern(ARecordPattern pattern)
54:                         throws AnalysisException
55:         {
56:                 return af.createPPatternListAssistant().alwaysMatches(pattern.getPlist());
57:         }
58:
59:         @Override
60:         public Boolean caseAIgnorePattern(AIgnorePattern pattern)
61:                         throws AnalysisException
62:         {
63:                 return true;
64:         }
65:
66:         @Override
67:         public Boolean caseAIdentifierPattern(AIdentifierPattern pattern)
68:                         throws AnalysisException
69:         {
70:                 return true;
71:         }
72:
73:         @Override
74:         public Boolean caseATuplePattern(ATuplePattern pattern)
75:                         throws AnalysisException
76:         {
77:                 return af.createPPatternListAssistant().alwaysMatches(pattern.getPlist());
78:         }
79:         
80:         @Override
81:         public Boolean caseAConcatenationPattern(AConcatenationPattern node)
82:                         throws AnalysisException
83:         {
84:•                return af.createPPatternAssistant(fromModule).alwaysMatches(node.getLeft()) &&
85:•                         af.createPPatternAssistant(fromModule).alwaysMatches(node.getRight());
86:         }
87:         
88:         @Override
89:         public Boolean caseAUnionPattern(AUnionPattern node)
90:                         throws AnalysisException
91:         {
92:•                return af.createPPatternAssistant(fromModule).alwaysMatches(node.getLeft()) &&
93:•                         af.createPPatternAssistant(fromModule).alwaysMatches(node.getRight());
94:         }
95:
96:         @Override
97:         public Boolean defaultPPattern(PPattern pattern) throws AnalysisException
98:         {
99:                 return false;
100:         }
101:
102:         @Override
103:         public Boolean createNewReturnValue(INode node) throws AnalysisException
104:         {
105:                 return false;
106:         }
107:
108:         @Override
109:         public Boolean createNewReturnValue(Object node) throws AnalysisException
110:         {
111:                 return false;
112:         }
113: }