Package: OverrideAnnotation

OverrideAnnotation

nameinstructionbranchcomplexitylinemethod
OverrideAnnotation()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
check(INode)
M: 56 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
checkdef(ILexNameToken, SClassDefinition)
M: 36 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
tcAfter(AModuleModules, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(PDefinition, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(PExp, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(PStm, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcAfter(SClassDefinition, TypeCheckInfo)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
tcBefore(AModuleModules, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(PDefinition, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(PExp, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(PStm, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tcBefore(SClassDefinition, TypeCheckInfo)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
typecheckArgs()
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%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (c) 2019 Nick Battle.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of Overture
8: *
9: ******************************************************************************/
10:
11: package org.overture.annotations.provided;
12:
13: import org.overture.ast.definitions.PDefinition;
14: import org.overture.ast.definitions.SClassDefinition;
15: import org.overture.ast.definitions.SFunctionDefinition;
16: import org.overture.ast.definitions.SOperationDefinition;
17: import org.overture.ast.expressions.PExp;
18: import org.overture.ast.intf.lex.ILexNameToken;
19: import org.overture.ast.lex.Dialect;
20: import org.overture.ast.modules.AModuleModules;
21: import org.overture.ast.node.INode;
22: import org.overture.ast.statements.PStm;
23: import org.overture.config.Settings;
24: import org.overture.parser.annotations.ASTAnnotationAdapter;
25: import org.overture.typechecker.TypeCheckInfo;
26: import org.overture.typechecker.TypeChecker;
27: import org.overture.typechecker.annotations.TCAnnotation;
28:
29: public class OverrideAnnotation extends ASTAnnotationAdapter implements TCAnnotation
30: {
31:         public OverrideAnnotation()
32:         {
33:                 super();
34:         }
35:         
36:         @Override
37:         public boolean typecheckArgs()
38:         {
39:                 return false;
40:         }
41:         
42:         /**
43:          * Type checker...
44:          */
45:
46:         @Override
47:         public void tcBefore(PDefinition node, TypeCheckInfo question)
48:         {
49:                 check(node);
50:         }
51:
52:         @Override
53:         public void tcBefore(PExp node, TypeCheckInfo question)
54:         {
55:                 check(node);
56:         }
57:
58:         @Override
59:         public void tcBefore(PStm node, TypeCheckInfo question)
60:         {
61:                 check(node);
62:         }
63:
64:         @Override
65:         public void tcBefore(AModuleModules node, TypeCheckInfo question)
66:         {
67:                 check(node);
68:         }
69:
70:         @Override
71:         public void tcBefore(SClassDefinition node, TypeCheckInfo question)
72:         {
73:                 check(node);
74:         }
75:
76:         public void check(INode node)
77:         {
78:•                if (Settings.dialect == Dialect.VDM_SL)
79:                 {
80:                         TypeChecker.report(6001, "@Override not available in VDM-SL", ast.getName().getLocation());
81:                 }
82:                 
83:•                if (!ast.getArgs().isEmpty())
84:                 {
85:                         TypeChecker.report(6002, "@Override has no arguments", ast.getName().getLocation());
86:                 }
87:                 
88:•                if (node instanceof SFunctionDefinition)
89:                 {
90:                         SFunctionDefinition func = (SFunctionDefinition)node;
91:                         checkdef(func.getName(), func.getClassDefinition());
92:                 }
93:•                else if (node instanceof SOperationDefinition)
94:                 {
95:                         SOperationDefinition op = (SOperationDefinition)node;
96:                         checkdef(op.getName(), op.getClassDefinition());
97:                 }
98:                 else
99:                 {
100:                         TypeChecker.report(6003, "@Override must be a function or operation", ast.getName().getLocation());
101:                 }
102:         }
103:         
104:         private void checkdef(ILexNameToken name, SClassDefinition def)
105:         {
106:•                if (def != null)
107:                 {
108:                         boolean found = false;
109:                         
110:•                        for (PDefinition indef: def.getAllInheritedDefinitions())
111:                         {
112:•                                if (indef.getName().getModifiedName(def.getName().getName()).equals(name))
113:                                 {
114:                                         found = true;
115:                                         break;
116:                                 }
117:                         }
118:                         
119:•                        if (!found)
120:                         {
121:                                 TypeChecker.report(6004, "Definition does not @Override superclass", name.getLocation());
122:                         }
123:                 }
124:         }
125:
126:         @Override
127:         public void tcAfter(PDefinition node, TypeCheckInfo question)
128:         {
129:                 // Nothing
130:         }
131:
132:         @Override
133:         public void tcAfter(PExp node, TypeCheckInfo question)
134:         {
135:                 // Nothing
136:         }
137:
138:         @Override
139:         public void tcAfter(PStm node, TypeCheckInfo question)
140:         {
141:                 // Nothing
142:         }
143:
144:         @Override
145:         public void tcAfter(AModuleModules node, TypeCheckInfo question)
146:         {
147:                 // Nothing
148:         }
149:
150:         @Override
151:         public void tcAfter(SClassDefinition node, TypeCheckInfo question)
152:         {
153:                 // Nothing
154:         }
155: }