-
Notifications
You must be signed in to change notification settings - Fork 9
/
Attribute.java
9332 lines (8122 loc) · 317 KB
/
Attribute.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
import java.util.Vector;
import java.io.*;
import javax.swing.JOptionPane;
/******************************
* 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: Class Diagram */
/* NB: Please complete dbType and rawDecoder */
public class Attribute extends ModelElement
{ private Type type;
private Type elementType;
private int kind; // SEN, ACT, INTERNAL, DERIVED
private String initialValue = ""; // default is none
private Expression initialExpression = null;
private boolean unique = false; // true if a primary key
private boolean frozen = false; // a constant
private boolean instanceScope = true; // "static"
private int visibility = PRIVATE; // PRIVATE, PUBLIC, PROTECTED, PACKAGE
private Entity entity = null; // owner
private boolean sorted = false; // for collection-valued attributes
private boolean isParameter = false;
private Vector navigation = new Vector(); // for attributes derived as composition
private int lower = 1;
private int upper = 1; // 0 represents *
private String role1 = null; // for associations represented as properties
private int card1 = ModelElement.MANY;
private Vector parameters = new Vector();
private boolean isArray = false;
private int width = 1; // for COBOL
private int multiplicity = 1;
private int startPosition = 1;
private int endPosition = 1;
public Attribute(String nme, Type t, int k)
{ super(nme);
type = t;
kind = k;
if (t != null && t.getDefault() != null)
{ initialValue = t.getDefault();
initialExpression = t.getDefaultValueExpression();
}
// elementType = t.elementType ?
if (type != null)
{ String tname = type.getName();
if ("Set".equals(tname))
{ upper = 0; lower = 0; }
else if ("Sequence".equals(tname))
{ upper = 0; lower = 0; }
}
}
public Attribute(String nme, ModelElement t, int k)
{ this(nme, (Type) t, k); }
public Attribute(String nme, Type t)
{ this(nme,t,ModelElement.INTERNAL); }
public static Attribute newAttribute(String nme, String typ)
{ Type t = Type.getTypeFor(typ);
if (t == null)
{ t = new Type("OclAny", null); }
return new Attribute(nme, t, ModelElement.INTERNAL);
}
public static Attribute newAttribute(String nme, String typ,
Vector types, Vector ents)
{ Type t = Type.getTypeFor(typ,types,ents);
if (t == null)
{ t = new Type("OclAny", null); }
return new Attribute(nme, t, ModelElement.INTERNAL);
}
public Attribute(BasicExpression e)
{ super(e.getData());
type = e.getType();
elementType = e.getElementType();
entity = e.getEntity();
int c2 = e.getMultiplicity();
if (c2 == ModelElement.ONE)
{ upper = 1;
lower = 1;
}
else
{ upper = 0;
lower = 0;
}
kind = INTERNAL;
}
public Attribute(Expression e)
{ super(e + "");
type = e.getType();
elementType = e.getElementType();
entity = e.getEntity();
int c2 = e.getMultiplicity();
if (c2 == ModelElement.ONE)
{ upper = 1;
lower = 1;
}
else
{ upper = 0;
lower = 0;
}
kind = INTERNAL;
}
public Attribute(BasicExpression v, Expression e, Expression init)
{ super(v.getData());
type = init.getType();
elementType = init.getElementType();
// entity = e.getEntity();
int c2 = init.getMultiplicity();
if (c2 == ModelElement.ONE)
{ upper = 1;
lower = 1;
}
else
{ upper = 0;
lower = 0;
}
kind = INTERNAL;
// initialExpression = e;
// initialValue = e + "";
}
public Attribute(Association ast)
{ super(ast.getRole2());
int c2 = ast.getCard2();
card1 = ast.getCard1();
Entity e2 = ast.getEntity2();
elementType = new Type(e2);
role1 = ast.getRole1();
if (ast.isAggregation())
{ addStereotype("aggregation"); }
if (c2 == ModelElement.ONE)
{ type = new Type(e2);
upper = 1;
lower = 1;
if (card1 == ModelElement.ONE)
{ unique = true; }
else if (card1 == ModelElement.ZEROONE)
{ unique = true; }
}
else if (ast.isOrdered())
{ type = new Type("Sequence", null);
type.setElementType(elementType);
upper = 0;
lower = 0;
}
else
{ type = new Type("Set", null);
type.setElementType(elementType);
upper = 0;
lower = 0;
}
kind = INTERNAL;
entity = ast.getEntity1();
if (c2 == ModelElement.ZEROONE)
{ upper = 1; }
if (ast.isQualified())
{ Type etype = (Type) type.clone();
type = new Type("Map", null);
type.setKeyType(new Type("String", null));
type.setElementType(etype);
}
setStereotypes(ast.getStereotypes()); // eg., target, source, aggregation, addOnly
}
public Attribute(Vector path)
{ super(ModelElement.composeNames(path));
navigation = path;
type = Type.composedType(path);
upper = Type.composeMultiplicities(path,"upper");
lower = Type.composeMultiplicities(path,"lower");
card1 = ModelElement.composeCard1(path);
unique = ModelElement.composeUnique(path);
String agg = ModelElement.composeAggregation(path);
if ("aggregation".equals(agg))
{ addStereotype("aggregation"); }
String st = ModelElement.composeSourceTarget(path);
if ("source".equals(st))
{ addStereotype("source"); }
else if ("target".equals(st))
{ addStereotype("target"); }
if (type != null)
{ elementType = type.getElementType(); }
kind = INTERNAL;
if (path.size() > 0)
{ ModelElement me = (ModelElement) path.get(0);
// setStereotypes(me.getStereotypes());
if (me instanceof Attribute)
{ entity = ((Attribute) me).entity; }
}
} // and set the entity and name. Set it as aggregation if all
// path elements are aggregations. Likewise for unique.
public Attribute(BehaviouralFeature qf)
{ super(qf.getName());
// assume that qf is a query operation & therefore has a
// result type.
type = qf.getResultType();
if (type == null)
{ upper = 1;
lower = 1;
}
else
{ int tm = type.typeMultiplicity();
if (tm == ModelElement.ONE)
{ upper = 1;
lower = 1;
}
else
{ upper = 0;
lower = 0;
}
elementType = type.getElementType();
}
setStatic(qf.isStatic());
entity = qf.getOwner();
// card1 = ModelElement.composeCard1(path);
// unique = ModelElement.composeUnique(path);
// String agg = ModelElement.composeAggregation(path);
// if ("aggregation".equals(agg))
// { addStereotype("aggregation"); }
// String st = ModelElement.composeSourceTarget(path);
// if ("source".equals(st))
// { addStereotype("source"); }
if (entity != null && entity.isTarget())
{ addStereotype("target"); }
kind = INTERNAL;
}
public static Attribute randomAttribute(Vector entities)
{ String nme = ModelElement.randomNormalString(10);
Type typ = Type.randomType(entities);
nme = ModelElement.decapitalise(nme);
Attribute res =
new Attribute(nme, typ, ModelElement.INTERNAL);
Expression expr = typ.getDefaultValueExpression();
res.setInitialisation(expr);
return res;
}
public static Attribute fromOperation(BehaviouralFeature qf)
{ Attribute res =
new Attribute(qf.getName(),null,ModelElement.INTERNAL);
Type restype = qf.getResultType();
if (restype == null)
{ res.upper = 1;
res.lower = 1;
restype = new Type("void", null);
}
else
{ int tm = restype.typeMultiplicity();
if (tm == ModelElement.ONE)
{ res.upper = 1;
res.lower = 1;
}
else
{ res.upper = 0;
res.lower = 0;
}
}
Type ftype = restype;
Vector pars = qf.getParameters();
if (pars.size() == 0)
{ ftype = new Type("Function", null);
ftype.setKeyType(new Type("void", null));
ftype.setElementType(restype);
res.setType(ftype);
}
else
{ for (int k = 0; k < pars.size(); k++)
{ Attribute par = (Attribute) pars.get(k);
Type domtype = par.getType();
Type typ = new Type("Function", null);
typ.setKeyType(domtype);
typ.setElementType(ftype);
ftype = typ;
}
res.setType(ftype);
System.out.println(">> Attribute from operation: " + ftype);
}
res.setStatic(qf.isStatic());
res.entity = qf.getOwner();
res.kind = INTERNAL;
return res;
}
public void setParameters(Vector pars)
{ parameters = pars; }
public Vector getParameters()
{ return parameters; }
public void setKind(int k)
{ kind = k; }
public boolean isArray()
{ return isArray; }
public void setArray(boolean b)
{ isArray = b; }
public boolean isParameter()
{ return isParameter; }
public void setIsParameter(boolean b)
{ isParameter = b; }
public void setWidth(int w)
{ width = w; }
public int getWidth()
{ return width; }
public void setMultiplicity(int m)
{ multiplicity = m; }
public int getMultiplicity()
{ return multiplicity; }
public void setStartPosition(int sp)
{ startPosition = sp; }
public int getStartPosition()
{ return startPosition; }
public void setEndPosition(int ep)
{ endPosition = ep; }
public int getEndPosition()
{ return endPosition; }
public boolean isFunction()
{ return type != null && type.isFunction(); }
public void setInitialisation(Expression expr)
{ initialExpression = expr; }
// public Expression getInitialExpression()
// { return initialExpression; }
public boolean typeCheck(Vector types, Vector entities)
{ if (type != null && type.isSorted())
{ setSorted(true); }
if (initialExpression != null)
{ Vector cntx = new Vector();
if (entity != null)
{ cntx.add(entity); }
Vector env = new Vector();
initialExpression.typeCheck(types,entities,cntx,env);
if (type != null)
{ System.out.println(">> Type of attribute: " + name +
" is " + type + "(" + elementType + ") {" +
type.isSorted() + ")");
}
else
{ System.err.println("!! No type for " + name); }
if (Type.isVacuousType(type) &&
!Type.isVacuousType(initialExpression.type))
{ type = initialExpression.type;
elementType = initialExpression.elementType;
type.elementType = elementType;
}
if (type != null && type.isSorted() &&
initialExpression.type != null)
{ initialExpression.type.setSorted(true); }
System.out.println(">> Type of initialiser: " + initialExpression + " is " + initialExpression.type + "(" + initialExpression.elementType + ")");
return true;
}
if (type == null)
{ type = new Type("OclAny", null);
return true;
}
String tname = type + "";
Type t = Type.getTypeFor(tname, types, entities);
if (t == null)
{ System.err.println("!! Warning: null type for attribute " + name);
// type = new Type("OclAny", null);
return true;
}
type = t;
Type et = elementType;
if (elementType != null)
{ String etname = elementType + "";
et = Type.getTypeFor(etname, types, entities);
if (et == null)
{ System.err.println("!! Warning: null element type for attribute " + name);
et = elementType;
type.elementType = elementType;
}
else
{ elementType = et;
type.elementType = et;
}
}
System.out.println(">> Updated type of attribute: " + name + " is " + type + "(" + elementType + ")");
if (initialExpression != null &&
initialExpression.type == null)
{ initialExpression.type = type;
initialExpression.elementType = et;
}
return true;
}
public boolean typeInference(Vector types, Vector entities,
java.util.Map vtypes)
{ if (initialExpression != null)
{ Vector cntx = new Vector();
if (entity != null)
{ cntx.add(entity); }
Vector env = new Vector();
initialExpression.typeCheck(types,entities,cntx,env);
if (type != null && type.isAliasType())
{ type = type.getActualType();
elementType = type.getElementType();
}
System.out.println(">> Type of attribute: " + name + " is " + type + "(" + elementType + ")");
if (initialExpression.type != null &&
initialExpression.type.isAliasType())
{ initialExpression.type =
initialExpression.type.getActualType();
elementType = initialExpression.type.getElementType();
}
if (Type.isVacuousType(type) &&
!Type.isVacuousType(initialExpression.type))
{ type = initialExpression.type;
elementType = initialExpression.elementType;
type.elementType = elementType;
}
if (Type.isVacuousType(elementType) &&
!Type.isVacuousType(initialExpression.elementType))
{ elementType = initialExpression.elementType;
type.elementType = elementType;
}
if (initialExpression.type == null)
{ System.err.println("!! Invalid initial expression -- no type for " + initialExpression + "!!");
initialExpression =
Type.defaultInitialValueExpression(type);
}
if (!Type.isVacuousType(elementType) &&
Type.isVacuousType(initialExpression.elementType))
{ initialExpression.elementType = elementType;
initialExpression.type.elementType = elementType;
}
System.out.println(">> Type of initialiser: " + initialExpression + " is " + initialExpression.type + "(" + initialExpression.elementType + ")");
return true;
}
else // no initialisation
{ if (isFrozen())
{ System.err.println("!! ERROR: frozen attributes must have an initialiser: " + getName()); }
}
if (type == null)
{ type = new Type("OclAny", null);
return true;
}
String tname = type + "";
Type t = Type.getTypeFor(tname, types, entities);
if (t == null)
{ System.err.println("!! Warning: null type for attribute " + name);
// type = new Type("OclAny", null);
return true;
}
type = t;
Type et = elementType;
if (elementType != null)
{ String etname = elementType + "";
et = Type.getTypeFor(etname, types, entities);
if (et == null)
{ System.err.println("!! Warning: null element type for attribute " + name);
et = elementType;
type.elementType = elementType;
}
else
{ elementType = et;
type.elementType = et;
}
}
System.out.println(">> Updated type of attribute: " + name + " is " + type + "(" + elementType + ")");
if (initialExpression != null &&
initialExpression.type == null)
{ initialExpression.type = type;
initialExpression.elementType = et;
}
return true;
}
public boolean isMany()
{ return upper == 0; }
public boolean isReference()
{ if (type != null && type.isEntity())
{ return true; }
if (type != null && Type.isEntityCollection(type))
{ return true; }
return false;
}
public static Vector reduceToInitialPaths(Vector atts)
{ // Remove r.f if r is already in atts
Vector res = new Vector();
for (int i = 0; i < atts.size(); i++)
{ Attribute att = (Attribute) atts.get(i);
if (containsInitialSegment(atts,att)) { }
else
{ res.add(att); }
}
return res;
}
private static boolean containsInitialSegment(Vector atts, Attribute att)
{ boolean res = false;
Vector navatt = att.navigation;
for (int i = 0; i < atts.size(); i++)
{ Attribute attx = (Attribute) atts.get(i);
if (attx == att) { }
else
{ Vector navx = attx.navigation;
if (navx.size() > 0 && navx.size() < navatt.size() && navatt.containsAll(navx))
{ return true; }
}
}
return res;
}
public int sizeof(String tname, Vector types, Vector entities)
{ if ("double".equals(tname) || tname.startsWith("long"))
{ return 8; }
Entity ent =
(Entity) ModelElement.lookupByName(tname,entities);
if (ent != null)
{ return ent.sizeof(types,entities); }
return 4;
} // records - classes; sequences
public boolean isNumeric()
{ return type != null && type.isNumericType(); }
public boolean isString()
{ return type != null && type.isStringType(); }
public boolean isCollection()
{ return type != null && type.isCollectionType(); }
public boolean isReferenceType()
{ return type != null && type.isReference(); }
public boolean isRef()
{ return type != null && type.isRef(); }
public boolean isNestedReferenceType()
{ return type != null && type.isNestedReference(); }
public boolean isFunctionType()
{ return type != null && type.isFunction(); }
public boolean isFunctionRef()
{ if (type == null)
{ return false; }
if ("Ref".equals(type.getName()))
{ return type.getElementType() != null &&
type.getElementType().isFunction();
}
return false;
}
public boolean isCollectionRef()
{ if (type == null)
{ return false; }
if ("Ref".equals(type.getName()))
{ return type.getElementType() != null &&
type.getElementType().isCollectionType();
}
return false;
}
public boolean isRefRef()
{ if (type == null)
{ return false; }
if ("Ref".equals(type.getName()))
{ return type.getElementType() != null &&
type.getElementType().isRef();
}
return false;
}
public boolean isEntityCollection()
{ return type != null && type.isCollectionType() &&
elementType != null && elementType.isEntity();
}
public boolean isNumericCollection()
{ return type != null && type.isCollectionType() &&
elementType != null && elementType.isNumeric();
}
public boolean isStringCollection()
{ return type != null && type.isCollectionType() &&
elementType != null && elementType.isString();
}
public boolean isPrimitiveCollection()
{ return type != null && type.isCollectionType() &&
elementType != null && elementType.isPrimitive();
}
public boolean isSet()
{ return type != null && type.isSetType(); }
public boolean isSequence()
{ return type != null && type.isSequenceType(); }
public boolean hasSequenceType()
{ return type != null && type.isSequenceType(); }
public boolean isMap()
{ return type != null && type.isMapType(); }
public boolean isTree()
{ return type != null && "OclAny".equals(type.getName()); }
// Should have an actual OclTree type, or a kind of collection.
public boolean isBoolean()
{ return type != null && type.getName().equals("boolean"); }
public boolean equalByNameAndOwner(Attribute att)
{ if (att.getName().equals(name) &&
att.getOwner() == entity && entity != null)
{ return true; }
return false;
}
public boolean hasIndexingOperation(java.util.Map collOps)
{ // there is some indexing operator on this attribute
String aname = getName();
java.util.Set keys = collOps.keySet();
for (Object k : keys)
{ Vector maxops = (Vector) collOps.get(k);
for (int i = 0; i < maxops.size(); i++)
{ Expression expr = (Expression) maxops.get(i);
if (Expression.isOclIndexOperation(aname, expr))
{ return true; }
}
}
return false;
}
public boolean containsSubexpression(Expression expr)
{ if (initialExpression != null &&
initialExpression.containsSubexpression(expr))
{ return true; }
return false;
}
public boolean equalToReverseDirection(Attribute att)
{ if (att.getName().equals(role1 + "") &&
elementType != null && elementType.isEntity() &&
att.getOwner() == elementType.getEntity())
{ return true; }
else if (att.getName().equals(role1 + "") &&
type != null && type.isEntity() &&
att.getOwner() == type.getEntity())
{ return true; }
return false;
}
public Attribute objectReference()
{ // path omitting the final feature
if (navigation.size() <= 1)
{ Attribute res = new Attribute("self",new Type(entity), ModelElement.INTERNAL);
return res;
}
Vector pathprefix = new Vector();
pathprefix.addAll(navigation);
pathprefix.remove(navigation.get(navigation.size()-1));
return new Attribute(pathprefix);
}
public String cg(CGSpec cgs)
{ String atext = this + "";
Vector args = new Vector();
args.add(getName());
args.add(type.cg(cgs));
if (initialExpression != null)
{ args.add(initialExpression.cg(cgs)); }
Vector eargs = new Vector();
eargs.add(this);
eargs.add(type);
if (initialExpression != null)
{ eargs.add(initialExpression); }
// only one Attribute rule?
// maybe for static/frozen
CGRule r = cgs.matchedAttributeRule(this,atext);
if (r != null)
{ System.out.println(">> Matched attribute rule for " + this + ": " + r);
return r.applyRule(args,eargs,cgs);
}
return atext;
}
public String cgReference(CGSpec cgs)
{ String atext = this + "";
Vector args = new Vector();
args.add(getName());
args.add(type.cg(cgs));
Vector eargs = new Vector();
eargs.add(this);
eargs.add(type);
// only one Reference rule?
CGRule r = cgs.matchedReferenceRule(this,atext);
if (r != null)
{ System.out.println(">>> Matched reference rule for " + this + ": " + r);
return r.applyRule(args,eargs,cgs);
}
return atext;
}
public String cgParameter(CGSpec cgs, Vector partail)
{ String atext = this + "";
Vector args = new Vector();
args.add(getName());
args.add(type.cg(cgs));
if (partail.size() == 0)
{ args.add(""); }
else
{ Attribute p = (Attribute) partail.get(0);
Vector newtail = new Vector();
newtail.addAll(partail);
newtail.remove(0);
args.add(p.cgParameter(cgs,newtail));
}
CGRule r = cgs.matchedParameterRule(this,partail,atext);
if (r != null)
{ return r.applyRule(args); }
return atext;
} // but omit initialisations for parameters
public void setInnerElementType(Type t)
{ if (type != null)
{ type.setInnerElementType(t); }
}
public Type getReverseType()
{ if (entity != null)
{ Type et = new Type(entity);
if (card1 == ModelElement.ONE)
{ return et; }
Type colltype = new Type("Set", null);
colltype.setElementType(et);
return colltype;
}
return null;
}
public Entity getClassType()
{ if (type != null)
{ if (type.isEntity())
{ return type.getEntity(); }
}
if (elementType != null)
{ if (elementType.isEntity())
{ return elementType.getEntity(); }
}
return null;
}
public String getRole1()
{ return role1; }
public boolean hasOpposite()
{ return role1 != null && role1.length() > 0; }
public Attribute getReverseReference()
{ if (role1 != null && role1.length() > 0)
{ Type tr = getReverseType();
Attribute res = new Attribute(role1,tr,ModelElement.INTERNAL);
res.setElementType(tr.getElementType());
return res;
}
return null;
}
public boolean isAggregation()
{ return hasStereotype("aggregation"); }
public boolean isBidirectionalassociation()
{ return (role1 != null && role1.length() > 0); }
public Expression makeInverseCallExpression()
{ // E1.allInstances()->select( e1x � e1.att->includes(self)) for *-mult att
BasicExpression srcexp = new BasicExpression(this);
srcexp.setUmlKind(Expression.ATTRIBUTE);
if (role1 != null && role1.length() > 0)
{ BasicExpression res = new BasicExpression(role1);
return res;
}
if (entity == null)
{ return new UnaryExpression("->inverse",srcexp); }
BasicExpression einstances = new BasicExpression(entity);
BasicExpression allinst = new BasicExpression("allInstances");
allinst.setUmlKind(Expression.FUNCTION);
allinst.setObjectRef(einstances);
String var = Identifier.nextIdentifier("var$");
BasicExpression vare = new BasicExpression(var);
vare.setType(new Type(entity));
vare.setElementType(new Type(entity));
BinaryExpression rng = new BinaryExpression(":", vare, allinst);
srcexp.setObjectRef(vare);
BasicExpression selfexp = new BasicExpression("self");
selfexp.setType(elementType);
selfexp.setElementType(elementType);
BinaryExpression test = new BinaryExpression("->includes", srcexp, selfexp);
if (upper == 1 && lower == 1)
{ test = new BinaryExpression("=", srcexp, selfexp); }
BinaryExpression selexp = new BinaryExpression("|", rng, test);
return selexp;
}
public boolean isComposed()
{ return (navigation != null && navigation.size() > 1); }
public static boolean isMultipleValued(Vector path)
{ int u = Type.composeMultiplicities(path,"upper");
if (u != 1)
{ return true; }
return false;
}
public boolean isMultiValued()
{ return upper != 1; }
public boolean isMandatory()
{ return lower > 0; }
public int upperBound()
{ if (upper == 0)
{ return Integer.MAX_VALUE; }
return upper;
}
public int lowerBound()
{ return lower; }
public boolean endsWith(Attribute att)
{ int n = navigation.size();
if (n < 2)
{ return false; }
Attribute last = (Attribute) navigation.get(n-1);
if (last.getName().equals(att.getName()) &&
(last.getType() + "").equals(att.getType() + ""))
{ return true; }
return false;
}
public boolean startsWith(Attribute att)
{ int n = navigation.size();
if (n < 2)
{ return false; }
Attribute first = (Attribute) navigation.get(0);
if (first.getName().equals(att.getName()) &&
(first.getType() + "").equals(att.getType() + ""))
{ return true; }
return false;
}
public Attribute first()
{ int n = navigation.size();
if (n < 1)
{ return this; }
Attribute first = (Attribute) navigation.get(0);
return first;
}
public Attribute last()
{ int n = navigation.size();
if (n < 1)
{ return this; }
Attribute last = (Attribute) navigation.get(n-1);
return last;
}
public Entity intermediateEntity()
{ if (navigation.size() < 2)
{ return null; }
Attribute a1 = (Attribute) navigation.get(0);
Type t1 = a1.getElementType();
if (t1 != null && t1.isEntity())
{ return t1.getEntity(); }
return null;
}
public boolean isCyclic()
{ // owner is ancestor/descendent of elementType or equal to it.
Type t = getElementType();
if (t != null && t.isEntity())
{ Entity elemt = t.getEntity();
if (elemt == entity || Entity.isAncestor(elemt,entity) ||
Entity.isAncestor(entity,elemt))
{ return true; }
}
return false;
}
public boolean isOrdered()
{ return Type.isSequenceType(type); }
public boolean isDirect()
{ return navigation.size() <= 1; }