[XCore] Compiler overrides code tagged as not generated [message #1060282] |
Thu, 23 May 2013 20:41  |
Eclipse User |
|
|
|
Hi,
I recently upgraded to Eclipse 4.3RC1 I20130516-2200 and XCore 1.1.0.v20130508-0449. I realized different code generation behavior. Code tagged as @generated_NOT gets overwritten. In fact even custom code gets overwritten. I created a simple that reflects this issue.
@GenModel(prefix="EMFTest", modelName="EMFTest")
package emftest
class ClassA{
String name
op void printStatus()
}
Then I modify ClassAImpl.java
private String message = "Hello";
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated_NOT
*/
public void printStatus()
{
System.out.println("ClassAImpl.printStatus()");
}
If I modify the .xcore meta-model, the previous code gets overwritten?
Thanks for your help.
|
|
|
Re: [XCore] Compiler overrides code tagged as not generated [message #1060315 is a reply to message #1060282] |
Fri, 24 May 2013 06:43   |
Eclipse User |
|
|
|
Régent,
If you generated into the default src-gen folder, then all the files are
marked as derived and you get behaviors such as doing a Clean build
removes all your generated files in the src-gen folder. Given such
behavior, it's not a good idea to rely on merging to accomplish anything
that needs to be preserved because you can end up losing them anyway if
and when you do a clean build. So as part of
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404419 I changed the
behavior so it doesn't merge at all; that also makes regeneration
significantly faster. As such, if you want to change that behavior to
also support merging, you can add a @GenModel annotation to the package
declaration in the Xcore source:
@GenModel(modelDirectory="/<your-project-name>/src")
On 23/05/2013 10:41 PM, Régent L Archevêque wrote:
> Hi,
>
> I recently upgraded to Eclipse 4.3RC1 I20130516-2200 and XCore
> 1.1.0.v20130508-0449. I realized different code generation behavior.
> Code tagged as @generated_NOT gets overwritten. In fact even custom
> code gets overwritten. I created a simple that reflects this issue.
>
>
> @GenModel(prefix="EMFTest", modelName="EMFTest")
> package emftest
> class ClassA{
> String name
> op void printStatus()
> }
>
>
> Then I modify ClassAImpl.java
>
> private String message = "Hello";
>
> /**
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @generated_NOT
> */
> public void printStatus()
> {
> System.out.println("ClassAImpl.printStatus()");
> }
>
>
> If I modify the .xcore meta-model, the previous code gets overwritten?
>
> Thanks for your help.
>
|
|
|
Re: [XCore] Compiler overrides code tagged as not generated [message #1060410 is a reply to message #1060315] |
Fri, 24 May 2013 14:12   |
Eclipse User |
|
|
|
Thanks Ed for the quick answer.
As you mentioned, I renamed the modelDirectory source directory and it works now.
I know it is not the preferred way to add custom code in the generated-code. In general, we implement basic operations in XCore and complex operations in Java. Sometimes we carefully use <functionName>Gen() pattern to provide additional functionality to getters. We use EMF since the last 10 years, we do not see how we can change our modeling/programming strategy in these particular cases. Do you have tips / tricks that we could explore? We try to stay on-the-edge with EMF but we may miss some important features / guidelines. On our side, the meta-model serves not only as data-model. I think most of the community uses EMF for that purpose.
Regent
|
|
|
Re: [XCore] Compiler overrides code tagged as not generated [message #1060424 is a reply to message #1060410] |
Fri, 24 May 2013 15:13   |
Eclipse User |
|
|
|
Régent,
Comments below.
On 24/05/2013 4:12 PM, Régent L Archevêque wrote:
> Thanks Ed for the quick answer.
>
> As you mentioned, I renamed the modelDirectory source directory and it
> works now.
>
> I know it is not the preferred way to add custom code in the
> generated-code. In general, we implement basic operations in XCore and
> complex operations in Java.
In terms of Xcore's block expressions, Xbase (as extended by Xcore) is
sufficiently expressive that there isn't really anything that you can do
in Java that can't be expressed in Xbase, and often more
concisely/elegantly...
> Sometimes we carefully use <functionName>Gen() pattern to provide
> additional functionality to getters.
Yes, there's an outstanding bugzilla about being able to express logic
for a getter without marking it as derived, but I've had no time for that.
> We use EMF since the last 10 years, we do not see how we can change
> our modeling/programming strategy in these particular cases.
Yes, there are still limitations with Xcore, one of the most important
ones being the inability to declare fields for the implementation classes...
> Do you have tips / tricks that we could explore?
No, not really.
> We try to stay on-the-edge with EMF but we may miss some important
> features / guidelines.
It's nice to see Xcore being used. It's so much simpler than using the
Sample Ecore Editor and gives such a nice complete overview of the model
structure...
> On our side, the meta-model serves not only as data-model. I think
> most of the community uses EMF for that purpose.
It's also very common to add behavior to a model, but I have no
statistics as to what percentage of the use cases that that approach.
>
> Regent ;)
|
|
|
|
Powered by
FUDForum. Page generated in 0.04225 seconds