Package: PatternAlwaysMatchesVisitor

PatternAlwaysMatchesVisitor

nameinstructionbranchcomplexitylinemethod
PatternAlwaysMatchesVisitor()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
alwaysMatches(List)
M: 2 C: 19
90%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 4
80%
M: 0 C: 1
100%
caseAIdentifierPattern(AIdentifierPattern)
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%
caseAIgnorePattern(AIgnorePattern)
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%
caseAObjectPattern(AObjectPattern)
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
caseARecordPattern(ARecordPattern)
M: 0 C: 5
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: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createNewReturnValue(INode)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
createNewReturnValue(Object)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
defaultPPattern(PPattern)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 2 C: 6
75%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: package org.overture.pog.utility;
2:
3: import java.util.LinkedList;
4: import java.util.List;
5:
6: import org.overture.ast.analysis.AnalysisException;
7: import org.overture.ast.analysis.AnswerAdaptor;
8: import org.overture.ast.node.INode;
9: import org.overture.ast.patterns.AIdentifierPattern;
10: import org.overture.ast.patterns.AIgnorePattern;
11: import org.overture.ast.patterns.ANamePatternPair;
12: import org.overture.ast.patterns.AObjectPattern;
13: import org.overture.ast.patterns.ARecordPattern;
14: import org.overture.ast.patterns.ATuplePattern;
15: import org.overture.ast.patterns.PPattern;
16:
17:•public class PatternAlwaysMatchesVisitor extends AnswerAdaptor<Boolean>
18: {
19:         public PatternAlwaysMatchesVisitor()
20:         {
21:         }
22:
23:         private Boolean alwaysMatches(List<PPattern> plist)
24:                         throws AnalysisException
25:         {
26:•                for (PPattern p : plist)
27:                 {
28:•                        if (!p.apply(this))
29:                         {
30:                                 return Boolean.FALSE;
31:                         }
32:                 }
33:
34:                 return Boolean.TRUE;
35:         }
36:
37:         @Override
38:         public Boolean defaultPPattern(PPattern node) throws AnalysisException
39:         {
40:                 return Boolean.FALSE; // Most patterns do not always match
41:         }
42:
43:         /**
44:          * First, literal patterns always match:
45:          *
46:          * @param node
47:          * @return
48:          * @throws AnalysisException
49:          */
50:
51:         @Override
52:         public Boolean caseAIdentifierPattern(AIdentifierPattern node)
53:                         throws AnalysisException
54:         {
55:                 return Boolean.TRUE;
56:         }
57:
58:         @Override
59:         public Boolean caseAIgnorePattern(AIgnorePattern node)
60:                         throws AnalysisException
61:         {
62:                 return Boolean.TRUE;
63:         }
64:
65:         /**
66:          * Now, a couple of patterns involve recursive calls to AND their components.
67:          *
68:          * @param node
69:          * @return
70:          * @throws AnalysisException
71:          */
72:
73:         @Override
74:         public Boolean caseARecordPattern(ARecordPattern node)
75:                         throws AnalysisException
76:         {
77:                 return alwaysMatches(node.getPlist());
78:         }
79:
80:         @Override
81:         public Boolean caseATuplePattern(ATuplePattern node)
82:                         throws AnalysisException
83:         {
84:                 return alwaysMatches(node.getPlist());
85:         }
86:
87:         @Override
88:         public Boolean caseAObjectPattern(AObjectPattern node)
89:                         throws AnalysisException
90:         {
91:                 LinkedList<PPattern> list = new LinkedList<PPattern>();
92:                 
93:•                for (ANamePatternPair npp: node.getFields())
94:                 {
95:                         list.add(npp.getPattern());
96:                 }
97:                 
98:                 return alwaysMatches(list);
99:         }
100:
101:         @Override
102:         public Boolean createNewReturnValue(INode node)
103:         {
104:•                assert false : "Should not happen";
105:                 return null;
106:         }
107:
108:         @Override
109:         public Boolean createNewReturnValue(Object node)
110:         {
111:•                assert false : "Should not happen";
112:                 return null;
113:         }
114: }