Package: AClassTypeAssistantTC

AClassTypeAssistantTC

nameinstructionbranchcomplexitylinemethod
AClassTypeAssistantTC(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%
findName(AClassType, ILexNameToken, NameScope)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMemberName(AClassType, ILexIdentifierToken)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasSupertype(AClassType, PType)
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%
inConstructor(Environment)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
isConstructor(PDefinition)
M: 0 C: 33
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 10
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.assistant.type;
23:
24: import org.overture.ast.assistant.IAstAssistant;
25: import org.overture.ast.definitions.AExplicitOperationDefinition;
26: import org.overture.ast.definitions.AImplicitOperationDefinition;
27: import org.overture.ast.definitions.AInheritedDefinition;
28: import org.overture.ast.definitions.PDefinition;
29: import org.overture.ast.intf.lex.ILexIdentifierToken;
30: import org.overture.ast.intf.lex.ILexNameToken;
31: import org.overture.ast.lex.LexNameToken;
32: import org.overture.ast.typechecker.NameScope;
33: import org.overture.ast.types.AClassType;
34: import org.overture.ast.types.PType;
35: import org.overture.typechecker.Environment;
36: import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory;
37:
38: public class AClassTypeAssistantTC implements IAstAssistant
39: {
40:
41:         protected ITypeCheckerAssistantFactory af;
42:
43:         public AClassTypeAssistantTC(ITypeCheckerAssistantFactory af)
44:         {
45:                 this.af = af;
46:         }
47:
48:         public LexNameToken getMemberName(AClassType cls, ILexIdentifierToken id)
49:         {
50:                 // Note: not explicit
51:                 return new LexNameToken(cls.getName().getName(), id.getName(), id.getLocation(), false, false);
52:         }
53:
54:         // TODO:Used in the TypeCheckerExpVisitor.
55:
56:         public PDefinition findName(AClassType cls, ILexNameToken tag,
57:                         NameScope scope)
58:         {
59:                 return af.createPDefinitionAssistant().findName(cls.getClassdef(), tag, scope);
60:         }
61:
62:         // Used in the SClassDefinitionAssistantTC.
63:         public boolean hasSupertype(AClassType sclass, PType other)
64:         {
65:                 return af.createSClassDefinitionAssistant().hasSupertype(sclass.getClassdef(), other);
66:         }
67:
68:         /**
69:          * Test whether a definition is a class constructor.
70:          */
71:         public boolean isConstructor(PDefinition def)
72:         {
73:•                if (def instanceof AExplicitOperationDefinition)
74:                 {
75:                         AExplicitOperationDefinition op = (AExplicitOperationDefinition)def;
76:                         return op.getIsConstructor();
77:                 }
78:•                else if (def instanceof AImplicitOperationDefinition)
79:                 {
80:                         AImplicitOperationDefinition op = (AImplicitOperationDefinition)def;
81:                         return op.getIsConstructor();
82:                 }
83:•                else if (def instanceof AInheritedDefinition)
84:                 {
85:                         AInheritedDefinition op = (AInheritedDefinition)def;
86:                         return isConstructor(op.getSuperdef());
87:                 }
88:                 
89:                 return false;
90:         }
91:
92:         /**
93:          * Test whether the calling environment indicates that we are within a constructor.
94:          */
95:         public boolean inConstructor(Environment env)
96:         {
97:                 PDefinition encl = env.getEnclosingDefinition();
98:         
99:•                if (encl != null)
100:                 {
101:                         return isConstructor(encl);
102:                 }
103:                 
104:                 return false;
105:         }
106: }