@@ -19,6 +19,9 @@ import static jce.properties.TextProperty.WRAPPER_SUFFIX
1919import org.eclipse.emf.ecore.InternalEObject
2020import org.eclipse.emf.ecore.EObject
2121import org.eclipse.emf.common.notify.Notifier
22+ import jce.util.IntermediateModelSearcher
23+ import eme.model.IntermediateModel
24+ import org.eclipse.emf.ecore.EStructuralFeature
2225
2326/**
2427 * This class models a wrapper class which unifies an origin code type with its Ecore counterparts in the Ecore model
@@ -29,41 +32,28 @@ class WrapperRepresentation {
2932 extension PathHelper nameUtil
3033 extension EcorificationProperties properties
3134
32- final String packageName
33- final String superClass
35+ String packageName
36+ String superClass
3437 final EClass eClass
35- final String wrapperName
36- final String factoryName
37- final List<TypeParameterRepresentation > typeParameters
38- final List<ConstructorRepresentation > wrapperConstructors
39- final Set<String > importDeclarations
40- final String ecoreInterface
41- final String ecoreImplementation
38+ String wrapperName
39+ String factoryName
40+ List<TypeParameterRepresentation > typeParameters
41+ List<ConstructorRepresentation > wrapperConstructors
42+ Set<String > importDeclarations
43+ String ecoreInterface
44+ String ecoreImplementation
45+ final IntermediateModel model
4246
4347 /**
4448 * Creates a new wrapper representation from an EClass and the EcorificationProperties. The EClass specifies which
4549 * types are unified. The properties specify the employed naming scheme.
4650 */
47- new (EClass eClass, IJavaProject project, EcorificationProperties properties) {
51+ new (EClass eClass, IJavaProject project, IntermediateModel model, EcorificationProperties properties) {
4852 this . eClass = eClass
53+ this . model = model
4954 this . properties = properties
5055 nameUtil = new PathHelper (' .' )
51- packageName = getPackage(eClass)
52- wrapperName = WRAPPER_PREFIX . get + eClass. name + WRAPPER_SUFFIX . get // name of the wrapper class
53- factoryName = ' ' ' «PathHelper.capitalize(packageName.getLastSegment)»Factory«FACTORY_SUFFIX.get»' ' '
54- superClass = getSuperClassName(eClass)
55- wrapperConstructors = ConstructorGenerator . generate(superClass, project, properties)
56- ecoreInterface = append(ECORE_PACKAGE . get, packageName, eClass. name)
57- ecoreImplementation = append(ECORE_PACKAGE . get, packageName, " impl" , eClass. name + " Impl" )
58- typeParameters = TypeParameterGenerator . generate(eClass. ETypeParameters , ecoreImplementation, project, properties)
59- importDeclarations = new HashSet // add import declarations:
60- if (superClass == = null ) {
61- importDeclarations + = InternalEObject . name
62- importDeclarations + = EObject . name
63- importDeclarations + = Notifier . name
64- }
65- wrapperConstructors. forEach[constructor|importDeclarations. addAll(constructor. imports)]
66- typeParameters. forEach[parameter|importDeclarations. addAll(parameter. imports)]
56+ createContent(project) // creates the important parts
6757 }
6858
6959 /**
@@ -109,6 +99,25 @@ class WrapperRepresentation {
10999 def String getPackage() {
110100 return packageName
111101 }
102+
103+ def private createContent(IJavaProject project) {
104+ packageName = getPackage(eClass)
105+ wrapperName = WRAPPER_PREFIX.get + eClass.name + WRAPPER_SUFFIX.get // name of the wrapper class
106+ factoryName = ' ' ' «PathHelper . capitalize(packageName. getLastSegment)»Factory «FACTORY_SUFFIX . get»' ' '
107+ superClass = getSuperClassName(eClass)
108+ wrapperConstructors = ConstructorGenerator.generate(superClass, project, properties)
109+ ecoreInterface = append(ECORE_PACKAGE.get, packageName, eClass.name)
110+ ecoreImplementation = append(ECORE_PACKAGE.get, packageName, "impl", eClass.name + "Impl")
111+ typeParameters = TypeParameterGenerator.generate(eClass.ETypeParameters, ecoreImplementation, project, properties)
112+ importDeclarations = new HashSet // add import declarations:
113+ if(superClass === null) {
114+ importDeclarations += InternalEObject.name
115+ importDeclarations += EObject.name
116+ importDeclarations += Notifier.name
117+ }
118+ wrapperConstructors.forEach[constructor|importDeclarations.addAll(constructor.imports)]
119+ typeParameters.forEach[parameter|importDeclarations.addAll(parameter.imports)]
120+ }
112121
113122 /**
114123 * Builds the super type declaration of a wrapper from a String that is either the super type or null.
@@ -196,16 +205,23 @@ class WrapperRepresentation {
196205 * Returns a special setter for every field which was extracted using multiplicities.
197206 */
198207 def private String getSpecialSetters() ' ' '
199- «FOR field : eClass. EStructuralFeatures »
208+ «FOR field : eClass. EStructuralFeatures SEPARATOR blankLine »
200209 «IF field. upperBound == - 1 »
201- def protected void set«field.name.toFirstUpper» (List «field.name») {
210+ def protected void set«field.name.toFirstUpper» (List<« getGenericArguments ( field )»> «field.name») {
202211 get«field. name. toFirstUpper». clear
203212 get«field. name. toFirstUpper». addAll(«field. name»)
204213 }
205-
206214 «ENDIF »
207215 «ENDFOR »
208216 ' ' ' // TODO (HIGH) replace raw type parameter and add imports
217+
218+ def private String getGenericArguments(EStructuralFeature feature) {
219+ var String result = ""
220+ for (argument : IntermediateModelSearcher.findField(feature, model).genericArguments) {
221+ result += argument.typeString
222+ }
223+ return result
224+ }
209225
210226 /**
211227 * Returns the fully qualified name of the super class of an EClass.
0 commit comments