Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b42ee8d60404b8cf98a720bbe14282ac007ef2dc (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
/*
 * Copyright (c) 2008 Borland Software Corporation
 * 
 * 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:
 *    Artem Tikhomirov (Borland) - initial API and implementation
 */

«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«IMPORT "http://www.eclipse.org/emf/2002/GenModel"»

«EXTENSION MetaModel»

/*
 * Does instanceof check.
 */
«DEFINE IsInstance(String accessor) FOR GenClass-»
«accessor» instanceof «getQualifiedInterfaceName()»«ENDDEFINE»

// Shorthand, negates IsInstance - handy if you consider
// different approaches for generated and dynamic models: false == instanceof
// vs. !MetaModelFacility.isInstance
«DEFINE NotInstance(String accessor) FOR GenClass-»
false == «EXPAND IsInstance(accessor)»«ENDDEFINE»

/**
 * Special kind of instanceof check, that compares eContainer() of the object.
 * Since metaClass may be an external interface, eContainer() might need cast to EObject  
 */
«DEFINE IsContainerInstance(String object, GenClass metaClass) FOR GenClass-»
«EXPAND _getEObjectFeature(object, "eContainer()") FOR metaClass» instanceof «getQualifiedInterfaceName()»«ENDDEFINE»

«DEFINE _getEObjectFeature(String object, String feature) FOR GenClass-»
«IF isExternalInterface()»((org.eclipse.emf.ecore.EObject) «object»).«feature»«ELSE»«object».«feature»«ENDIF-»
«ENDDEFINE»

// Public/API-sort templates are named with first letter capitalized.
// FIXME getFeatureValue* and setFeatureValue start with lowercase to indicate pending refactoring

«DEFINE getFeatureValue(String containerVar, genmodel::GenClass containerClass) FOR genmodel::GenFeature-»
«IF isExternalInterface(containerClass)-»
((«EXPAND featureTargetType») ((org.eclipse.emf.ecore.EObject) «containerVar»).eGet(«EXPAND MetaFeature»))«-»
«ELSE-»
«containerVar».«getGetAccessor()»()«-»
«ENDIF-»
«ENDDEFINE»

«DEFINE featureTargetType FOR GenFeature»«IF isListType()»java.util.List«ELSE»«EXPAND QualifiedClassName FOR findGenClassifier(genClass.genPackage.genModel, ecoreFeature.eType)»«ENDIF»«ENDDEFINE»

/*
 * FIXME leave only one version of these two getFeatureValue
 *
 * A slightly more sophisticated version of getFeatureValue().
 * @param containerName the name of the container
 * @param feature the feature whose value is in interest
 * @param containerMetaClass the <code>GenClass</code> of the container, or <code>null</code>, if the container is declared as an <code>org.eclipse.emf.ecore.EObject</code>.
 * @param needsCastToResultType whether the cast to the result type is required (this parameter is only used if the <code>org.eclipse.emf.ecore.EClass</code> this feature belongs to is an external interface). 
 */
«DEFINE getFeatureValue(String containerVar, genmodel::GenClass container, boolean needsCastToResultType) FOR genmodel::GenFeature-»
«IF isExternalInterface(genClass)-»
«IF needsCastToResultType»((«EXPAND featureTargetType») «ENDIF»«containerVar.parenthesizedCast(container, null)».eGet(«EXPAND MetaFeature»)«IF needsCastToResultType»)«ENDIF-»
«ELSE-»
«containerVar.parenthesizedCast(container, genClass)».«getGetAccessor()»()«-»
«ENDIF-»
«ENDDEFINE»

«DEFINE setFeatureValue(String containerVar, genmodel::GenClass containerGenClass, String valueVar) FOR genmodel::GenFeature-»
«EXPAND setFeatureValue(containerVar, containerGenClass, valueVar, false)»«ENDDEFINE»

// FIXME support list features as well, i.e. do .add() instead of eSet
«DEFINE setFeatureValue(String containerVar, genmodel::GenClass containerGenClass, String valueVar, boolean isPlainObjectValue) FOR genmodel::GenFeature-»
«IF isExternalInterface(containerGenClass)-»
((org.eclipse.emf.ecore.EObject) «containerVar»).eSet(«EXPAND MetaFeature», «valueVar»)«-»
«ELSE-»
«containerVar».set«getAccessorName(this)»(«IF !isPlainObjectValue»«valueVar»«ELSE»«IF isPrimitiveType()»«EXPAND _unwrapObjectToPrimitiveValue(valueVar)»«ELSE»(«EXPAND featureTargetType») «valueVar»«ENDIF»«ENDIF»)«-»
«ENDIF-»
«ENDDEFINE»

«DEFINE _unwrapObjectToPrimitiveValue(String valueVar) FOR GenFeature-»
((«EXPAND featureTargetType») «valueVar»).«ecoreFeature.eType.instanceClassName»Value()«ENDDEFINE»

«DEFINE MetaClass FOR genmodel::GenClassifier»«getQualifiedPackageInterfaceName(genPackage)».eINSTANCE.get«getClassifierAccessorName(this)»()«ENDDEFINE»

«DEFINE MetaFeature FOR genmodel::GenFeature»«getQualifiedPackageInterfaceName(genClass.genPackage)».eINSTANCE.get«getFeatureAccessorName(this)»()«ENDDEFINE»

// SomeFactory.eINSTANCE.createBlaBla();
//NB: for map entries, the resulting type is EObject, not the qualified interface name. If cast is needed, use (un)parenthesizedCast() extension.
//see GenClassImpl#hasFactoryInterfaceCreateMethod() for details why map entries should be treated differently
«DEFINE NewInstance FOR genmodel::GenClass-»
«IF isMapEntry()-»
«genPackage.getQualifiedFactoryInterfaceName()».«genPackage.getFactoryInstanceName()».create(«EXPAND MetaClass»)«ELSE-»
«genPackage.getQualifiedFactoryInterfaceName()».«genPackage.getFactoryInstanceName()».create«ecoreClass.name»()«ENDIF-»
«ENDDEFINE»

// XXX Need to take into account possible GenClass from generated and always available code
// e.g. Notation or Ecore 

«DEFINE NewInstance(String varName) FOR genmodel::GenClass-»
«getQualifiedInterfaceName()» «varName» = «IF isMapEntry()»(«getQualifiedInterfaceName()») «ENDIF»«EXPAND NewInstance»;
«ENDDEFINE»

/*
 * Ensures value is of type EObject, may be no-op if context GenClass is compatible with EObject.
 * Note, injected value is not surrounded with parenthesis, may need to introduce another
 * template to accomplish that if needed.
 */
«DEFINE DowncastToEObject(String value) FOR genmodel::GenClass»«IF isExternalInterface()»(org.eclipse.emf.ecore.EObject) «ENDIF»«value»«ENDDEFINE»

/*
 * Declares new variable of appropriate type and assigns casted value to it.
 */
«DEFINE DeclareAndAssign(String assignee, String value) FOR GenClass-»
«getQualifiedInterfaceName()» «assignee» = («getQualifiedInterfaceName()») «value»;«ENDDEFINE»

/*
 * third boolean parameter is to indicate the value is not EObject, so may
 * need extra cast in case dynamic model instances are in use.
 */
«DEFINE DeclareAndAssign(String assignee, String value, boolean isPlainObjectValue) FOR GenClass-»
«EXPAND DeclareAndAssign(assignee, value)»«ENDDEFINE»

«DEFINE DeclareAndAssign(String assignee, String value, boolean isPlainObjectValue) FOR GenClassifier-»
«getQualifiedClassName()» «assignee» = («getQualifiedClassName()») «value»;«ENDDEFINE»

// @see IsContainerInstance
«DEFINE DeclareAndAssignContainer(String assignee, String object, GenClass metaClass) FOR GenClass-»
«getQualifiedInterfaceName()» «assignee» = («getQualifiedInterfaceName()») «EXPAND _getEObjectFeature(object, "eContainer()") FOR metaClass»;«ENDDEFINE»

/*
 * Declares new variable of context type and assignes a value obtained from 'src',
 * which is of type 'srcMetaClass', via 'srcFeature'
 *
 * XXX in certain scenarions may need extra cast of the feature value
 */
«DEFINE DeclareAndAssign(String assignee, String src, GenClass srcMetaClass, GenFeature srcFeature) FOR GenClass-»
«getQualifiedInterfaceName()» «assignee» = «EXPAND getFeatureValue(src, srcMetaClass) FOR srcFeature»;«ENDDEFINE»

/*
 * Same as DeclareAndAssign, with extra operation applied to source object
 */
«DEFINE DeclareAndAssign2(String assignee, String src, GenClass srcMetaClass, GenFeature srcFeature, String srcExt, boolean needCast) FOR GenClass-»
«getQualifiedInterfaceName()» «assignee» = «IF needCast»(«getQualifiedInterfaceName()») «ENDIF»«EXPAND getFeatureValue(src, srcMetaClass) FOR srcFeature».«srcExt»;«ENDDEFINE»

/*
 * Cast value of type EObject to specific type. Would be no-op with dynamic model instances,
 * therefore, the fact eObjectValue is actually EObject is essential
 */
«DEFINE CastEObject(String eObjectValue) FOR GenClass»(«getQualifiedInterfaceName()») «eObjectValue»«ENDDEFINE»

/**
 * Qualified interface name of the generated EClass, or EObject for dynamic models.
 * Use whenever class name is inevitable (e.g. method arguments)
 * SHOULD NEVER APPEAR in instanceof or any other similar comparison operation
 */
«DEFINE QualifiedClassName FOR GenClass»«getQualifiedInterfaceName()»«ENDDEFINE»
«DEFINE QualifiedClassName FOR GenClassifier»«getQualifiedClassName()»«ENDDEFINE»

«DEFINE PopulateItemProviderFactories(String factoryListVar) FOR GenEditorGenerator-»
«FOREACH getAllDomainGenPackages(true) AS genPackage-»
		«factoryListVar».add(new «genPackage.getQualifiedItemProviderAdapterFactoryClassName()»());
«ENDFOREACH-»
«ENDDEFINE»

Back to the top