Package: LeafTypeInfo

LeafTypeInfo

nameinstructionbranchcomplexitylinemethod
LeafTypeInfo(STypeIR, boolean)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
consCheckExp(String, String, String, NameGen)
M: 6 C: 104
95%
M: 1 C: 9
90%
M: 1 C: 5
83%
M: 2 C: 19
90%
M: 0 C: 1
100%
consSubjectCheck(String, String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
consSubjectCheckForType(String, String, String)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLeafTypesRecursively()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getType()
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%
getUtilsCallMap()
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%
static {...}
M: 0 C: 60
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
toString()
M: 20 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.codegen.vdm2jml.predgen.info;
2:
3: import java.util.HashMap;
4: import java.util.LinkedList;
5: import java.util.List;
6: import java.util.Map;
7:
8: import org.apache.log4j.Logger;
9: import org.overture.codegen.ir.STypeIR;
10: import org.overture.codegen.ir.types.ABoolBasicTypeIR;
11: import org.overture.codegen.ir.types.ACharBasicTypeIR;
12: import org.overture.codegen.ir.types.AIntNumericBasicTypeIR;
13: import org.overture.codegen.ir.types.ANat1NumericBasicTypeIR;
14: import org.overture.codegen.ir.types.ANatNumericBasicTypeIR;
15: import org.overture.codegen.ir.types.AQuoteTypeIR;
16: import org.overture.codegen.ir.types.ARatNumericBasicTypeIR;
17: import org.overture.codegen.ir.types.ARealNumericBasicTypeIR;
18: import org.overture.codegen.ir.types.ARecordTypeIR;
19: import org.overture.codegen.ir.types.AStringTypeIR;
20: import org.overture.codegen.ir.types.ATokenBasicTypeIR;
21: import org.overture.codegen.runtime.Utils;
22: import org.overture.codegen.vdm2java.JavaQuoteValueCreator;
23: import org.overture.codegen.vdm2jml.JmlGenUtil;
24: import org.overture.codegen.vdm2jml.JmlGenerator;
25: import org.overture.codegen.vdm2jml.util.NameGen;
26:
27: public class LeafTypeInfo extends AbstractTypeInfo
28: {
29:         private static final String CLASS_QUALIFIER = ".class";
30:         private static final String IS_BOOL = "is_bool";
31:         private static final String IS_NAT = "is_nat";
32:         private static final String IS_NAT1 = "is_nat1";
33:         private static final String IS_INT = "is_int";
34:         private static final String IS_RAT = "is_rat";
35:         private static final String IS_REAL = "is_real";
36:         private static final String IS_CHAR = "is_char";
37:         private static final String IS_TOKEN = "is_token";
38:         private static final String IS = "is_";
39:
40:         private STypeIR type;
41:
42:         protected Logger log = Logger.getLogger(this.getClass().getName());
43:
44:         private static Map<Class<? extends STypeIR>, String> utilsCallMap;
45:
46:         static
47:         {
48:                 utilsCallMap = new HashMap<>();
49:                 utilsCallMap.put(ABoolBasicTypeIR.class, IS_BOOL);
50:                 utilsCallMap.put(ANatNumericBasicTypeIR.class, IS_NAT);
51:                 utilsCallMap.put(ANat1NumericBasicTypeIR.class, IS_NAT1);
52:                 utilsCallMap.put(AIntNumericBasicTypeIR.class, IS_INT);
53:                 utilsCallMap.put(ARatNumericBasicTypeIR.class, IS_RAT);
54:                 utilsCallMap.put(ARealNumericBasicTypeIR.class, IS_REAL);
55:                 utilsCallMap.put(ACharBasicTypeIR.class, IS_CHAR);
56:                 utilsCallMap.put(ATokenBasicTypeIR.class, IS_TOKEN);
57:                 utilsCallMap.put(AQuoteTypeIR.class, IS);
58:                 utilsCallMap.put(ARecordTypeIR.class, IS);
59:                 utilsCallMap.put(AStringTypeIR.class, IS);
60:         }
61:
62:         public LeafTypeInfo(STypeIR type, boolean optional)
63:         {
64:                 super(optional);
65:                 this.type = type;
66:         }
67:
68:         public STypeIR getType()
69:         {
70:                 return type;
71:         }
72:
73:         @Override
74:         public String toString()
75:         {
76:•                if (isOptional())
77:                 {
78:                         return "[" + type.toString() + "]";
79:                 } else
80:                 {
81:                         return type.toString();
82:                 }
83:         }
84:
85:         @Override
86:         public List<LeafTypeInfo> getLeafTypesRecursively()
87:         {
88:                 List<LeafTypeInfo> types = new LinkedList<LeafTypeInfo>();
89:                 types.add(this);
90:
91:                 return types;
92:         }
93:
94:         @Override
95:         public String consCheckExp(String enclosingClass, String javaRootPackage,
96:                         String arg, NameGen nameGen)
97:         {
98:                 String methodName = utilsCallMap.get(type.getClass());
99:
100:•                if (methodName == null)
101:                 {
102:                         log.error("Got unhandled case");
103:                         return "true";
104:                 }
105:
106:                 String call;
107:•                if (type instanceof AQuoteTypeIR)
108:                 {
109:                         String qouteValue = ((AQuoteTypeIR) type).getValue();
110:                         String quoteType = JavaQuoteValueCreator.fullyQualifiedQuoteName(javaRootPackage, qouteValue);
111:                         call = consSubjectCheckForType(methodName, arg, quoteType);
112:•                } else if (type instanceof ARecordTypeIR)
113:                 {
114:                         ARecordTypeIR rt = (ARecordTypeIR) type;
115:                         String defClass = rt.getName().getDefiningClass();
116:                         String recPackage = JmlGenUtil.consRecPackage(defClass, javaRootPackage);
117:                         String fullyQualifiedRecType = recPackage + "."
118:                                         + rt.getName().getName();
119:
120:                         call = consSubjectCheckForType(methodName, arg, fullyQualifiedRecType);
121:•                } else if (type instanceof AStringTypeIR)
122:                 {
123:                         call = consSubjectCheckForType(methodName, arg, String.class.getSimpleName());
124:                 } else
125:                 {
126:                         call = consSubjectCheck(methodName, arg);
127:                 }
128:
129:                 // If the type is optional 'null' is also a legal value
130:•                if (isOptional())
131:                 {
132:                         return "(" + consIsNullCheck(arg) + JmlGenerator.JML_OR + call
133:                                         + ")";
134:                 }
135:
136:                 return call;
137:         }
138:
139:         private String consSubjectCheck(String methodName, String arg)
140:         {
141:                 return consSubjectCheck(Utils.class.getSimpleName(), methodName, arg);
142:         }
143:
144:         private String consSubjectCheckForType(String methodName, String arg,
145:                         String type)
146:         {
147:                 return consSubjectCheckExtraArg(Utils.class.getSimpleName(), methodName, arg, type
148:                                 + CLASS_QUALIFIER);
149:         }
150:
151:         public static Map<Class<? extends STypeIR>, String> getUtilsCallMap()
152:         {
153:                 return utilsCallMap;
154:         }
155: }