Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cef801816df2bb8245f2700e458adc46d268d1f2 (plain) (blame)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
/*****************************************************************************
 * Copyright (c) 2011 Nicolas Deblock & Cedric Dumoulin & Manuel Giles.
 *
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * 	Nicolas Deblock  nico.deblock@gmail.com  - Initial transformation and implementation 
 * 	Cedric Dumoulin  Cedric.dumoulin@lifl.fr - Initial transformation and implementation 
 * 	Manuel Giles	 giles.manu@live.fr		 - Initial transformation and implementation 
 *
 *****************************************************************************/ 

import stereotypeUtil;
import Strings;

/* Model type declarations
*/
modeltype UMLmm uses "http://www.eclipse.org/uml2/3.0.0/UML";
modeltype JDTmm uses 'http:///jdtmm.ecore';
modeltype JavaProfile uses java('http://www.eclipse.org/papyrus/JAVA/1');

/**
 *
 */
transformation uml2jdt2( in uml: UMLmm, out jdt: JDTmm)
  extends stereotypeUtil;

/** Root of java stereotypes */
intermediate property UMLmm::STEREOTYPE_JAVA_NAMED_ELEMENT : String;
intermediate property UMLmm::STEREOTYPE_JAVA_GEN : String;
/** Apply to any Types */
intermediate property UMLmm::STEREOTYPE_JAVA_CLASS : String;
intermediate property UMLmm::STEREOTYPE_JAVA_PROJECT : String;
intermediate property UMLmm::STEREOTYPE_JAVA_SRC_FOLDER : String;
intermediate property UMLmm::STEREOTYPE_JAVA_PACKAGE : String;
intermediate property UMLmm::STEREOTYPE_PRIMITIVETYPE : String;

intermediate property UMLmm::TAGVALUE_SRC : String;
intermediate property UMLmm::TAGVALUE_PROJECT : String;
intermediate property UMLmm::TAGVALUE_NAME : String;
intermediate property UMLmm::TAGVALUE_GENERATED : String;
intermediate property UMLmm::TAGVALUE_IMPLEMENTATION_CLASS : String;
intermediate property UMLmm::TAGVALUE_EXPLICIT_REQUIRED_IMPORTS : String;
intermediate property UMLmm::TAGVALUE_EXPLICIT_PLAIN_TEXT_REQUIRED_IMPORTS : String;
intermediate property UMLmm::NO_PACKAGE : String;
/** Default name values for generation */
intermediate property UMLmm::GENERATION_DEFAULT_SRC_NAME : String;
intermediate property UMLmm::GENERATION_DEFAULT_PROJECT_NAME : String;

/**
 *  The main operation. This is the entry point of the transformation.
 */
main() {

  // Initialize global variables
  uml.STEREOTYPE_JAVA_NAMED_ELEMENT := "java::JavaNamedElement";
  uml.STEREOTYPE_JAVA_GEN := "java::JavaGen";
  uml.STEREOTYPE_JAVA_CLASS := "java::JavaClass";
  uml.STEREOTYPE_JAVA_PROJECT := "java::JavaProject";
  uml.STEREOTYPE_JAVA_SRC_FOLDER := "java::JavaSrcFolder";
  uml.STEREOTYPE_JAVA_PACKAGE := "java::JavaPackage_";
  uml.STEREOTYPE_PRIMITIVETYPE := "java::PrimitiveType";
  
  uml.TAGVALUE_SRC := "srcName";
  uml.TAGVALUE_NAME := "name";
  uml.TAGVALUE_GENERATED := "isGenerated";
  uml.TAGVALUE_PROJECT := "projectName";
  uml.TAGVALUE_IMPLEMENTATION_CLASS := "implementationClass";
  uml.TAGVALUE_EXPLICIT_REQUIRED_IMPORTS := "explicitRequiredImports";
  uml.TAGVALUE_EXPLICIT_PLAIN_TEXT_REQUIRED_IMPORTS := "explicitPlainTextRequiredImports";
  uml.NO_PACKAGE := null;
  
  // Default names
  uml.GENERATION_DEFAULT_SRC_NAME := "generated";
  uml.GENERATION_DEFAULT_PROJECT_NAME := "defaultProject";
  
  // Select only object that we want to generate
  var types : Set(uml::Type) := uml.objects()[uml::Type]->select(o | 
             o.oclIsTypeOf(uml::Class) 
             or o.oclIsTypeOf(uml::Interface)
             or o.oclIsTypeOf(uml::PrimitiveType)
             or o.oclIsTypeOf(uml::Enumeration) );
             
  log('------------------------ Start marking input elements');
  // First pass: mark uml::Type objects
  types -> map markUmlType(uml.GENERATION_DEFAULT_SRC_NAME, uml.GENERATION_DEFAULT_PROJECT_NAME);
  // show result
  log('------------------------  Show results');
  types -> map showMarkedType();
  log('------------------------  Show packages results');
  uml.objects()[uml::Package] -> map showMarkedType();
  // Second pass: transform marked objects
  log('------------------------  Start transformation');
  types -> map transformTypeToType();

  log('------------------------  Done');

}

/**
 * A query used to check if a stereotype is applied to an UML element
 */
query uml::Element::isStereotyped( stereotypeName : String ) : Boolean {
	var stereotype = self.getAppliedStereotype(stereotypeName);
    return not stereotype.oclIsUndefined();
}

/**
 * Is the specified type a Compilation Unit ?
 */
query uml::Type::isCompilationUnit( ) : Boolean {

    // A compilation unit is a type whose owner is a Package
    return self.owner.oclIsKindOf(Package);
}

/**
 * Get the interfaces associated to the Classifier
 */
query uml::Classifier::generalInterfaces() : Set(uml::Interface) {
	// Get interface linked by a generalization
//    var res : Set(uml::Interface) :=  self.generalization -> select( p | p.general.oclIsTypeOf(uml::Interface)) 
//                                    -> collect(p | p.general.oclAsType(uml::Interface)) -> asSet();
    var res : Set(uml::Interface) := self.generalization.general[uml::Interface] -> asSet();
      	
  return res;
}

/**
 * Get the ExplicitImports from a classifier.
 * Explicit imports are stored in a Stereotype.
 */
query uml::Classifier::getJavaClassStereotype() : JavaProfile::JavaClass {
	
	var stereotype := self.getAppliedStereotype(uml.STEREOTYPE_JAVA_CLASS);
	if (stereotype.oclIsUndefined())
	then
	  return null
	endif;
	
	var res:JavaProfile::JavaClass := self.getStereotypeApplication(stereotype).oclAsType(JavaProfile::JavaClass);
	return res;
}

/**
 * Get the ExplicitImports from a classifier.
 * Explicit imports are stored in a Stereotype.
 */
query uml::Classifier::getExplicitPlainTextRequiredImports() : Set(String) {
	
	var emptySet : Set(String) := Set{};
	return self.getTaggedValue( uml.STEREOTYPE_JAVA_CLASS, 
	    uml.TAGVALUE_EXPLICIT_PLAIN_TEXT_REQUIRED_IMPORTS, 
	    OclAny ) [String]->asSet();
}

/**
 * Get the interfaces associated to the Classifier
 */
query uml::BehavioredClassifier::generalInterfacesForClass() : Set(uml::Interface) 
{
	// Get interface linked by a generalization
	//    var res : Set(uml::Interface) :=  self.generalization -> select( p | p.general.oclIsTypeOf(uml::Interface)) 
	//                                    -> collect(p | p.general.oclAsType(uml::Interface)) -> asSet();
    var res : Set(uml::Interface) := self.generalization.general[uml::Interface] -> asSet();
        
    // manage the interfaceRealisation
  	res += self.oclAsType(uml::BehavioredClassifier).interfaceRealization.supplier[uml::Interface];    
  	
  return res;
}

/**
 * Get the general Class associated to the Enumeration
 */
query uml::Enumeration::general() : uml::Class {
	// Get interface linked by a generalization
    var res : uml::Class :=  self.generalization.general[uml::Class] -> asOrderedSet() -> first();
                                    
  return res;
}

/**
 * return true if the element is marked has "toGenerate". Return false otherwise.
 */
query uml::NamedElement::isGenerated() : Boolean {
	// by default, generated are true
	var generated := true;
	
	self.getApplicableStereotypes()->forEach(st) {				
			generated := self->getBooleanTaggedValue("java::"+st.name, "isGenerated",generated)->asOrderedSet()->first();
	};

	return generated;
}


/**
 * Compute additional data associated to self.
 * How to compute such datas is dependant of the type of self, so dispatch to the appropriate method.
 *
 * Common ancestor. Dispatch to correct method according to the element's type.
 */
helper NamedElement::getData(defaultSrcName : String, defaultProjectName : String) : TypeMarker {
	
//	log("NamedElement::getData(self.name=" + self.name + ") ");

	// overloading doesn't work, so we do it manually
	if( self.oclIsKindOf(uml::PrimitiveType)) then {
		return self.oclAsType(uml::PrimitiveType).getDataFromPrimitiveType( defaultSrcName, defaultProjectName);
	} endif;
	
	if( self.oclIsKindOf(uml::Type)) then {
		return self.oclAsType(uml::Type).getDataFromType( defaultSrcName, defaultProjectName);
	}
	else {
	  if( self.oclIsKindOf(uml::Package)) then {
		  return self.oclAsType(uml::Package).getDataFromPackage( defaultSrcName, defaultProjectName);
	  } endif;
	} endif;
	// not defined
	return null;
}

/**
 * Compute the additional data for a uml::Type.
 * Recursively set the additional data for the parent (owner) of this type.
 */
helper Type::getDataFromType( defaultSrcName : String, defaultProjectName : String) : TypeMarker {
	
	log( "Type::getDataFromType(self.name=" + self.name + ")");
	// Check if data already exist
	if not self.data.oclIsUndefined()
	then 
	  return self.data 
	endif;
	
	// Create it
	log("Type::getData() - start creation");
	var data : TypeMarker := object TypeMarker {};
	
	var parent :uml::Namespace  := self.namespace; 
	if parent != null 
	  then {
	  //
	  var parentData : TypeMarker := parent.getData(defaultSrcName, defaultProjectName);
	    data.srcName := self.getStringTaggedValue(uml.STEREOTYPE_JAVA_CLASS, uml.TAGVALUE_SRC, parentData.srcName);
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_CLASS, uml.TAGVALUE_PROJECT, parentData.projectName );
	  	data.packageName := parentData.packageName;
	  	data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_CLASS, uml.TAGVALUE_GENERATED, true );
	  }
	  else {
	  	data.srcName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_CLASS, uml.TAGVALUE_SRC, defaultSrcName );
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_CLASS, uml.TAGVALUE_PROJECT, defaultProjectName );
	  	data.packageName := uml.NO_PACKAGE;
	  	data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_CLASS, uml.TAGVALUE_GENERATED, true );
	  }
	endif;
	
	
	self.data := data;
	return data;
}

/**
 * Compute the additional data for a uml::Type.
 * Recursively set the additional data for the parent (owner) of this type.
 *
 * Primitive types are stored in the package declared in uml.TAGVALUE_IMPLEMENTATION_CLASS.
 * If no implementation class is declared, use the same scheme as Classes.
 */
helper PrimitiveType::getDataFromPrimitiveType( defaultSrcName : String, defaultProjectName : String) : TypeMarker {
	
	log("Type::getDataFromPrimitiveType(self.name=" + self.name + ")");
	// Check if data already exist
	if not self.data.oclIsUndefined()
	then 
	  return self.data 
	endif;
	
	// Create it
	log("Type::getData() - start creation");
	var data : TypeMarker := object TypeMarker {};
	
	var parent :uml::Namespace  := self.namespace; 
	if parent != null 
	  then {
	    //
	    var parentData : TypeMarker := parent.getData(defaultSrcName, defaultProjectName);
	    data.srcName := self.getStringTaggedValue(uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_SRC, parentData.srcName);
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_PROJECT, parentData.projectName );
	  	data.packageName := parentData.packageName;
	  	data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_GENERATED, parentData.generated );
	  }
	  else {
	  	data.srcName := self.getStringTaggedValue( uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_SRC, defaultSrcName );
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_PROJECT, defaultProjectName );
	  	data.packageName := uml.NO_PACKAGE;
	  	data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_GENERATED, true );
	  }
	endif;
	
	// Check if an instance name is set
	var instanceClassName := self.getStringTaggedValue(uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_IMPLEMENTATION_CLASS, null);
	if( not instanceClassName.oclIsUndefined()) then {
		// Try to get the package name from the provided qualified name.
		// If none is specified, use the regular package name.
		var packageName : String := instanceClassName.findPackageFromQualifiedName(data.packageName);
		data.packageName := packageName;
	} endif;
	
	self.data := data;
	return data;
}

/**
 * Get the package name of the specified qualifiedname. Return the package name if there is one.
 * Return the nameIfNotFound value if no package is set in qualifiedName.
 * @param nameIfNotFound Default name returned if no package specified in provided String
 */
query String::findPackageFromQualifiedName( nameIfNotFound : String) : String {
	
	// Get the index of the last segment
	var cur : int := self.lastIndexOf('.');
	// return empty string if not found
	var res : String;
	// Do strange comparison because of trouble with
	// QVTo
	if 0>(cur) then {
	  res := nameIfNotFound;
	  } 
	  else {
	  	res := self.substring( 1, cur);
	  } endif;
	
	return res;
}

/**
 * Get the last name from the specified qualifiedname. 
 */
query String::lastNameFromQualifiedName( ) : String {
	
	// Get the index of the last segment
	var cur : Integer := self.lastIndexOf('.');
	// return empty string if not found
	var res : String;
	// Do strange comparison because of trouble with
	// QVTo
	if 0>(cur) then {
	  // Only one name ==> return it
	  res := self;
	  } 
	  else {
	  	cur := cur+2;
	  	res := self.substring( cur, self.size());
	  } endif;
	
	return res;
}


/**
 * Get generation data associated to a Package.
 * Associated stereotype are taken into account to compute the GenData
 */
helper Package::getDataFromPackage(defaultSrcName : String, defaultProjectName : String) : TypeMarker {
	
	log("Type::getDataFromPackage(self.name=" + self.name + ")");
	// Check if data already exist
	if not self.data.oclIsUndefined()
	then 
	  return self.data 
	endif;
	
	var data : TypeMarker;
    
    // Switch to correct helper, according to stereotype
    switch {
    	case (self.isStereotyped( uml.STEREOTYPE_JAVA_SRC_FOLDER) ) {
    		// SrcFolder
	        data :=  self.createDataFromSrcFolder(defaultSrcName, defaultProjectName);
    	}
    	case ( self.isStereotyped( uml.STEREOTYPE_JAVA_PROJECT) ) {
    		// JavaProject
	        data :=  self.createDataFromJavaProject(defaultSrcName, defaultProjectName);
    	}
    	case ( self.isStereotyped( uml.STEREOTYPE_JAVA_PACKAGE)) {
    		// Treat it as a Java Package
    		// uml::Model and uml::Package can be marked with this stereotype.
    		// When a uml::Model is marked as package, it is not considered anymore as a root for packages
	        data :=  self.createDataFromSimplePackage(defaultSrcName, defaultProjectName);
    	}
    	case ( self.oclIsTypeOf(uml::Model) ) {
    		// uml::Model
    		// uml::Model is considered as the root of packages. 
    		// So, stop on type Model, except if a STEREOTYPE_JAVA_PACKAGE is set.
	        data :=  self.createDataFromUmlModel(defaultSrcName, defaultProjectName);
    	}
    	else {
    		// Default Package
	        data :=  self.createDataFromSimplePackage(defaultSrcName, defaultProjectName);
    	}
    };
    
	self.data := data;
	return data;
}

/**
 * Get or create the Data for a Package Stereotypes "SrcFolder"
 */
helper Package::createDataFromSrcFolder(defaultSrcName : String, defaultProjectName : String) : TypeMarker {

  var data := object TypeMarker {};
  var parent : Namespace := self.namespace;
  
	if parent != null 
	  then {
	    //
	    var parentData : TypeMarker := parent.getData(defaultSrcName, defaultProjectName);
	    // We are in an SrcFolder, so srcName is either the stereotype.srcName or self.name
	    data.srcName := self.getStringTaggedValue(uml.STEREOTYPE_JAVA_SRC_FOLDER, uml.TAGVALUE_SRC, self.name);
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_SRC_FOLDER, uml.TAGVALUE_PROJECT, parentData.projectName );
	  	// packageName = "" or null, as we are in a srcFolder (root of packages)
	  	data.packageName := uml.NO_PACKAGE;
	  	// Compute generated: (parent.generated == false ? false : taggedValue || true )
	  	data.generated := if parentData.generated = false then false else self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_SRC_FOLDER, uml.TAGVALUE_GENERATED, true ) endif;
	  }
	  else {
	  	data.srcName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_SRC_FOLDER, uml.TAGVALUE_SRC, self.name );
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_SRC_FOLDER, uml.TAGVALUE_PROJECT, defaultProjectName );
	  	// packageName = "" or null, as we are in a srcFolder (root of packages)
	  	data.packageName := uml.NO_PACKAGE;
	  	data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_SRC_FOLDER, uml.TAGVALUE_GENERATED, true );
	  }
	endif;
	
	
//	self.data := data;
	return data;
}

/**
 * Get or create the Data for this simple Package
 * Don't check if the package is a src or project
 */
helper Package::createDataFromSimplePackage(defaultSrcName : String, defaultProjectName : String) : TypeMarker {

  var data := object TypeMarker {};
  var parent : Namespace := self.namespace;
  
	if parent != null 
	  then {
	    //
	    var parentData : TypeMarker := parent.getData(defaultSrcName, defaultProjectName);
	    data.srcName := self.getStringTaggedValue(uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_SRC, parentData.srcName);
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_PROJECT, parentData.projectName );
	  	data.packageName := self.computePackageName( parentData.packageName, self.getStringTaggedValue(uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_NAME, self.name) );
	  	data.generated := if parentData.generated = false then false else self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_GENERATED, true ) endif;
	  }
	  else {
	  	// This is the root node, and maybe the stereotype overide some values.
	  	data.srcName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_SRC, defaultSrcName );
	  	data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_PROJECT, self.name );
	  	data.packageName := self.getStringTaggedValue(uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_NAME, self.name);
	  	data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_PACKAGE, uml.TAGVALUE_GENERATED, true );
	  }
	endif;
	
	
//	self.data := data;
	return data;
}

/**
 *
 */
helper Package::computePackageName( parentName : String, selfName : String) : String {
	if( parentName.oclIsUndefined() or parentName.length() = 0) then {
		return selfName;
	} endif;
	
	return parentName + "." + selfName;
}

/**
 * Get or create the Data for a Package Stereotypes "Project"
 */
helper Package::createDataFromJavaProject(defaultSrcName : String, defaultProjectName : String) : TypeMarker {

  var data := object TypeMarker {};

  data.srcName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_PROJECT, uml.TAGVALUE_SRC, defaultSrcName );
  // We are in a JavaProject, so the name is either the setereotype.projectName, or the folder name
  data.projectName := self.getStringTaggedValue( uml.STEREOTYPE_JAVA_PROJECT, uml.TAGVALUE_PROJECT, self.name );
  // packageName = "" or null, as we are in a srcFolder (root of packages)
  data.packageName := uml.NO_PACKAGE;
  data.generated := self.getBooleanTaggedValue( uml.STEREOTYPE_JAVA_PROJECT, uml.TAGVALUE_GENERATED, true );
  return data;
}

/**
 * Get or create the Data for a uml::Model with no stereotype
 * This is the root, so stop recursivity
 */
helper Package::createDataFromUmlModel(defaultSrcName : String, defaultProjectName : String) : TypeMarker {

  var data := object TypeMarker {};

  data.srcName := defaultSrcName;
  // Use the name of the Model as project name.
  data.projectName :=  self.name;
  // packageName = "" or null, as we are in a srcFolder (root of packages)
  data.packageName := uml.NO_PACKAGE;
  data.generated := true;
  return data;
}

/**
 * A class used to hold data on a type
 */
intermediate class TypeMarker { 
   isCompilationUnit : Boolean;
   projectName : String;
   srcName : String;
   packageName : String;
   generated : Boolean = true;
  
   }
   
    // log this object
query  TypeMarker::show() : String {
   	 return self.projectName + "-" + self.srcName + "-" + self.packageName; 
/*
   	       + "(isCu=" + self.isCompilationUnit.repr()
   	       + ", isGenerated=" + self.generated.repr()
   	       + ")";
*/
   };
   
/**
 * Add a property to the uml::Type. This property is filled during the first pass.
 * The first pass collect the data that are used during the second pass.
 */
intermediate property uml::NamedElement::data : TypeMarker;
	


/**
 * Show the content of marked type
 */
mapping uml::NamedElement::showMarkedType() 
{
  log( '--------- ' + self.name + " ---------");
  log( 'uml=' + self.repr());
  log( 'data=' + self.data.repr());
  
  log( 'projectName=' + self.data.projectName);
  log( 'srcName    =' + self.data.srcName.repr());
  log( 'packageName=' + self.data.packageName);
  log( 'generated  =' + self.data.generated.repr());
}

/**
 * Map a model to a JavaModel.
 * Compute and associate additional data (in a TypeMarker class) to the type. 
 * Recursively ensure that the data are associated to the container of this type.
 */
mapping uml::Type::markUmlType(defaultSrcName : String, defaultProjectName : String) 
//  when { self.isCompilationUnit() }
{
//  log("------ try to get data for " + self.name);
  if( self.data.oclIsUndefined() ) then {
    log("Compute associated data for '" + self.name + "'");
  	self.data := self.getData( defaultSrcName, defaultProjectName);
  }	endif;
}

/**
 * Map a model to a JavaModel.
 * Compute and associate additional data (in a TypeMarker class) to the type. 
 * Recursively ensure that the data are associated to the container of this type.
 */
mapping uml::Type::markUmlType() 
{
  self.map markUmlType( uml.GENERATION_DEFAULT_SRC_NAME, uml.GENERATION_DEFAULT_PROJECT_NAME);
}

/**
 *
 */
mapping uml::Namespace::getNamespaceMarker() : TypeMarker  {
	
	init {
//		if not self.namespaceMarker.oclIsUndefined() then return self.namespaceMarker endif;
	}
	
	
}

/* ******************************************************************** */
/*                                                                      */
/* ******************************************************************** */
abstract mapping uml::NamedElement::transformNamedElementToJavaElement() : JDTmm::JDTJavaElement
{
	// by default, isGenerated are true
	generated := self.isGenerated();	
	//generated := self.data.generated;	
	
	comment := self.ownedComment.body->asOrderedSet()->first();
	log("************************************" + self.name,comment);
} 


mapping uml::Type::transformTypeToType() : JDTmm::JDTType  	
	disjuncts Class::generateCuClass, Class::generateNestedClass, 
	     Interface::generateCuInterface, Interface::generateNestedInterface, 
	     Enumeration::generateCuEnumeration, Enumeration::generateNestedEnumeration,
	     PrimitiveType::generateCuPrimitiveType
{

}

helper createOrRetrieveJavaModel2() : JDTJavaModel {
	// get the model unique instance, or create it.
	var model : JDTJavaModel  := resolveoneIn(createOrRetrieveJavaModel).oclAsType(JDTJavaModel);
	if( model.oclIsUndefined()) then {
	  model := map createOrRetrieveJavaModel();
	} endif;
	return model;
}

/**
 * Generate a Class that should be a CompilationUnit and set its CompilationUnit
 */
mapping uml::Class::generateCuClass() : JDTmm::JDTClass 
  inherits Class::generateClass /*, NamedElement::transformNamedElementToJavaElement */
  when { self.isCompilationUnit() }
{	
  log("------- transform", self.qualifiedName);	
	compilationUnit := self.map type2CompilationUnit();
}

/**
 * Generate a Class that is nested in another Type
 */
mapping uml::Class::generateNestedClass() : JDTmm::JDTClass 
  inherits Class::generateClass
when { not self.isCompilationUnit() }
{
  log("------- transform", self.qualifiedName);
    // We are NOT a compilation unit, so our parent is a Type
	owner := self.namespace.oclAsType(uml::Type).map transformTypeToType();	
}

/**
 * Generate a Class.
 * set all except its compilationUnit and its owner
 */
mapping uml::Class::generateClass() : JDTmm::JDTClass 
  inherits Classifier::mapTypeToType
{    
//	log( "Interfaces:");
//	self.generalInterfaces()->forEach(c) {
//		log( "  interface=", c.name);
//	};
	log("------- transform", self.qualifiedName);
	interface := false;
	_class := true;
	_enum := false;
	
    // map inheritance
    superClass := self.superClass[uml::Class] -> asOrderedSet() -> first().map transformTypeToType();
    // map interfaces
    superInterfaces := self.generalInterfacesForClass() -> map transformTypeToType();
   	// Properties
	fields := self.ownedAttribute.map propertyToField();
	// Compute property from associations
	// This is already computed from the previous case, as such
	// properties are marked with owner=Classifier
//	fields += self.ownedAttribute.map propertyToAssociationField();
	fields += self[uml::AssociationClass].memberEnd.map propertyToFieldOfAssociationClass();	
	
	//fields.type := self->generateClass() -> asOrderedSet() -> first();
	// Methods
	methods := self.ownedOperation -> map operationToMethod();
}


/**
 * Create a Compilation Unit, and set its packageFragment 
 */
mapping uml::Type::type2CompilationUnit() : JDTCompilationUnit 
	inherits NamedElement::transformNamedElementToJavaElement
{
	
	elementName := self.name;
	// Compute the package fragment from the GenData associated to the type
	var res : JDTPackageFragment := self.data.map typeMarkerToPackageFragment();
	
//	log( "try to set package fragment found packageFragment=", res);
//	log( "     type(.packageFragment)=", self);
	
	// Set the packageFragment of this CU
	// next call has a bug, so we do the opposite affectation:
	// add this CU to its packageFragment
//	packageFragment := res; 
    res.compilationUnits += result;
}

/**
 * Generate a Interface that should be a CompilationUnit and set its CompilationUnit
 */
mapping uml::Interface::generateCuInterface() : JDTmm::JDTInterface 
  inherits Interface::generateInterface /*, NamedElement::transformNamedElementToJavaElement */
  when { self.isCompilationUnit() }
{	
  log("------- transform", self.qualifiedName);	
	compilationUnit := self.map type2CompilationUnit();
	
}

/**
 * Generate a Interface that is nested in another Type
 */
mapping uml::Interface::generateNestedInterface() : JDTmm::JDTInterface 
  inherits Interface::generateInterface
when { not self.isCompilationUnit() }
{
  log("------- transform", self.qualifiedName);	
    // We are NOT a compilation unit, so our parent is a Type
	owner := self.namespace.oclAsType(uml::Type).map transformTypeToType();
}

/**
 * Generate a Interface.
 * set all except its compilationUnit and its owner
 */
mapping uml::Interface::generateInterface() : JDTmm::JDTInterface 
  inherits Classifier::mapTypeToType
{
	interface := true;
	_class := false;
	_enum := false;
	
	    // map interfaces
    superInterfaces := self.generalInterfaces() -> map transformTypeToType();
    	// Properties
	fields := self.ownedAttribute -> map propertyToField();
	// Methods
	methods := self.ownedOperation -> map operationToMethod();
    
	
}

/**
 * Generate a Enumeration that should be a CompilationUnit and set its CompilationUnit
 */
mapping uml::Enumeration::generateCuEnumeration() : JDTmm::JDTEnum 
  inherits Enumeration::generateEnumeration /*, NamedElement::transformNamedElementToJavaElement */
  when { self.isCompilationUnit() }
{	
  log("------- transform", self.qualifiedName);	
	compilationUnit := self.map type2CompilationUnit();
	
}

/**
 * Generate a Enumeration that is nested in another Type
 */
mapping uml::Enumeration::generateNestedEnumeration() : JDTmm::JDTEnum 
  inherits Enumeration::generateEnumeration
when { not self.isCompilationUnit() }
{
  log("------- transform", self.qualifiedName);	
    // We are NOT a compilation unit, so our parent is a Type
	owner := self.namespace.oclAsType(uml::Type).map transformTypeToType();
}

/**
 * Generate a Enumeration.
 * set all except its compilationUnit and its owner
 */
mapping uml::Enumeration::generateEnumeration() : JDTmm::JDTEnum 
  inherits Classifier::mapTypeToType
{
    interface := false;
	_class := false;
	_enum := true;
    
    // map inheritance
    superClass := self.general().map transformTypeToType();
    // map interfaces
    superInterfaces := self.generalInterfaces() -> map transformTypeToType();
    
    // Properties
	fields := self.ownedAttribute -> map propertyToField();

    // Litterals ??
	fields += self.ownedLiteral -> map enumerationLiteral2Field();


	// Methods
	methods := self.ownedOperation -> map operationToMethod();
    
}

mapping uml::EnumerationLiteral::enumerationLiteral2Field() : JDTmm::JDTField
{
	elementName := self.name;
	// visibility
	visibility := self.visibility.visibilityToVisibility();
	// modifiers
	final := false;
	_static := false;
	// multiplicity
	isMultiValued := false;
	// type
	type := null;	
}

/**
 * Generate a primitive type
 */
mapping uml::PrimitiveType::generateCuPrimitiveType() : JDTmm::JDTClass
	inherits Classifier::mapTypeToType
{
  log("------- transform", self.qualifiedName);	
  compilationUnit := self.map type2CompilationUnit();
  
  // Compute elementName
  // Check if another name is set in instanceClassname
  // Set only the last name, because the package name is set previously in the compilationUnit.
  var instanceName : String := self.getStringTaggedValue(uml.STEREOTYPE_PRIMITIVETYPE, uml.TAGVALUE_IMPLEMENTATION_CLASS, null);
  elementName := if( instanceName.oclIsUndefined()) 
                   then self.name
                   else instanceName.lastNameFromQualifiedName()
                 endif;
                 
  // Adjust compilation unit name
  compilationUnit.elementName := elementName;
  
  generated := self.data.generated;
}

/**
 * Generate a Enumeration.
 * set all except its compilationUnit and its owner
 */
abstract mapping uml::Classifier::mapTypeToType() : JDTmm::JDTType 
	inherits NamedElement::transformNamedElementToJavaElement
{
	
	// Ensure that data are set
	if( self.data.oclIsUndefined()) then {
		self.map markUmlType();
	} endif;
	
	elementName := self.name;
	// visibility
	visibility := self.visibility.visibilityToVisibility();
	// modifiers
	_abstract := self.getBooleanTaggedValue("java::JavaClass", "isAbstract",self.isAbstract);
	final := self.getBooleanTaggedValue("java::JavaClass", "isFinal",self.isLeaf);
	_static := self.getBooleanTaggedValue("java::JavaClass", "isStatic", false);
	generated := self.data.generated;
	
	// Explicit imports
	explicitRequiredImports += self.elementImport.target[uml::Classifier] -> map transformTypeToType();
    // Explicit imports from stereotype
    var ext:JavaProfile::JavaClass := self.getJavaClassStereotype();
    explicitRequiredImports += ext.explicitRequiredImports -> map transformTypeToType();
    explicitPlainTextRequiredImports += ext.explicitPlainTextRequiredImports
    
}

/**
 * Transform the visibility.
 */
query uml::VisibilityKind::visibilityToVisibility() : jdtmm::VisibilityKind {
	
	if( self = uml::VisibilityKind::public ) then return jdtmm::VisibilityKind::public endif;
	if( self = uml::VisibilityKind::protected ) then return jdtmm::VisibilityKind::protected endif;
	if( self = uml::VisibilityKind::private ) then return jdtmm::VisibilityKind::private endif;
	
	// Can't happen'
	return jdtmm::VisibilityKind::public;
}

/**
 * Map a Property to a field
 */
mapping uml::Property::propertyToField() : JDTField 
	inherits NamedElement::transformNamedElementToJavaElement
{
	//
	elementName := self.name;
	// visibility
	visibility := self.visibility.visibilityToVisibility();
	// modifiers
	final := self.getBooleanTaggedValue("java::JavaProperty", "isFinal",self.isLeaf);
	_static := self.getBooleanTaggedValue("java::JavaProperty", "isStatic", self.isStatic);
	// getter setter
	generateGetter := self.getEnumTaggedValue("java::JavaProperty", "generateGetter", "default").getTrueFalseDefaultValue();
	generateSetter := self.getEnumTaggedValue("java::JavaProperty", "generateSetter", "default").getTrueFalseDefaultValue();
	
	// multiplicity
	isMultiValued := self.upper < 1;
	// type
	type := self.type.map transformTypeToType();
	
	// Specify the default value
	if(not self.defaultValue.isNull() ) then {
		value := self.defaultValue.valueSpecificationToString();
	} endif;		
}

/**
 * Compute the default value from the ValueSpecification.
 * Check if this is a special case.
 * 
 */
query uml::ValueSpecification::valueSpecificationToString() : String {
	
	switch {
		case (self.oclIsTypeOf(uml::InstanceValue)) {
			var iv := self.oclAsType(uml::InstanceValue );
			
			// Is it an EnumLiteral ?
			if( iv.instance.oclIsTypeOf(uml::EnumerationLiteral)) then {
				// This is an enum literal. Prefix it with its typeName
				return iv.type.name + "." + iv.instance.name;
			} endif;
		}
		else {
			return self.stringValue()
		}
	};
	return "";
}

/**
 * Return the value of the enumeration literal for Enum 'TrueFalseDefault'
 */
query  String::getTrueFalseDefaultValue(): TrueFalseDefault {	
	if(self = "true") then
		return TrueFalseDefault::_true
	else 
		if(self = "false") then
			return TrueFalseDefault::_false
		endif
	endif;
	
	return TrueFalseDefault::_default;
}
/**
 * Map a Property to a field of a association class 
 */
mapping uml::Property::propertyToFieldOfAssociationClass() : JDTField
	inherits Property::propertyToField
{
	
}

/**
 * Map a Property to a association field assoc+nameOfProperty
 */
mapping uml::Property::propertyToAssociationField() : JDTField 
	inherits Property::propertyToField 
when {
	not self.association.oclIsUndefined()
}
{
	// handle the class association
    elementName := "assoc"+ self.name.firstToUpper();    
	type := self.association.map transformTypeToType()->asOrderedSet()->first();
}

/**
 * Map a Operation to a Method
 */
mapping uml::Operation::operationToMethod() : JDTMethod 
	inherits NamedElement::transformNamedElementToJavaElement	
{
	//
	elementName := self.name;
	// visibility
	visibility := self.visibility.visibilityToVisibility();
	// modifiers
	final := self.getBooleanTaggedValue("java::JavaMethod", "isFinal",self.isLeaf);
	_static := self.getBooleanTaggedValue("java::JavaMethod", "isStatic", self.isStatic);
	_abstract := self.getBooleanTaggedValue("java::JavaMethod", "isAbstract", self.isAbstract);
	synchronized := self.getBooleanTaggedValue("java::JavaMethod", "isSynchronized", false);
	
	// constructor 
	_constructor :=  self.getBooleanTaggedValue("java::JavaMethod", "isConstructor", false);
	
	// arguments
	returnType := self.ownedParameter->select(m| m.direction.repr()="return")->first().map parameterToParameter();
	parameters := self.ownedParameter->select(m| m.direction.repr()!="return")-> map parameterToParameter();

    // Body
    bodies := self.method -> map BehaviorToMethodBody();
	// exception
	exceptions := self.raisedException -> map transformTypeToType();
}

mapping uml::Parameter::parameterToParameter() : jdtmm::JDTParameter 
	inherits NamedElement::transformNamedElementToJavaElement
{
	//
	elementName := self.name;
	// modifiers
	final := self.getBooleanTaggedValue("java::JavaClass", "isFinal",false);
	// multiplicity
	isMultiValued := self.upper < 1;
	// type
	type := self.type.map transformTypeToType();
}

/**
 * Transform a Behavior to a JDTMethodBody.
 * Root rule of transforming a Behavior to a JDTMethodBody. The real transformation ois done in sub-rules 
 * (with the same name, but different input type).
 *
 * Behavior can't be transformed to JDTMethodBody, so create a JDTMethodBody with an error message.
 */
mapping uml::Behavior::BehaviorToMethodBody() : jdtmm::JDTMethodBody {
	init {
		var jdtBody := object JDTOpaqueBody {};
		jdtBody._body := "Don't know how to map a Behavior to a Java Body";
		result := jdtBody;
	}
}

/**
 * Transform an OpaqueBehavior to a MethodBody.
 * As we return a subclass of JDTMethodBody, delegate to the appropriate rule.
 */
mapping uml::OpaqueBehavior::BehaviorToMethodBody() : jdtmm::JDTMethodBody {
	init {
		result := self.map OpaqueBehaviorToOpaqueBody();
	}
	
}

/**
 * Transform an OpaqueBehavior to a OpaqueBody
 */
mapping uml::OpaqueBehavior::OpaqueBehaviorToOpaqueBody() : jdtmm::JDTOpaqueBody {
	
//	log("OpaqueBehavior found");
	
	// Look for the java index
	var  index : Integer := self.language->indexOf("Java");
	if ( index >= 0) then {
		_body := self.body->at(index);
	}
	else {
	  _body := "// No 'Java' body found. Please set a 'Java' body in the OpaqueBehavior associted to method.";
	} 
	endif;
}
	
	



/**
 * Get or create the PackageFragment corresponding to the TypeMarker
 */
mapping TypeMarker::typeMarkerToPackageFragment() : JDTPackageFragment {
	
	init {
		// Check if the fragment already exist
		
		// First, lookup fragment root
		var srcRoot:JDTPackageFragmentRoot := self.map typeMarkerToPackageFragmentRoot();
		
		// Second, lookup in srcRoot for an fragment with the same name
		result := srcRoot.packageFragments -> select( fragment  | self.packageName=fragment.elementName)-> asSequence()-> first();
   	
        if( result.oclIsUndefined()) then {
        	log("create fragment " + self.packageName );
        } 
        else {
        	log("reuse fragment '" + result.elementName + "'' for gendata " + self.show() );
        } endif;
        
        // Ideally, we should return here. But this is not allowed in this qvt version
        // return;
	}
	
	// Initialize our object if it is not already done
	if( packageFragmentRoot.oclIsUndefined() ) then {
		
	    // Try one of the end of the relation. Some QVT implementation fail on the first end,
	    // So use the second. (In any cases, we should only affect one end, EMF will do the second end)
		// packageFragmentRoot := srcRoot; // self.map typeMarkerToPackageFragmentRoot();
		srcRoot.packageFragments += result;
		elementName := self.packageName;
		
		// Get the isGenerated Flag
		// Need to know the flag that has been set in the corresponding package.
		// But here, we only got the genData associated to the CompilationUnit, so we
		// can't know the flag value.
		// TODO: improve the algorithm to be able to get the package's flag value
		// actually, always set it to true
		generated := true;
		
/*
		// if package is generated=false, put generated=false for the children's package  	
		if(generated = false) then {
			log("c'est false");
			srcRoot.packageFragments->forEach(pack) {
				log("**********************"+pack.elementName, pack.elementName.indexOf(elementName));			
				if (pack.elementName.indexOf(elementName) != -1) then {
					pack.generated := false;
					log("************************ elementName passé à ", generated);	
				} endif;
			};
		} endif;
*/		
	} endif;
	
}

/**
 * Get or create the PackageFragmentRoot corresponding to the TypeMarker
 */
mapping TypeMarker::typeMarkerToPackageFragmentRoot() : JDTPackageFragmentRoot {
	
	init {
		// Check if the fragment already exist
		
		// First, lookup corresponding project
		var project:JDTJavaProject := self.map typeMarkerToJavaProject();
		
		// Second, lookup in project for an srcRoot with the same name
		result := project.packageFragmentRoots -> select( srcRoot  | self.srcName=srcRoot.elementName)-> asSequence()-> first();

        if( result.oclIsUndefined()) then {
        	log("create PackageFragmentRoot " + self.srcName );
        } 
        else {
        	log("reuse PackageFragmentRoot '" + result.elementName + "' for gendata " + self.show() );
        } endif;
        
        
        // Ideally, we should return here. But this is not allowed in this qvt version
        // return;
	}
	
	// Initialize our object if it is not already done
	if( javaProject.oclIsUndefined() ) then {
	  javaProject := project; // self.map typeMarkerToJavaProject();
	  elementName := self.srcName;	
		// Get the isGenerated Flag
		// Need to know the flag that has been set in the corresponding package.
		// But here, we only got the genData associated to the CompilationUnit, so we
		// can't know the flag value.
		// TODO: improve the algorithm to be able to get the package's flag value
		// actually, always set it to true
		generated := true;
	} endif;
}

/**
 * Get or create the PackageJavaProject corresponding to the TypeMarker
 */
mapping TypeMarker::typeMarkerToJavaProject() : JDTJavaProject {
	
	init {
		// Lookup if there is a Project already created for this projectName
		// resolveIn return a list of object created with the specified mapping rule
		// Then, we loukup in the list for an element with the requested name.
		result := resolveIn(TypeMarker::typeMarkerToJavaProject)
		    ->select( project  | self.projectName=project.oclAsType(JDTJavaProject).elementName)->first().oclAsType(JDTJavaProject);

	
        if( result.oclIsUndefined()) then {
        	log("create project " + self.projectName );
        } 
        else {
        	log("reuse project '" + result.elementName + "'' for gendata " + self.show() );
        } endif;
        

        // Ideally, we should return here. But this is not allowed in this qvt version
        // return;
	}
	
	// Initialize our object if it is not already done
 	if( javaModel.oclIsUndefined() ) then {
	  javaModel := map createOrRetrieveJavaModel();
	  elementName := self.projectName;	
		// Get the isGenerated Flag
		// Need to know the flag that has been set in the corresponding package.
		// But here, we only got the genData associated to the CompilationUnit, so we
		// can't know the flag value.
		// TODO: improve the algorithm to be able to get the package's flag value
		// actually, always set it to true
		generated := true;
	} endif;
}

/**
 *
 */
mapping createOrRetrieveJavaModel () : JDTJavaModel {
init {
 // result := resolveoneIn(createOrRetrieveJavaModel).oclAsType(JDTJavaModel);
//  if not result.oclIsUndefined() then{ return c; }endif;
}
 	generated := true;
  	elementName := "JavaModel";
}

Back to the top