Package: FunctionChecker

FunctionChecker

nameinstructionbranchcomplexitylinemethod
FunctionChecker(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%
caseAExplicitFunctionDefinition(AExplicitFunctionDefinition)
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%
caseAImplicitFunctionDefinition(AImplicitFunctionDefinition)
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%
caseAImportedDefinition(AImportedDefinition)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
caseAInheritedDefinition(AInheritedDefinition)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
caseALocalDefinition(ALocalDefinition)
M: 2 C: 40
95%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 0 C: 4
100%
M: 0 C: 1
100%
caseARenamedDefinition(ARenamedDefinition)
M: 0 C: 7
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%
defaultPDefinition(PDefinition)
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%
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: /*
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 org.overture.ast.analysis.AnalysisException;
25: import org.overture.ast.analysis.AnswerAdaptor;
26: import org.overture.ast.definitions.AExplicitFunctionDefinition;
27: import org.overture.ast.definitions.AImplicitFunctionDefinition;
28: import org.overture.ast.definitions.AImportedDefinition;
29: import org.overture.ast.definitions.AInheritedDefinition;
30: import org.overture.ast.definitions.ALocalDefinition;
31: import org.overture.ast.definitions.ARenamedDefinition;
32: import org.overture.ast.definitions.PDefinition;
33: import org.overture.ast.node.INode;
34: import org.overture.ast.types.AParameterType;
35: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
36:
37: /**
38: * This class implements a way to check if a node is a function.
39: *
40: * @author kel
41: */
42:•public class FunctionChecker extends AnswerAdaptor<Boolean>
43: {
44:         protected ITypeCheckerAssistantFactory af;
45:
46:         public FunctionChecker(ITypeCheckerAssistantFactory af)
47:         {
48:                 this.af = af;
49:         }
50:
51:         @Override
52:         public Boolean caseAExplicitFunctionDefinition(
53:                         AExplicitFunctionDefinition node) throws AnalysisException
54:         {
55:                 return true;
56:         }
57:
58:         @Override
59:         public Boolean caseAImplicitFunctionDefinition(
60:                         AImplicitFunctionDefinition node) throws AnalysisException
61:         {
62:                 return true;
63:         }
64:
65:         @Override
66:         public Boolean caseAImportedDefinition(AImportedDefinition node)
67:                         throws AnalysisException
68:         {
69:                 return node.getDef().apply(THIS);
70:         }
71:
72:         @Override
73:         public Boolean caseAInheritedDefinition(AInheritedDefinition node)
74:                         throws AnalysisException
75:         {
76:                 return node.getSuperdef().apply(THIS);
77:         }
78:
79:         @Override
80:         public Boolean caseALocalDefinition(ALocalDefinition node)
81:                         throws AnalysisException
82:         {
83:•                return node.getValueDefinition() != null
84:•                                || af.createPTypeAssistant().isType(af.createPDefinitionAssistant().getType(node), AParameterType.class) ? false
85:•                                : !af.createPTypeAssistant().isUnknown(af.createPDefinitionAssistant().getType(node)) &&
86:•                                 af.createPTypeAssistant().isFunction(af.createPDefinitionAssistant().getType(node), null);
87:         }
88:
89:         @Override
90:         public Boolean caseARenamedDefinition(ARenamedDefinition node)
91:                         throws AnalysisException
92:         {
93:                 return node.getDef().apply(THIS);
94:         }
95:
96:         @Override
97:         public Boolean defaultPDefinition(PDefinition node)
98:                         throws AnalysisException
99:         {
100:                 return false;
101:         }
102:
103:         @Override
104:         public Boolean createNewReturnValue(INode node)
105:         {
106:•                assert false : "should not happen";
107:                 return null;
108:         }
109:
110:         @Override
111:         public Boolean createNewReturnValue(Object node)
112:         {
113:•                assert false : "should not happen";
114:                 return null;
115:         }
116: }