Package: PONotCaseContext

PONotCaseContext

nameinstructionbranchcomplexitylinemethod
PONotCaseContext(PPattern, PType, PExp, IPogAssistantFactory)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getCaseExp()
M: 0 C: 79
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
getContext()
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%
getContextNode(PExp)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.pog.contexts;
25:
26: import java.util.List;
27:
28: import org.overture.ast.expressions.AEqualsBinaryExp;
29: import org.overture.ast.expressions.AExistsExp;
30: import org.overture.ast.expressions.AImpliesBooleanBinaryExp;
31: import org.overture.ast.expressions.ANotUnaryExp;
32: import org.overture.ast.expressions.PExp;
33: import org.overture.ast.factory.AstExpressionFactory;
34: import org.overture.ast.patterns.PMultipleBind;
35: import org.overture.ast.patterns.PPattern;
36: import org.overture.ast.types.PType;
37: import org.overture.pog.pub.IPogAssistantFactory;
38: import org.overture.pog.utility.ContextHelper;
39: import org.overture.pog.utility.UniqueNameGenerator;
40:
41: public class PONotCaseContext extends POContext
42: {
43:         public final PPattern pattern;
44:         public final PType type;
45:         public final PExp exp;
46:         public final IPogAssistantFactory assistantFactory;
47:
48:         public PONotCaseContext(PPattern pattern, PType type, PExp exp,
49:                         IPogAssistantFactory assistantFactory)
50:         {
51:                 this.pattern = pattern;
52:                 this.type = type;
53:                 this.exp = exp;
54:                 this.assistantFactory = assistantFactory;
55:         }
56:
57:         @Override
58:         public PExp getContextNode(PExp stitch)
59:         {
60:                 AImpliesBooleanBinaryExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(getCaseExp(), stitch);
61:                 return impliesExp;
62:         }
63:
64:         private PExp getCaseExp()
65:         {
66:•                if (assistantFactory.createPPatternAssistant(null).isSimple(pattern))
67:                 {
68:                         ANotUnaryExp notExp = new ANotUnaryExp();
69:                         AEqualsBinaryExp equalsExp = AstExpressionFactory.newAEqualsBinaryExp(patternToExp(pattern.clone(), assistantFactory, new UniqueNameGenerator(exp)), exp.clone());
70:                         notExp.setExp(equalsExp);
71:                         return notExp;
72:
73:                 } else
74:                 {
75:
76:                         ANotUnaryExp notExp = new ANotUnaryExp();
77:                         AExistsExp existsExp = new AExistsExp();
78:                         List<PMultipleBind> bindList = ContextHelper.bindListFromPattern(pattern.clone(), type.clone());
79:
80:                         existsExp.setBindList(bindList);
81:                         PExp matching = patternToExp(pattern,assistantFactory,new UniqueNameGenerator(exp));
82:                         AEqualsBinaryExp equalsExp = AstExpressionFactory.newAEqualsBinaryExp(matching, exp.clone());
83:
84:                         existsExp.setPredicate(equalsExp);
85:                         notExp.setExp(existsExp);
86:                         return notExp;
87:                 }
88:
89:         }
90:
91:         @Override
92:         public String getContext()
93:         {
94:                 return "";
95:         }
96: }