-
Notifications
You must be signed in to change notification settings - Fork 8
/
CGCondition.java
1656 lines (1383 loc) · 52 KB
/
CGCondition.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************
* Copyright (c) 2003--2024 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
/* Package: CSTL */
import java.util.Vector;
import javax.swing.*;
public class CGCondition
{ String stereotype = "";
String variable = "";
boolean positive = true;
String quantifier = "";
boolean isSubstitute = false;
// e/x means replace x by e
boolean isMatches = false;
// compare variable to stereotype
boolean isWith = false;
boolean isNested = false;
public CGCondition()
{ }
public CGCondition(String prop, String var)
{ stereotype = prop;
variable = var;
}
public CGCondition(Expression expr)
{ // _i = stereo or _i /= stereo
if (expr instanceof BinaryExpression)
{ BinaryExpression ee = (BinaryExpression) expr;
Vector vars = ee.metavariables();
if (vars.size() > 0)
{ variable = (String) vars.get(0); }
else
{ variable = "_1"; }
if ("/=".equals(ee.getOperator()))
{ positive = false; }
stereotype = ee.getRight() + "";
}
}
public static CGCondition newCGCondition(
String category, Expression expr, Vector rulevars)
{ // _i = stereo or _i /= stereo
String stereo = "";
String var = "";
boolean pos = true;
boolean nestedCondition = false;
if (expr instanceof BinaryExpression)
{ BinaryExpression ee = (BinaryExpression) expr;
String oper = ee.getOperator();
Vector vars = ee.metavariables();
if (vars.size() > 0)
{ var = (String) vars.get(0); }
else if (category.equals("OclStatement"))
{ var = "_4"; }
else
{ var = "_1"; }
if ("/=".equals(oper))
{ pos = false; }
else if ("isNested".equals(oper))
{ nestedCondition = true; }
// otherwise assumed to be "="
stereo = ee.getRight() + "";
}
if (rulevars.contains(var))
{ CGCondition res = new CGCondition(stereo,var);
res.setPositive(pos);
res.setIsNested(nestedCondition);
return res;
}
return null;
}
public Vector metavariables()
{ Vector vars1 = CGRule.metavariables(variable);
Vector vars2 = CGRule.metavariables(stereotype);
Vector res = VectorUtil.union(vars1,vars2);
return res;
}
public void setVariable(String v)
{ variable = v; }
public boolean hasVariable()
{ if (variable != null &&
variable.startsWith("_"))
{ return true; }
return false;
}
public void setVariableMetafeature(String mf)
{ variable = variable + "`" + mf; }
public void setStereotypeMetafeature(String mf)
{ stereotype = stereotype + "`" + mf; }
public void setStereotype(String st)
{ stereotype = st; }
public void addToStereotype(String st)
{ stereotype = stereotype + st; }
public void setPositive(boolean pos)
{ positive = pos; }
public void setPositive()
{ positive = true; }
public void setNegative()
{ positive = false; }
public void setSubstitute()
{ isSubstitute = true; }
public void setMatches()
{ isMatches = true; }
public void setExistential()
{ quantifier = "any"; }
public void setUniversal()
{ quantifier = "all"; }
public void setIsWith(boolean w)
{ isWith = w; }
public void setIsNested(boolean w)
{ isNested = w; }
public String toString()
{ String res = variable;
if ("all".equals(quantifier))
{ res = res + " all"; }
else if ("any".equals(quantifier))
{ res = res + " any"; }
else if (isSubstitute)
{ res = res + " /"; }
else if (isMatches)
{ res = res + " matches"; }
else if (isWith)
{ res = res + " with"; }
else if (isNested)
{ res = res + " isNested"; }
if (positive) { }
else
{ res = res + " not"; }
return res + " " + stereotype;
}
public boolean equals(Object other)
{ if (other instanceof CGCondition)
{ CGCondition cc = (CGCondition) other;
if (toString().equals(cc + ""))
{ return true; }
}
return false;
}
public String applyPostAction(String res,
Vector variables, Vector eargs, Vector newargs,
CGSpec cgs, Vector entities, Vector rhsVariables)
{ if (isSubstitute)
{ String rep = variable;
String varx = variable;
String var = stereotype;
Vector metafs = CGRule.metafeatures(variable);
// System.out.println("***>> Action metafeatures of " + variable + " are: " + metafs);
if (metafs.size() > 0)
{
// If the variable has a metafeature: _i`mf
// evaluate _i`mf in cgs as the rep
String mf = (String) metafs.get(0);
int mfindex = mf.indexOf("`");
varx = mf.substring(0,mfindex);
String mffeat = mf.substring(mfindex+1,mf.length());
if (mffeat != null && variables.contains(varx))
{ int i = variables.indexOf(varx);
ASTTerm ast = (ASTTerm) eargs.get(i);
rep = CGRule.applyMetafeature(
mffeat,ast,cgs,entities);
}
else
{ rep = varx; }
}
else if (variables.contains(varx))
{ int i = variables.indexOf(varx);
rep = (String) newargs.get(i);
}
else if (rhsVariables.contains(varx))
{ rep = ASTTerm.getStereotypeValue(varx); }
if (variables.contains(stereotype))
{ int i = variables.indexOf(stereotype);
var = (String) newargs.get(i);
}
else if (rhsVariables.contains(stereotype))
{ var = ASTTerm.getStereotypeValue(stereotype); }
res = res.replace(var,rep);
}
return res;
} // Either could have a metafeature.
public String evaluateProperty(Vector vars, Vector eargs,
Vector reps, CGSpec cgs,
Vector entities, Vector globalVariables)
{ // stereotype can be _i, _$ for LHS or global
// variables, or _i`f for metafeature f, or a value
// without variables.
// Result is evaluation in ruleset cgs with actual args
// eargs, reps
String stereo = new String(stereotype);
for (int x = 0; x < reps.size() && x < vars.size(); x++)
{ String var = (String) vars.get(x);
String arg1 = (String) reps.get(x);
String svarx = var;
String smffeat = null;
Vector stereomfs = CGRule.metafeatures(stereo);
if (stereomfs.size() > 0)
{
// If stereo is variable with a metafeature: _i`mf
// evaluate _i`mf in cgs and substitute in stereo
String smf = (String) stereomfs.get(0);
int smfindex = smf.indexOf("`");
svarx = smf.substring(0,smfindex);
smffeat = smf.substring(smfindex+1,smf.length());
if (smffeat != null && var.equals(svarx))
{ int indv = vars.indexOf(svarx);
if (indv >= 0 && eargs.get(indv) instanceof ASTTerm)
{
ASTTerm earg = (ASTTerm) eargs.get(indv);
stereo = CGRule.applyMetafeature(
smffeat,earg,cgs,entities);
}
}
}
stereo = stereo.replace(var,arg1);
}
for (int y = 0; y < globalVariables.size(); y++)
{ String rvar = (String) globalVariables.get(y);
String varValue = ASTTerm.getStereotypeValue(rvar);
if (varValue != null)
{ stereo = stereo.replace(rvar,varValue);
// JOptionPane.showMessageDialog(null,
// "Global variable " + rvar + " value is " + stereo, "",
// JOptionPane.INFORMATION_MESSAGE);
System.out.println(">--> Replacing global variable " + rvar + " by " + varValue);
}
} // No metafeatures allowed
return stereo;
}
public void applyAction(Vector vars, Vector eargs,
Vector reps, CGSpec cgs,
Vector entities, Vector globalVariables)
{ // vv stereo
// means ast.setStereotype(stereorep)
// where ast is the eargs element of vars variable vv
// stereorep is stereo with each var
// replaced by corresponding rep
// If vv has no corresponding eargs, then it is a global
// variable, vv stereo sets its value to stereo.
// If vv is ww`mf then evaluate ww`mf (for ruleset
// or built-in function mf) and add stereo to
// stereotypes of the result. If mf is neither
// a ruleset nor a built-in function, then
// it is tagged value setting mf=stereo for ww.
// _* all stereo
// sets the stereotype for each term in the _* list
// _i`f with _j uses _j as the parameter _$ in f::
if (isSubstitute || isMatches || isNested)
{ return; }
String stereo = new String(stereotype);
Vector stereomfs = CGRule.metafeatures(stereo);
for (int x = 0; x < reps.size() && x < vars.size(); x++)
{ String var = (String) vars.get(x);
String arg1 = (String) reps.get(x);
String svarx = var;
String smffeat = null;
if (stereomfs.size() > 0)
{
// If stereo has a metafeature: _i`mf
// evaluate _i`mf in cgs and set stereo to result
String smf = (String) stereomfs.get(0);
int smfindex = smf.indexOf("`");
svarx = smf.substring(0,smfindex);
smffeat = smf.substring(smfindex+1,smf.length());
if (smffeat != null && var.equals(svarx))
{ int indv = vars.indexOf(svarx);
if (indv >= 0 && eargs.get(indv) instanceof ASTTerm)
{
ASTTerm earg = (ASTTerm) eargs.get(indv);
stereo = CGRule.applyMetafeature(
smffeat,earg,cgs,entities);
}
}
}
stereo = stereo.replace(var,arg1);
/* JOptionPane.showMessageDialog(null,
"LHS variable " + var + " value is " + arg1 + "\n" +
" New stereotype value is: " + stereo, "",
JOptionPane.INFORMATION_MESSAGE); */
}
for (int y = 0; y < globalVariables.size(); y++)
{ String rvar = (String) globalVariables.get(y);
String varValue = ASTTerm.getStereotypeValue(rvar);
/* JOptionPane.showMessageDialog(null,
"Global variable " + rvar + " value is " + varValue + "\n" +
"Old stereotype value is: " + stereo + "\n" +
"Metafeatures " + stereomfs, "",
JOptionPane.INFORMATION_MESSAGE); */
if (stereomfs.size() > 0)
{
// If stereo has a metafeature: rvar`mf
// evaluate rvar`mf in cgs and set stereo to result
String gmf = (String) stereomfs.get(0);
int gmfindex = gmf.indexOf("`");
String gvarx = gmf.substring(0,gmfindex);
String gmffeat =
gmf.substring(gmfindex+1,gmf.length());
if (gmffeat != null && rvar.equals(gvarx))
{ // find the value of varValue`gmffeat
if (varValue != null)
{ // stereo = stereo.replace(rvar,varValue);
String gmfvalue =
ASTTerm.getTaggedValue(varValue, gmffeat);
if (gmfvalue != null)
{ stereo = stereo.replace(gmf,gmfvalue); }
}
}
}
else if (varValue != null) // no stereotype
{ stereo = stereo.replace(rvar,varValue);
System.out.println(">--> Replacing global variable " + rvar + " by " + varValue);
}
}
// System.out.println(">>> Applying action " + variable + " (" + positive + ") " + stereo);
// JOptionPane.showMessageDialog(null,
// "Applying action " + variable + " (" + positive + ") " + stereo, "",
// JOptionPane.INFORMATION_MESSAGE);
String varx = variable;
String mffeat = null;
if (quantifier.equals("all") && "_*".equals(varx))
{ // set each term in _* to the stereo
int starind = vars.indexOf(varx);
if (starind >= 0)
{ Object obj = eargs.get(starind);
if (obj instanceof Vector)
{ Vector termlist = (Vector) obj;
for (int p = 0; p < termlist.size(); p++)
{ if (termlist.get(p) instanceof ASTTerm)
{ ASTTerm trm = (ASTTerm) termlist.get(p);
ASTTerm.setType(trm,stereo);
ASTTerm.addStereo(trm,stereo);
System.out.println("***>> Applying action _* all " + stereo + " to: " + trm);
}
}
}
}
return;
}
if (isWith)
{ ASTTerm.setStereotypeValue("_$", stereo);
// JOptionPane.showMessageDialog(null,
// "Global variable _$ value is " + stereo, "",
// JOptionPane.INFORMATION_MESSAGE);
}
Vector metafs = CGRule.metafeatures(variable);
// System.out.println("***>> Action metafeatures of " + variable + " are: " + metafs);
if (metafs.size() > 0)
{
// If the variable has a metafeature: _i`mf
// evaluate _i`mf in cgs and set stereotype of result
String mf = (String) metafs.get(0);
int mfindex = mf.indexOf("`");
varx = mf.substring(0,mfindex);
mffeat = mf.substring(mfindex+1,mf.length());
}
int ind = vars.indexOf(varx);
if (ind >= 0)
{ Object obj = eargs.get(ind);
if (obj instanceof ModelElement)
{ ModelElement me = (ModelElement) obj;
if (positive)
{ me.addStereotype(stereo); }
else
{ me.removeStereotype(stereo); }
}
else if (obj instanceof ASTTerm)
{ ASTTerm ast = (ASTTerm) obj;
String lit = ast.literalForm();
// if there is a metafeature of variable, apply it:
if (mffeat != null)
{ if (cgs.hasRuleset(mffeat))
{ String repl = CGRule.applyMetafeature(
mffeat,ast,cgs,entities);
// Evaluate ast`mffeat and set its stereo
/* JOptionPane.showMessageDialog(null,
"repl: " + repl + " Ruleset mffeat: " + mffeat +
" stereo: " + stereo, "",
JOptionPane.INFORMATION_MESSAGE); */
if (isWith) { }
else if (positive && repl != null)
{ ASTTerm.setType(repl,stereo);
ASTTerm.addStereo(repl,stereo);
}
else if (repl != null)
{ ASTTerm.setType(repl,null);
ASTTerm.removeStereo(repl,stereo);
}
}
else if (CSTL.isInbuiltFunction(mffeat))
{ // standard metafeature such as `first etc
String repl = CGRule.applyMetafeature(
mffeat,ast,cgs,entities);
if (positive && repl != null)
{ ASTTerm.setType(repl,stereo);
ASTTerm.addStereo(repl,stereo);
}
else if (repl != null)
{ ASTTerm.setType(repl,null);
ASTTerm.removeStereo(repl,stereo);
}
/* JOptionPane.showMessageDialog(null,
"Executed action " + repl +
" |-> " + stereo + " Tagged values = " + ASTTerm.metafeatures,
"", JOptionPane.INFORMATION_MESSAGE);
*/
}
else // No ruleset, set ast`mffeat=stereo
{ ASTTerm.setTaggedValue(ast, mffeat, stereo);
/* JOptionPane.showMessageDialog(null,
"Executed action " + ast + "`" + mffeat +
" = " + stereo + " Tagged values = " + ASTTerm.metafeatures,
"", JOptionPane.INFORMATION_MESSAGE); */
// repl = stereo;
}
/* System.out.println(">>> Executed action " + repl + " (" + positive + ") " + stereo);
JOptionPane.showMessageDialog(null,
"Executed action " + repl + " (" + positive + ") " + stereo, "",
JOptionPane.INFORMATION_MESSAGE); */
}
else
{ if (isWith) { }
else if (positive)
{ // ast.addStereotype(stereo);
ASTTerm.addStereo(lit,stereo);
}
else
{ // ast.removeStereotype(stereo);
ASTTerm.removeStereo(lit,stereo);
}
/* JOptionPane.showMessageDialog(null,
"Executed action " + ast + " (" + positive + ") " + stereo + " " + ASTTerm.getStereotypes(ast), "",
JOptionPane.INFORMATION_MESSAGE); */
}
}
}
else // varx is a global variable
{ /* JOptionPane.showMessageDialog(null,
"Set global variable " + varx + " " + mffeat + " " + stereo, "",
JOptionPane.INFORMATION_MESSAGE); */
if (mffeat == null || mffeat.length() == 0)
{ ASTTerm.setStereotypeValue(varx,stereo); }
else // varx`mffeat = stereo
{ String varValue = ASTTerm.getStereotypeValue(varx);
if (varValue != null)
{ ASTTerm.setTaggedValue(varValue,mffeat,stereo); }
}
}
}
public static boolean conditionsSatisfied(
Vector conditions,
Vector vars, Vector eargs,
Vector entities, CGSpec cgs, Vector gvars)
{ boolean res = true;
for (int i = 0; i < eargs.size(); i++)
{ Object m = eargs.get(i);
String var = "_" + (i+1); // assumes numbered _1, _2 ...
for (int j = 0; j < conditions.size(); j++)
{ CGCondition cond = (CGCondition) conditions.get(j);
if (cond.variable != null)
{ int mfindex = cond.variable.indexOf("`");
String cvar = cond.variable;
if (mfindex > 0)
{ cvar = cvar.substring(0,mfindex); }
if ("_*".equals(cvar) &&
m instanceof Vector)
{ if (cond.conditionSatisfied((Vector) m,entities,cgs))
{ }
else
{ return false; }
System.out.println("||| Condition " + cond + " is satisfied by " + m);
}
else if ("_+".equals(cvar) &&
m instanceof Vector)
{ if (cond.conditionSatisfied((Vector) m,entities,cgs))
{ }
else
{ return false; }
System.out.println("||| Condition " + cond + " is satisfied by " + m);
}
else if (var.equals(cvar))
{ if (m instanceof Type &&
cond.conditionSatisfied((Type) m, entities,cgs))
{ }
else if (m instanceof Expression &&
cond.conditionSatisfied((Expression) m, entities,cgs))
{ }
else if (m instanceof Statement &&
cond.conditionSatisfied((Statement) m, entities,cgs) )
{ }
else if (m instanceof Attribute &&
cond.conditionSatisfied((Attribute) m, entities,cgs) )
{ }
else if (m instanceof ModelElement &&
cond.stereotypeConditionSatisfied((ModelElement) m, entities,cgs))
{ }
else if (m instanceof Vector &&
cond.conditionSatisfied((Vector) m, entities,cgs))
{ }
else if (m instanceof String &&
cond.conditionSatisfied((String) m, entities,cgs))
{ }
else if (m instanceof ASTTerm &&
cond.conditionSatisfiedASTTerm((ASTTerm) m, vars,
eargs, new Vector(), entities, cgs, gvars))
{ System.out.println("||| ASTTerm condition " + cond + " satisfied by term " + m);
System.out.println();
}
else
{ return false; }
System.out.println("||| Condition " + cond + " is satisfied by " + m);
}
}
}
}
return res;
}
public static boolean allConditionsSatisfied(CGRule r,
Vector conditions,
Vector vars, Vector eargs,
Vector reps,
Vector entities, CGSpec cgs, Vector gvars)
{ boolean res = true;
// JOptionPane.showMessageDialog(null,
// "|||| Checking conditions " + conditions + " with global variables " + gvars, "",
// JOptionPane.INFORMATION_MESSAGE);
for (int j = 0; j < conditions.size(); j++)
{ CGCondition cond = (CGCondition) conditions.get(j);
if (cond.variable != null)
{ String cvar = cond.variable;
int mfindex = cvar.indexOf("`");
if (mfindex > 0)
{ cvar = cvar.substring(0,mfindex); }
int ind = r.variables.indexOf(cvar);
// variablePosition for CGTL rules
if (ind < 0)
{ // Global variable or unknown thing.
String evaluatedStereo =
cond.evaluateProperty(vars, eargs,
reps, cgs,
entities, gvars);
String gval =
(String) ASTTerm.metafeatures.get(cvar);
if (gvars.contains(cvar))
{ // and evaluate its metafeature if any
/* JOptionPane.showMessageDialog(null,
"|||| Checking condition " + gval + " = " + cond.stereotype + "~" + evaluatedStereo, "",
JOptionPane.INFORMATION_MESSAGE); */
if (evaluatedStereo.equals(gval))
{ }
else if (gval != null &
ASTTerm.metafeatures.get(gval) instanceof Vector &&
((Vector) ASTTerm.metafeatures.get(gval)).contains(evaluatedStereo))
{ }
else
{ return false; }
}
else // not a variable on LHS
{ return false; }
/* JOptionPane.showMessageDialog(null,
"|||| Condition " + gval + " " + evaluatedStereo + " is true", "",
JOptionPane.INFORMATION_MESSAGE); */
}
else if (ind >= 0 && ind < eargs.size())
{ Object m = eargs.get(ind);
if ("_*".equals(cvar) &&
m instanceof Vector)
{ if (cond.conditionSatisfied((Vector) m,entities,cgs, gvars))
{ }
else
{ return false; }
System.out.println("||| Condition " + cond + " is satisfied by " + m);
}
else if ("_+".equals(cvar) &&
m instanceof Vector)
{ if (cond.conditionSatisfied((Vector) m,entities,cgs, gvars))
{ }
else
{ return false; }
System.out.println("||| Condition " + cond + " is satisfied by " + m);
}
else if (m instanceof Type &&
cond.conditionSatisfied((Type) m, entities,cgs))
{ }
else if (m instanceof Expression &&
cond.conditionSatisfied((Expression) m, entities,cgs))
{ }
else if (m instanceof Statement &&
cond.conditionSatisfied((Statement) m, entities,cgs) )
{ }
else if (m instanceof Attribute &&
cond.conditionSatisfied((Attribute) m, entities,cgs) )
{ }
else if (m instanceof ModelElement &&
cond.stereotypeConditionSatisfied((ModelElement) m, entities,cgs))
{ }
else if (m instanceof Vector &&
cond.conditionSatisfied((Vector) m, entities,cgs,gvars))
{ }
else if (m instanceof String &&
cond.conditionSatisfied((String) m, entities,cgs))
{ }
else if (m instanceof ASTTerm &&
cond.conditionSatisfiedASTTerm((ASTTerm) m,
vars, eargs, reps,
entities, cgs, gvars))
{ System.out.println("||| ASTTerm condition " + cond + " satisfied by term " + m);
System.out.println();
}
else
{ return false; }
System.out.println("||| Condition " + cond + " is satisfied by " + m);
}
}
}
return res;
}
public boolean stereotypeConditionSatisfied(ModelElement m, Vector entities, CGSpec cgs)
{ if (m.hasStereotype(stereotype))
{ return positive; }
if (!m.hasStereotype(stereotype))
{ return !positive; }
return false;
}
public boolean conditionSatisfied(Object t, Vector entities, CGSpec cgs, Vector gvars)
{ if (t instanceof Type)
{ return conditionSatisfied((Type) t, entities,cgs); }
if (t instanceof Attribute)
{ return conditionSatisfied((Attribute) t, entities,cgs); }
if (t instanceof Expression)
{ return conditionSatisfied((Expression) t, entities,cgs); }
if (t instanceof Statement)
{ return conditionSatisfied((Statement) t, entities,cgs); }
if (t instanceof ASTTerm)
{ Vector vars = new Vector();
Vector eargs = new Vector();
Vector reps = new Vector();
return conditionSatisfiedASTTerm((ASTTerm) t,
vars, eargs, reps,
entities, cgs, gvars);
}
if (t instanceof Vector)
{ return conditionSatisfied((Vector) t, entities,cgs); }
if (t instanceof String)
{ return conditionSatisfied((String) t, entities,cgs); }
return false;
}
public boolean conditionSatisfied(Object t, Vector entities, CGSpec cgs)
{ if (t instanceof Type)
{ return conditionSatisfied((Type) t, entities,cgs); }
if (t instanceof Attribute)
{ return conditionSatisfied((Attribute) t, entities,cgs); }
if (t instanceof Expression)
{ return conditionSatisfied((Expression) t, entities,cgs); }
if (t instanceof Statement)
{ return conditionSatisfied((Statement) t, entities,cgs); }
if (t instanceof ASTTerm)
{ Vector gvars = new Vector();
return conditionSatisfied((ASTTerm) t, entities,cgs, gvars);
}
if (t instanceof Vector)
{ return conditionSatisfied((Vector) t, entities,cgs); }
if (t instanceof String)
{ return conditionSatisfied((String) t, entities,cgs); }
return false;
}
public boolean conditionSatisfied(Type t, Vector entities, CGSpec cgs)
{ System.out.println("||| Checking type condition " + t + " " + stereotype);
System.out.println();
if ("string".equals(stereotype.toLowerCase()) && t.isStringType())
{ return positive; }
if ("class".equals(stereotype.toLowerCase()) && t.isEntityType(entities))
{ System.out.println("||| Condition class satisfied for " + t);
return positive;
}
if ("interface".equals(stereotype.toLowerCase()) && t.isInterfaceType(entities))
{ System.out.println("||| Condition interface satisfied for " + t);
return positive;
}
if ("void".equals(stereotype.toLowerCase()) &&
(t == null || "void".equals(t.getName()) ||
t.isVoidType()))
{ return positive; }
if ("enumerated".equals(stereotype.toLowerCase()) &&
t.isEnumeratedType())
{ return positive; }
if ("datatype".equals(stereotype.toLowerCase()) &&
t.isDatatype())
{ return positive; }
if ("map".equals(stereotype.toLowerCase()) &&
t.isMapType())
{ return positive; }
if ("sortedmap".equals(stereotype.toLowerCase()) &&
t.isSortedMapType())
{ return positive; }
if ("function".equals(stereotype.toLowerCase()) &&
t.isFunctionType())
{ return positive; }
if ("collection".equals(stereotype.toLowerCase()) &&
t.isCollectionType())
{ return positive; }
if ("sequence".equals(stereotype.toLowerCase()) &&
t.isSequenceType())
{ return positive; }
if ("set".equals(stereotype.toLowerCase()) &&
t.isSetType())
{ return positive; }
if ("sortedset".equals(stereotype.toLowerCase()) &&
t.isSortedSetType())
{ return positive; }
if ("ref".equals(stereotype.toLowerCase()) && t.isRef())
{ return positive; }
if ("integer".equals(stereotype.toLowerCase()) && t.isInteger())
{ return positive; }
if ("real".equals(stereotype.toLowerCase()) && t.isReal())
{ return positive; }
if ("int".equals(stereotype.toLowerCase()) && t.isInt())
{ return positive; }
if ("long".equals(stereotype.toLowerCase()) && t.isLong())
{ return positive; }
if ("class".equals(stereotype.toLowerCase()) && !(t.isEntityType(entities)))
{ System.out.println("||| " + t + " is not a class");
return !positive;
}
if ("interface".equals(stereotype.toLowerCase()) && !(t.isInterfaceType(entities)))
{ System.out.println("||| " + t + " is not an interface");
return !positive;
}
if ("void".equals(stereotype.toLowerCase()) && t != null && !t.isVoidType())
{ return !positive; }
if ("enumerated".equals(stereotype.toLowerCase()) && !(t.isEnumeratedType()))
{ return !positive; }
if ("map".equals(stereotype.toLowerCase()) && !t.isMapType())
{ return !positive; }
if ("sortedmap".equals(stereotype.toLowerCase()) &&
!t.isSortedMapType())
{ return !positive; }
if ("function".equals(stereotype.toLowerCase()) &&
!t.isFunctionType())
{ return !positive; }
if ("collection".equals(stereotype.toLowerCase()) && !(t.isCollectionType()))
{ return !positive; }
if ("sequence".equals(stereotype.toLowerCase()) && !(t.isSequenceType()))
{ return !positive; }
if ("set".equals(stereotype.toLowerCase()) && !(t.isSetType()))
{ return !positive; }
if ("sortedset".equals(stereotype.toLowerCase()) && !(t.isSortedSetType()))
{ return !positive; }
if ("ref".equals(stereotype.toLowerCase()) && !(t.isRef()))
{ return !positive; }
if ("integer".equals(stereotype.toLowerCase()) && !(t.isInteger()))
{ return !positive; }
if ("real".equals(stereotype.toLowerCase()) && !(t.isReal()))
{ return !positive; }
if ("int".equals(stereotype.toLowerCase()) && !(t.isInt()))
{ return !positive; }
if ("long".equals(stereotype.toLowerCase()) && !(t.isLong()))
{ return !positive; }
return false;
}
public boolean conditionSatisfied(Attribute a, Vector entities, CGSpec cgs)
{ if ("primary".equals(stereotype.toLowerCase()) && a.isPrimaryAttribute())
{ return positive; }
if ("static".equals(stereotype.toLowerCase()) && a.isStatic())
{ return positive; }
if (a.hasStereotype(stereotype))
{ return positive; }
return false;
}
public boolean conditionSatisfied(Vector v, Vector entities, CGSpec cgs, Vector gvars)
{ System.out.println(".>>>. Checking vector condition " + quantifier + " " + stereotype);
if ("all".equals(quantifier))
{ if (v.size() == 0)
{ return true; }
CGCondition gcond = new CGCondition(stereotype, "_1");
gcond.setPositive(positive);
for (int i = 0; i < v.size(); i++)
{ Object x = v.get(i);
if (gcond.conditionSatisfied(x,entities,cgs)) { }
else
{ return false; }
}
return true;
}
if ("any".equals(quantifier))
{ if (v.size() == 0)
{ return false; }
CGCondition gcond = new CGCondition(stereotype,"_1");
gcond.setPositive(positive);
for (int i = 0; i < v.size(); i++)
{ Object x = v.get(i);
if (gcond.conditionSatisfied(x,entities,cgs))
{ return true; }
}
return false;
}
if ("empty".equals(stereotype.toLowerCase()) &&
(v == null || v.size() == 0))
{ return positive; }
if ("empty".equals(stereotype.toLowerCase()) &&
v != null && v.size() > 0)
{ return !positive; }
if ("multiple".equals(stereotype.toLowerCase()) &&
(v == null || v.size() <= 1))
{ return !positive; }
if ("multiple".equals(stereotype.toLowerCase()) &&
v != null && v.size() > 1)
{ return positive; }
if ("singleton".equals(stereotype.toLowerCase()) &&
(v == null || v.size() != 1))
{ return !positive; }
if ("singleton".equals(stereotype.toLowerCase()) &&
v != null && v.size() == 1)
{ return positive; }
if ("1ary".equals(stereotype.toLowerCase()) &&