@@ -13,6 +13,7 @@ import asmeta.definitions.domains.MapDomain
13
13
import asmeta.definitions.domains.SequenceDomain
14
14
import asmeta.definitions.domains.EnumTd
15
15
import asmeta.definitions.MonitoredFunction
16
+ import org.asmeta.asm2java.ToString
16
17
17
18
class JavaASMGenerator2 extends AsmToJavaGenerator {
18
19
@@ -118,8 +119,8 @@ class JavaASMGenerator2 extends AsmToJavaGenerator {
118
119
coverControlled();' ' ' );
119
120
120
121
sb. append(System . lineSeparator)
121
- if (finalStateConditions !== null || ! finalStateConditions. isEmpty){
122
- sb. append(" \t\t\t\t " ). append(' ' ' /*final state condition */' ' ' )
122
+ if (finalStateConditions !== null && ! finalStateConditions. isEmpty){
123
+ sb. append(" \t\t\t\t " ). append(' ' ' /* final state condition */' ' ' )
123
124
sb. append(System . lineSeparator)
124
125
sb. append(" \t\t\t\t " ). append(' ' ' if(isFinalState()){
125
126
System.out.println("\n <Stato finale>");
@@ -141,7 +142,7 @@ class JavaASMGenerator2 extends AsmToJavaGenerator {
141
142
sb. append(" \t\t " ). append(' ' ' // Controlled getters' ' ' );
142
143
sb. append(System . lineSeparator)
143
144
144
- controllerGetter (asm,sb);
145
+ controlledGetter (asm,sb);
145
146
146
147
sb. append(System . lineSeparator)
147
148
sb. append(" \t " ). append(' ' ' // Cover functions' ' ' );
@@ -211,34 +212,74 @@ class JavaASMGenerator2 extends AsmToJavaGenerator {
211
212
def coverBranches (Asm asm , StringBuffer sb ) {
212
213
for (fd : asm. headerSection. signature. function){
213
214
if (fd instanceof MonitoredFunction || fd instanceof ControlledFunction ){
214
- sb. append(" \t " ). append(' ' ' private void cover_«fd.name»(){' ' ' );
215
- if (fd. codomain instanceof EnumTd ){
216
- sb. append(System . lineSeparator)
217
- sb. append(" \t\t " ). append(' ' ' switch(this.get_«fd.name»()){' ' ' );
218
- var codomainContents = fd. codomain. eContents;
219
- for (enumerativeLog: codomainContents){
220
- val startIndex = enumerativeLog. toString(). indexOf(" symbol: " ) + " symbol: " . length
221
- val endIndex = enumerativeLog. toString(). indexOf(" )" , startIndex)
222
- val symbol = enumerativeLog. toString(). substring(startIndex, endIndex)
215
+ if (fd. domain == = null ){
216
+ sb. append(" \t " ). append(' ' ' private void cover_«fd.name»(){' ' ' );
217
+ if (fd. codomain instanceof EnumTd ){
218
+ sb. append(System . lineSeparator)
219
+ sb. append(" \t\t " ). append(' ' ' switch(this.get_«fd.name»()){' ' ' );
220
+ /* metodo più rapido ma meno consistente
221
+ var codomainContents = fd.codomain.eContents;
222
+ for(enumerativeLog: codomainContents){
223
+ val startIndex = enumerativeLog.toString().indexOf("symbol: ") + "symbol: ".length
224
+ val endIndex = enumerativeLog.toString().indexOf(")", startIndex)
225
+ val symbol = enumerativeLog.toString().substring(startIndex, endIndex)
226
+ sb.append(System.lineSeparator)
227
+ sb.append("\t\t\t").append('''case «symbol» :
228
+ System.out.println("Branch «fd.codomain.name» «symbol» covered");
229
+ // Branch «fd.codomain.name» «symbol» covered
230
+ break;''');
231
+ }
232
+ */
233
+ /* Metodo normale */
234
+ for (dd : asm. headerSection. signature. domain){
235
+ if (dd. equals(fd. codomain)){
236
+ if (dd instanceof EnumTd ){
237
+ for (var int i = 0 ; i < dd. element. size; i++ ) {
238
+ var symbol = new ToString (asm). visit(dd. element. get(i))
239
+ sb. append(System . lineSeparator)
240
+ sb. append(" \t\t\t " ). append(' ' ' case «symbol» :
241
+ System.out.println("Branch «fd.codomain.name» «symbol» covered");
242
+ // Branch «fd.codomain.name» «symbol» covered
243
+ break;' ' ' );
244
+ }
245
+ }
246
+ }
247
+ }
248
+ /* */
249
+ sb. append(System . lineSeparator)
250
+ sb. append(" \t\t\t " )sb. append(' ' ' }' ' ' );
251
+ }
252
+ else {
253
+ sb. append(System . lineSeparator)
254
+ sb. append(" \t\t " ). append(' ' ' this.get_«fd.name»();' ' ' );
223
255
sb. append(System . lineSeparator)
224
- sb. append(" \t\t\t " ). append(' ' ' case «symbol» :
225
- System.out.println("Branch «fd.codomain.name» «symbol» covered");
226
- // Branch «fd.codomain.name» «symbol» covered
227
- break;' ' ' );
256
+ sb. append(" \t\t " ). append(' ' ' //1 Branch covered' ' ' );
228
257
}
229
258
sb. append(System . lineSeparator)
230
- sb. append(" \t\t\t " )sb. append(' ' ' }' ' ' );
231
- }
232
- else {
259
+ sb. append(" \t " ). append(' ' ' }' ' ' );
233
260
sb. append(System . lineSeparator)
234
- sb. append(" \t\t " ). append(' ' ' this.get_«fd.name»();' ' ' );
235
261
sb. append(System . lineSeparator)
236
- sb. append(" \t\t " ). append(' ' ' //1 Branch covered' ' ' );
237
262
}
238
- sb. append(System . lineSeparator)
239
- sb. append(" \t " ). append(' ' ' }' ' ' );
240
- sb. append(System . lineSeparator)
241
- sb. append(System . lineSeparator)
263
+ else { // fd.domain != null
264
+ for (dd : asm. headerSection. signature. domain){
265
+ if (dd. equals(fd. domain)){
266
+ if (dd instanceof EnumTd ){
267
+ sb. append(" \t " ). append(' ' ' private void cover_«fd.name»(){' ' ' );
268
+ for (var int i = 0 ; i < dd. element. size; i++ ) {
269
+ var symbol = new ToString (asm). visit(dd. element. get(i))
270
+ sb. append(System . lineSeparator)
271
+ sb. append(" \t\t " ). append(' ' ' this.get_«fd.name»_«symbol»();' ' ' );
272
+ }
273
+ sb. append(System . lineSeparator)
274
+ sb. append(" \t\t " ). append(' ' ' // «dd.element.size» Branch covered' ' ' );
275
+ sb. append(System . lineSeparator)
276
+ sb. append(" \t " ). append(' ' ' }' ' ' );
277
+ sb. append(System . lineSeparator)
278
+ sb. append(System . lineSeparator)
279
+ }
280
+ }
281
+ }
282
+ }
242
283
}
243
284
}
244
285
}
@@ -287,7 +328,7 @@ class JavaASMGenerator2 extends AsmToJavaGenerator {
287
328
}
288
329
}
289
330
290
- def controllerGetter (Asm asm , StringBuffer sb ) {
331
+ def controlledGetter (Asm asm , StringBuffer sb ) {
291
332
var asmName = asm. name;
292
333
for (fd : asm. headerSection. signature. function) {
293
334
if (fd instanceof ControlledFunction ) {
@@ -327,6 +368,38 @@ class JavaASMGenerator2 extends AsmToJavaGenerator {
327
368
' ' ' );
328
369
}
329
370
}
371
+ else { // TODO: Da sistemare i getter per le funzioni con Dominio -> Codominio
372
+
373
+ for (dd : asm. headerSection. signature. domain){
374
+ if (dd. equals(fd. domain)){
375
+ if (dd instanceof EnumTd ){
376
+ for (var int i = 0 ; i < dd. element. size; i++ ) {
377
+ var symbol = new ToString (asm). visit(dd. element. get(i))
378
+ sb. append(System . lineSeparator)
379
+ if (fd. codomain instanceof ConcreteDomain ){ // considero subsetOf Integer
380
+ sb. append(" \t " ). append(' ' ' public int get_«fd.name»_«symbol»(){' ' ' );
381
+ sb. append(System . lineSeparator)
382
+ sb. append(" \t\t " ). append(' ' ' return this.esecuzione.«fd.name».oldValues.get(' ' ' );
383
+ sb. append(System . lineSeparator)
384
+ sb. append(" \t\t\t " ). append(' ' ' this.esecuzione.«fd.domain.name»_elemsList.get(«i»)).value;' ' ' );
385
+ sb. append(System . lineSeparator)
386
+ sb. append(" \t " ). append(' ' ' }' ' ' );
387
+ }
388
+ else {
389
+ sb. append(" \t " ). append(' ' ' public «asmName».«fd.codomain.name» get_«fd.name»_«symbol»(){' ' ' );
390
+ sb. append(System . lineSeparator)
391
+ sb. append(" \t\t " ). append(' ' ' return this.esecuzione.«fd.name».oldValues.get(' ' ' );
392
+ sb. append(System . lineSeparator)
393
+ sb. append(" \t\t\t " ). append(' ' ' this.esecuzione.«fd.domain.name»_elemsList.get(«i»));' ' ' );
394
+ sb. append(System . lineSeparator)
395
+ sb. append(" \t " ). append(' ' ' }' ' ' );
396
+ }
397
+ sb. append(System . lineSeparator)
398
+ }
399
+ }
400
+ }
401
+ }
402
+ }
330
403
}
331
404
}
332
405
}
@@ -532,7 +605,7 @@ class JavaASMGenerator2 extends AsmToJavaGenerator {
532
605
}
533
606
534
607
def setIsFinalState (Asm asm , StringBuffer sb ){
535
- if (finalStateConditions !== null || ! finalStateConditions. isEmpty){
608
+ if (finalStateConditions !== null && ! finalStateConditions. isEmpty){
536
609
sb. append(System . lineSeparator)
537
610
sb. append(" \t " ). append(' ' ' // final state condition' ' ' )
538
611
sb. append(System . lineSeparator)
0 commit comments