[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.modeling.mdt.uml2.uml] Re: Questions about code generation rules in uml2
|
Sunny,
Note sure why one would need to reverse-engineer the UML2 code generator
(the source is openly available and the logic is in the templates), but I'll
try to answer your questions as best I can... see below.
"Sunny" <sunfire001@xxxxxxxxx> wrote in message
news:b2a5fbd6b836f32c4dc8173a3aaac382$1@xxxxxxxxxxxxxxxxxx
> Hi,
>
> I am trying to reverse engineer associations from the uml2's
> implementation (based on UML2.0 spec. and uml2_1.1.1). I would like to
> know the generation rules for its code:
>
> 1. in what situation a field is (or is not) generated for a navigable
> association end in the implementation class? For example, a field
> Classifier#generalization is generated for the association from Classifier
> to Generalization (pp.26), but not for the association from ActivityGroup
> to ActivityNode (pp.288)
>
The logic for whether to generate a field is fairly complex, but generally
one is generated iff it meets the usual EMF criteria and such a field does
not already exist in the class hierarchy, the feature is not a union, and
the feature has not been redefined. See the source for
org.eclipse.uml2.codegen.ecore.genmodel.impl.GenClassImpl#getDeclaredFieldGenFeatures()
for details.
> 2. in what situation, a createRoleName() is generated (e.g.,
> Classifier#createGeneralization())?
These factory methods are generated iff the option has been turned on in the
generator model, the feature is changeable, the feature is effectively a
containment feature (or a subset of one) and the feature's class has at
least one child class. See the source for
org.eclipse.uml2.codegen.ecore.genmodel.util.isFactoryMethods(GenClass,
GenFeature) for details.
>
> 3. is it true that only when the type of an association end is a subclass
> of NamedElement, is a method getRoleName(String name) generated (e.g.,
> Classifier#getRedefinedClassifier(String name))?
No, these look-up methods are generated for any multiplicity-many reference
feature which is typed by a type that has one of its features marked as a
"key" in the generator model. See the source for
org.eclipse.uml2.codegen.ecore.genmodel.util.getKeyGenFeatures(GenFeature)
for details.
> 4. how are association ends subsetting other ends specially handled in the
> generated code? (e.g., what kind of code will be generated if an
> association end subsets another end)
>
This depends on whether the feature and its superset are multiplicity-many
or not... Generally, the getter for a multiplicity-many subset is generated
to use a special subset/superset list - see
org.eclipse.uml2.codegen.ecore.genmodel.impl.GenClassImpl#getSubsetListConstructor(GenFeature)
for details - whereas a scalar feature gets extra code appended to its
setter to also add elements to the superset feature - see
templates/model/Class/setGenFeature.post.insert.javajetinc for details.
> 5. how are association ends redefining other ends specially handled in the
> generated code?
The accessor for the other end is generally overridden to call the accessor
for the redefining end.
> I checked the book "EMF Modeling Framework" and could not find all the
> corresponding rules to generate the uml2_1.1.1's code. For example, it
> only says that a field won't be generated for a volatile or non-changeable
> reference? It says nothing about the handling for subsetting or
> redefinition...
Of course not - all of the support for UML constructs like subsetting,
unions, redefinitions, etc. isn't part of EMF, but rather is provided by the
UML2 code generator. I apologize for the lack of documentation...
>
> Your help is much appreciated,
>
> -- Sunny
>
>