-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttribute.java
3908 lines (3380 loc) · 131 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.*;
/******************************
* Copyright (c) 2003,2019 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 */
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 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;
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(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; }
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"); }
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 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 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 String getRole1()
{ return role1; }
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.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 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; }
public boolean isConcreteChain()
{ // all element types are concrete classes if they are entity types
if (navigation.size() == 0)
{ if (elementType == null)
{ if (type.isEntity())
{ return type.getEntity().isConcrete(); }
return false;
}
else
{ if (elementType.isEntity())
{ return elementType.getEntity().isConcrete(); }
}
return false;
}
else
{ for (int i = 0; i < navigation.size(); i++)
{ Attribute x = (Attribute) navigation.get(i);
if (x.elementType == null)
{ if (x.type.isEntity())
{ return x.type.getEntity().isConcrete(); }
return false;
}
else
{ if (x.elementType.isEntity())
{ return x.elementType.getEntity().isConcrete(); }
}
return false;
}
}
return false;
}
public Vector intermediateEntities()
{ // all entity element types
Vector res = new Vector();
if (navigation.size() == 0)
{ if (elementType == null)
{ if (type.isEntity())
{ res.add(type.getEntity()); }
return res;
}
else
{ if (elementType.isEntity())
{ res.add(elementType.getEntity()); }
}
return res;
}
else
{ for (int i = 0; i < navigation.size() - 1; i++)
{ Attribute x = (Attribute) navigation.get(i);
if (x.elementType == null)
{ if (x.type.isEntity())
{ res.add(x.type.getEntity()); }
}
else
{ if (x.elementType.isEntity())
{ res.add(x.elementType.getEntity()); }
}
}
}
return res;
}
public void replaceIntermediateEntity(Entity orig, Entity newe)
{ // all entity element types
if (navigation.size() == 0)
{ if (elementType == null)
{ if (type.isEntity() && type.getEntity() == orig)
{ type = new Type(newe);
elementType = type;
}
return;
}
else
{ if (elementType.isEntity() && elementType.getEntity() == orig)
{ type = new Type(newe);
elementType = type;
}
}
return;
}
else
{ for (int i = 0; i < navigation.size() - 1; i++)
{ Attribute x = (Attribute) navigation.get(i);
if (x.elementType == null)
{ if (x.type.isEntity() && x.type.getEntity() == orig)
{ x.type = new Type(newe);
x.elementType = x.type;
}
}
else
{ if (x.elementType.isEntity() && x.elementType.getEntity() == orig)
{ x.type = new Type(newe);
x.elementType = x.type;
}
}
}
}
}
public int steps()
{ int res = navigation.size();
if (res == 0)
{ return 1; }
return res;
}
public boolean isForbiddenInverse(Attribute ast)
{ Vector v2 = ast.getNavigation();
Attribute q = ast;
if (v2.size() > 0)
{ q = (Attribute) v2.get(0); }
if ((role1 + "").equals(q.getName()) &&
getName().equals("" + q.role1) &&
q.upper == 1)
{ return true; }
return false;
}
public Attribute getFinalFeature()
{ int pathsize = navigation.size();
if (pathsize == 0)
{ return this; }
return (Attribute) navigation.get(pathsize-1);
}
public boolean equals(Object x)
{ if (x instanceof Attribute)
{ Attribute att = (Attribute) x;
if (att.getName().equals(getName()) &&
(att.getType() + "").equals(getType() + "") &&
att.entity == entity)
{ return true; }
}
return false;
}
public boolean isManyValued()
{ return upper == 0; }
public boolean isMultipleValued()
{ if (upper != 1)
{ return true; }
if (lower != 1)
{ return true; }
return false;
}
public boolean isSingleValued()
{ return lower == 1 && upper == 1; }
public void setEntity(Entity e)
{ entity = e; }
public void setType(Type t)
{ type = t;
if (t != null && t.getDefault() != null)
{ initialValue = t.getDefault(); }
}
public void setNavigation(Vector p)
{ navigation = p; }
public boolean isMultiple()
{ if (type == null)
{ return false; }
return type.isCollectionType();
}
public boolean isEntityInstance()
{ if (type == null)
{ return false; }
return type.isEntity();
}
public boolean isSorted()
{ return sorted; }
public boolean isComposition()
{ return hasStereotype("aggregation"); }
public void setElementType(Type et)
{ elementType = et; } // type.setElementType(et) also
public void setSorted(boolean srt)
{ sorted = srt; }
public Object clone()
{ Attribute res = new Attribute(getName(),type,kind);
res.setInitialValue(initialValue);
res.setInitialExpression(initialExpression);
res.setUnique(unique);
res.setFrozen(frozen);
res.setInstanceScope(instanceScope); // "static"
res.setVisibility(visibility);
res.setElementType(elementType);
// res.setEntity(entity); ??
res.sorted = sorted;
return res;
}
public String getJavaType()
{ if (type != null)
{ return type.getJava(); }
return "int";
}
public Type getElementType()
{ return elementType; }
public Vector getNavigation()
{ return navigation; }
public int getLower()
{ return lower; }
public int getUpper()
{ return upper; }
public int getCard1()
{ return card1; }
public static String parList(Vector pars)
{ String res = "";
for (int i = 0; i < pars.size(); i++)
{ Attribute par = (Attribute) pars.get(i);
res = res + " " + par.getName() + " " + par.getType();
}
return res;
}
public boolean isSource()
{ return stereotypes.contains("source"); }
public boolean isTarget()
{ return stereotypes.contains("target"); }
public Attribute mergeAttribute(Attribute att)
{ // checks they can be merged in a common superclass
Attribute res = null;
Type newt = type.mergeType(att.type); // not for collection types
if (newt == null) { return null; }
if (kind == att.kind)
{ res = new Attribute(getName(),newt,kind);
if (initialValue.equals(att.initialValue))
{ res.setInitialValue(initialValue);
if (initialExpression != null)
{ res.setInitialExpression(initialExpression); }
else
{ res.setInitialExpression(att.initialExpression); }
}
if (unique == att.unique)
{ res.setUnique(unique); }
if (frozen == att.frozen)
{ res.setFrozen(frozen); }
if (instanceScope == att.instanceScope)
{ res.setInstanceScope(instanceScope); }
if (visibility == PUBLIC || att.visibility == PUBLIC)
{ res.setVisibility(PUBLIC); }
else
{ res.setVisibility(PROTECTED); }
return res;
}
return null;
}
public void setInitialValue(String val)
{ initialValue = val; }
public void setInitialExpression(Expression e)
{ initialExpression = e; }
public void setUnique(boolean uniq)
{ unique = uniq;
if (uniq)
{ card1 = ModelElement.ZEROONE; }
}
public void setIdentity(boolean uniq)
{ unique = uniq;
if (uniq)
{ card1 = ModelElement.ZEROONE; }
}
public boolean isIdentity()
{ return unique; }
public boolean isIdentityFeature()
{ return card1 == ModelElement.ZEROONE; }
public void setFrozen(boolean fr)
{ frozen = fr; }
public boolean isFinal()
{ return frozen && initialExpression != null; }
public void setInstanceScope(boolean inst)
{ instanceScope = inst; }
public void setStatic(boolean stat)
{ instanceScope = !stat; }
public boolean isStatic()
{ return instanceScope == false; }
public void setVisibility(int visib)
{ visibility = visib; }
public Entity getEntity()
{ return entity; }
public Entity getOwner()
{ return entity; }
public Type getType()
{ return type; }
public int getKind()
{ return kind; }
public String getInitialValue()
{ return initialValue; }
public String getInitialValueSMV()
{ if ("false".equals(initialValue))
{ return "FALSE"; }
if ("true".equals(initialValue))
{ return "TRUE"; }
if ("\"\"".equals(initialValue))
{ return "empty"; }
return initialValue;
}
public Expression getInitialExpression()
{ return initialExpression; }
public int getVisibility()
{ return visibility; }
public String getDefaultValue()
{ if (initialValue != null && !initialValue.equals(""))
{ return initialValue; }
return type.getDefault();
}
public int syntacticComplexity()
{ // att : T = init
int result = 3 + type.complexity();
if (initialExpression != null)
{ result += initialExpression.syntacticComplexity(); }
return result;
}
public boolean isSensor() // or internal
{ return kind == ModelElement.SEN ||
kind == ModelElement.INTERNAL;
}
public boolean isInput()
{ return kind == ModelElement.SEN ||
kind == ModelElement.INTERNAL;
}
public boolean isUnique()
{ return unique; }
public boolean isFrozen()
{ return frozen; }
public boolean isInstanceScope()
{ return instanceScope; }
public boolean isClassScope()
{ return !instanceScope; }
public boolean isUpdatable()
{ return !frozen && kind != ModelElement.DERIVED; }
public boolean isAssignable()
{ return !frozen && kind != ModelElement.SEN; }
public boolean needsControllerOp()
{ return !frozen &&
(kind == ModelElement.SEN || kind == ModelElement.INTERNAL); }
// DERIVED are handled locally?
public void saveEMF(PrintWriter out)
{ out.println(" attr " + getType() + " " + getName() + ";"); }
public void saveKM3(PrintWriter out)
{ if (isStatic())
{ out.println(" static attribute " + getName() + " : " + getType() + ";"); }
out.println(" attribute " + getName() + " : " + getType() + ";");
}
public String getKM3()
{ if (isStatic())
{ return " static attribute " + getName() + " : " + getType() + ";"; }
return " attribute " + getName() + " : " + getType() + ";";
}
public void saveEcore(PrintWriter out)
{ String res = " <eStructuralFeatures xsi:type=\"ecore:EAttribute\" ";
res = res + " name=\"" + getName() + "\"";
if (type.isEnumerated())
{ res = res + " eType=\"#//" + type.getName() + "\""; }
else
{ res = res + " eType=\"ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//" + type.eType() + "\""; }
if (initialValue != null && !initialValue.equals(""))
{ res = res + " defaultValueLiteral=\"" + initialValue + "\" "; }
res = res + "/>";
out.println(res);
}
public String methodDeclaration()
{ String res = "";
res = " " + getType().getJava() + " " + getName();
String initval = getInitialValue();
if (initval != null)
{ res = res + " = " + initval; }
else
{ res = res + " = " + getType().getDefault(); }
res = res + ";\n";
return res;
}
public void generateJava(PrintWriter out)
{ if (visibility == PRIVATE)
{ out.print(" private "); }
else if (visibility == PUBLIC)
{ out.print(" public "); }
else if (visibility == PROTECTED)
{ out.print(" protected "); }
else
{ out.print(" "); }
if (!instanceScope) { out.print("static "); }
if (isFinal()) { out.print("final "); }
type.generateJava(out);
// if (isFinal())
if (initialValue != null)
{ out.print(getName() + " = " + initialValue + ";"); }
else
{ out.print(getName() + ";"); }
if (kind == ModelElement.INTERNAL)
{ out.println(" // internal"); }
else if (kind == ModelElement.SEN)
{ out.println(" // sensor"); } // can be used for volatile data in C
else if (kind == ModelElement.ACT)
{ out.println(" // actuator"); }
else if (kind == ModelElement.DERIVED)
{ out.println(" // derived"); }
}
public String methodDeclarationJava6()
{ String res = "";
res = " " + getType().getJava6() + " " + getName();
Expression initval = initialExpression;
if (initval != null)
{ res = res + " = " + initval.queryFormJava6(new java.util.HashMap(), true); }
else
{ res = res + " = " + getType().getDefaultJava6(); }
res = res + ";\n";
return res;
}
public String methodDeclarationJava7()
{ String res = "";
res = " " + getType().getJava7(elementType) + " " + getName();
Expression initval = initialExpression;
if (initval != null)
{ res = res + " = " + initval.queryFormJava7(new java.util.HashMap(), true); }
else
{ res = res + " = " + getType().getDefaultJava7(); }
res = res + ";\n";
return res;
}
public void generateJava6(PrintWriter out)
{ if (visibility == PRIVATE)
{ out.print(" private "); }
else if (visibility == PUBLIC)
{ out.print(" public "); }
else if (visibility == PROTECTED)
{ out.print(" protected "); }
else
{ out.print(" "); }
if (!instanceScope) { out.print("static "); }
if (isFinal()) { out.print("final "); }
type.generateJava6(out);
if (isFinal() && initialValue != null)
{ out.print(getName() + " = " + initialValue + ";"); }
else
{ out.print(getName() + ";"); }
if (kind == ModelElement.INTERNAL)
{ out.println(" // internal"); }
else if (kind == ModelElement.SEN)
{ out.println(" // sensor"); }
else if (kind == ModelElement.ACT)
{ out.println(" // actuator"); }
else if (kind == ModelElement.DERIVED)
{ out.println(" // derived"); }
}
public void generateJava7(PrintWriter out)
{ if (visibility == PRIVATE)
{ out.print(" private "); }
else if (visibility == PUBLIC)
{ out.print(" public "); }
else if (visibility == PROTECTED)
{ out.print(" protected "); }
else
{ out.print(" "); }
if (!instanceScope) { out.print("static "); }
if (isFinal()) { out.print("final "); }
type.generateJava7(out, elementType);
if (isFinal() && initialValue != null)
{ out.print(getName() + " = " + initialValue + ";"); }
else
{ out.print(getName() + ";"); }
if (kind == ModelElement.INTERNAL)
{ out.println(" // internal"); }
else if (kind == ModelElement.SEN)
{ out.println(" // sensor"); }
else if (kind == ModelElement.ACT)
{ out.println(" // actuator"); }
else if (kind == ModelElement.DERIVED)
{ out.println(" // derived"); }
}
public String methodDeclarationCSharp()
{ String res = "";
res = " " + getType().getCSharp() + " " + getName();
String initval = getInitialValue();
if (initval != null)
{ res = res + " = " + initval; }
else
{ res = res + " = " + getType().getDefaultCSharp(); }
res = res + ";\n";
return res;
}
public void generateCSharp(PrintWriter out)
{ if (visibility == PRIVATE)
{ out.print(" private "); }
else if (visibility == PUBLIC)
{ out.print(" public "); }
else if (visibility == PROTECTED)
{ out.print(" protected "); }
else
{ out.print(" "); }
if (!instanceScope) { out.print("static "); }
if (isFinal()) { out.print("const "); }
type.generateCSharp(out);
if (isFinal() && initialValue != null)
{ out.print(getName() + " = " + initialValue + ";"); }
else
{ out.print(getName() + ";"); }
if (kind == ModelElement.INTERNAL)
{ out.println(" // internal"); }
else if (kind == ModelElement.SEN)
{ out.println(" // sensor"); }
else if (kind == ModelElement.ACT)
{ out.println(" // actuator"); }
else if (kind == ModelElement.DERIVED)
{ out.println(" // derived"); }
}
public String methodDeclarationCPP()
{ String res = "";
res = " " + getType().getCPP(getElementType()) + " " + getName();
String initval = getInitialValue();
if (initval != null)
{ res = res + " = " + initval; }
else
{ res = res + " = " + getType().getDefaultCPP(getElementType()); }
res = res + ";\n";
return res;
} // initialExpression & convert to C++, etc, also for C#
public void staticAttributeDefinition(PrintWriter out, String ename)
{ String res = " " + getType().getCPP(getElementType()) + " " + ename + "::" + getName();
String initval = getInitialValue(); // initialExpression is better
if (initval != null)
{ res = res + " = " + initval; }
else
{ res = res + " = " + getType().getDefaultCPP(getElementType()); }
res = res + ";\n";
out.println(res);
}
public void generateCPP(PrintWriter out)
{ /* if (visibility == PRIVATE)
{ out.print(" private "); }
else if (visibility == PUBLIC)
{ out.print(" public "); }
else if (visibility == PROTECTED)
{ out.print(" protected "); }
else
{ out.print(" "); } */
out.print(" ");
if (!instanceScope) { out.print("static "); }
if (isFinal()) { out.print("const "); }
type.generateCPP(out,elementType);
if (isFinal() && initialValue != null)
{ out.print(getName() + " = " + initialValue + ";"); }
else
{ out.print(getName() + ";"); }
if (kind == ModelElement.DERIVED)
{ out.println(" // derived"); }
else
{ out.println(); }
}
public void generateInterfaceJava(PrintWriter out)
{ if (visibility == PUBLIC && !instanceScope && isFinal())
{ }
else
{ out.print(" // "); }
type.generateJava(out);
if (isFinal())
{ out.println(getName() + " = " + initialValue + ";"); }
else
{ out.println(getName() + ";"); }
}
public void generateInterfaceJava6(PrintWriter out)
{ if (visibility == PUBLIC && !instanceScope && isFinal())
{ }
else
{ out.print(" // "); }
type.generateJava6(out);
if (isFinal())
{ out.println(getName() + " = " + initialValue + ";"); }
else
{ out.println(getName() + ";"); }
}
public void generateInterfaceJava7(PrintWriter out)
{ if (visibility == PUBLIC && !instanceScope && isFinal())
{ }
else
{ out.print(" // "); }
type.generateJava7(out, elementType);
if (isFinal())
{ out.println(getName() + " = " + initialValue + ";"); }
else
{ out.println(getName() + ";"); }
}
public void generateInterfaceCSharp(PrintWriter out)
{ if (visibility == PUBLIC && !instanceScope && isFinal())
{ }
else
{ out.print(" // "); }
type.generateCSharp(out);
if (isFinal())
{ out.println(getName() + " = " + initialValue + ";"); }
else
{ out.println(getName() + ";"); }
}
public void generateMethodJava(PrintWriter out)
{ out.print(" ");
type.generateJava(out);
out.print(getName());
if (initialValue != null && !initialValue.equals(""))
{ out.println(" = " + initialValue + ";"); }
else
{ out.println(";"); }
}
public String saveModelData(PrintWriter out)
{ String nme = getName();
Entity e = getEntity();
String entnme = e + "";
if (e == null)
{ entnme = Identifier.nextIdentifier("attribute_"); }
String cname = nme + "_" + entnme;
String tname = type.getUMLModelName(out);
out.println(cname + " : Property");
out.println(cname + ".name = \"" + nme + "\"");
if (e != null)
{ out.println(cname + " : " + entnme + ".ownedAttribute"); }
out.println(cname + ".type = " + tname);
if (elementType != null)