Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Format generated Code
Format generated Code [message #423253] Thu, 25 September 2008 14:22 Go to next message
Eclipse UserFriend
Originally posted by: fdo.scodi.ch

Hello

In my workspace I have set the "Save Actions" which also formats the code
the way I want.

Now if I generate code from my genmodel, the output format is different as
the rest of my classes. Another problem is the modification of those
classes, as soon as I save my changes and want to commit to our svn
repository I have a whole lot of changes.

I started to modify the
org.eclipse.emf.codegen.ecore/templates/model/Class.javajet, but this
can't be the solution.

Is it some how possible to tell the generator to use my code formatting or
tell it to do a "save" after generation?
The genmodel does have a "Code Formatting" option, but that doesn't solve
the problem. It doesn't format the way I defined it in the preferences.

I appreciate any help!
Re: Format generated Code [message #423256 is a reply to message #423253] Thu, 25 September 2008 14:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30825
Registered: July 2009
Senior Member
Flavio,

Comments below.

Flavio Donzé wrote:
> Hello
>
> In my workspace I have set the "Save Actions" which also formats the
> code the way I want.
>
> Now if I generate code from my genmodel, the output format is
> different as the rest of my classes. Another problem is the
> modification of those classes, as soon as I save my changes and want
> to commit to our svn repository I have a whole lot of changes.
>
> I started to modify the
> org.eclipse.emf.codegen.ecore/templates/model/Class.javajet, but this
> can't be the solution.
>
> Is it some how possible to tell the generator to use my code
> formatting or tell it to do a "save" after generation?
> The genmodel does have a "Code Formatting" option, but that doesn't
> solve the problem. It doesn't format the way I defined it in the
> preferences.
It invokes the regular Eclipse formatter which is based on your
preferences. But I think save actions can include more than just
formatting. Is it related to some type of cleanup action rather than
just formatting?
>
> I appreciate any help!
>
Re: Format generated Code [message #423260 is a reply to message #423256] Thu, 25 September 2008 15:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fdo.scodi.ch

Well I have my own formatter, not the "Eclipse [built-in]". Does it take
the default provided by Eclipse or my selected "Active profile"? Probably
not my profile, for example the toString method:

// after my save
public String toString() {
if (eIsProxy()) {
return super.toString();
}
// after emf generation
public String toString() {
if (eIsProxy())
return super.toString();

The braces are missing.

Ahh, just found out that this is not a formatting but a "Code Style"
option, which is also applied during the "save process".

Well then, is it possible to apply this code style to the generated code?

I disabled the "Code Style" option and saved the class again, I still get
a different output, especially the javadoc comments.

I still think the default Eclipse formatting is used instead of my active
profile.

Ed Merks wrote:

> Flavio,

> Comments below.

> Flavio Donzé wrote:
>> Hello
>>
>> In my workspace I have set the "Save Actions" which also formats the
>> code the way I want.
>>
>> Now if I generate code from my genmodel, the output format is
>> different as the rest of my classes. Another problem is the
>> modification of those classes, as soon as I save my changes and want
>> to commit to our svn repository I have a whole lot of changes.
>>
>> I started to modify the
>> org.eclipse.emf.codegen.ecore/templates/model/Class.javajet, but this
>> can't be the solution.
>>
>> Is it some how possible to tell the generator to use my code
>> formatting or tell it to do a "save" after generation?
>> The genmodel does have a "Code Formatting" option, but that doesn't
>> solve the problem. It doesn't format the way I defined it in the
>> preferences.
> It invokes the regular Eclipse formatter which is based on your
> preferences. But I think save actions can include more than just
> formatting. Is it related to some type of cleanup action rather than
> just formatting?
>>
>> I appreciate any help!
>>
Re: Format generated Code [message #423264 is a reply to message #423260] Thu, 25 September 2008 15:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30825
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000004080208050002040805
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Flavio,

It should be using the project's options:

public static Object createCodeFormatter(Map<?, ?> options,
String workspacePath)
{
if (options == null)
{
IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(new
Path(workspacePath).segment(0));
if (project != null)
{
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null)
{
options = javaProject.getOptions(true);
}
}
}
return ToolFactory.createCodeFormatter(options);
}

And if the project doesn't have local options, this should use the
globally applicable ones.

But what you describe is more than formatting. I'm not sure there is a
programmatic way to invoke save actions.


Flavio Donz
Re: Format generated Code [message #423267 is a reply to message #423264] Thu, 25 September 2008 15:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: fdo.scodi.ch

ok, thanks Ed!

I found out that the "Save actions" are almost equal to the "Clean up"
preferences.
Do you think this would be possible to invoke? That would solve the
problem.

Ed Merks wrote:

> Flavio,

> It should be using the project's options:

> public static Object createCodeFormatter(Map<?, ?> options,
> String workspacePath)
> {
> if (options == null)
> {
> IProject project =
> ResourcesPlugin.getWorkspace().getRoot().getProject(new
> Path(workspacePath).segment(0));
> if (project != null)
> {
> IJavaProject javaProject = JavaCore.create(project);
> if (javaProject != null)
> {
> options = javaProject.getOptions(true);
> }
> }
> }
> return ToolFactory.createCodeFormatter(options);
> }

> And if the project doesn't have local options, this should use the
> globally applicable ones.

> But what you describe is more than formatting. I'm not sure there is a
> programmatic way to invoke save actions.


> Flavio Donzé wrote:
>> Well I have my own formatter, not the "Eclipse [built-in]". Does it
>> take the default provided by Eclipse or my selected "Active profile"?
>> Probably not my profile, for example the toString method:
>>
>> // after my save
>> public String toString() {
>> if (eIsProxy()) {
>> return super.toString();
>> }
>> // after emf generation
>> public String toString() {
>> if (eIsProxy())
>> return super.toString();
>>
>> The braces are missing.
>>
>> Ahh, just found out that this is not a formatting but a "Code Style"
>> option, which is also applied during the "save process".
>>
>> Well then, is it possible to apply this code style to the generated code?
>>
>> I disabled the "Code Style" option and saved the class again, I still
>> get a different output, especially the javadoc comments.
>>
>> I still think the default Eclipse formatting is used instead of my
>> active profile.
>>
>> Ed Merks wrote:
>>
>>> Flavio,
>>
>>> Comments below.
>>
>>> Flavio Donzé wrote:
>>>> Hello
>>>>
>>>> In my workspace I have set the "Save Actions" which also formats the
>>>> code the way I want.
>>>>
>>>> Now if I generate code from my genmodel, the output format is
>>>> different as the rest of my classes. Another problem is the
>>>> modification of those classes, as soon as I save my changes and want
>>>> to commit to our svn repository I have a whole lot of changes.
>>>>
>>>> I started to modify the
>>>> org.eclipse.emf.codegen.ecore/templates/model/Class.javajet, but
>>>> this can't be the solution.
>>>>
>>>> Is it some how possible to tell the generator to use my code
>>>> formatting or tell it to do a "save" after generation?
>>>> The genmodel does have a "Code Formatting" option, but that doesn't
>>>> solve the problem. It doesn't format the way I defined it in the
>>>> preferences.
>>> It invokes the regular Eclipse formatter which is based on your
>>> preferences. But I think save actions can include more than just
>>> formatting. Is it related to some type of cleanup action rather than
>>> just formatting?
>>>>
>>>> I appreciate any help!
>>>>
>>
>>
Re: Format generated Code [message #423269 is a reply to message #423267] Thu, 25 September 2008 16:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30825
Registered: July 2009
Senior Member
Flavio,

I don't know if there is a programmatic way to invoke that. If someone
could determine how to do it programatically, that we could look at how
to invoke that...


Flavio Donzé wrote:
> ok, thanks Ed!
>
> I found out that the "Save actions" are almost equal to the "Clean up"
> preferences.
> Do you think this would be possible to invoke? That would solve the
> problem.
>
> Ed Merks wrote:
>
>> Flavio,
>
>> It should be using the project's options:
>
>> public static Object createCodeFormatter(Map<?, ?> options,
>> String workspacePath)
>> {
>> if (options == null)
>> {
>> IProject project =
>> ResourcesPlugin.getWorkspace().getRoot().getProject(new
>> Path(workspacePath).segment(0));
>> if (project != null)
>> {
>> IJavaProject javaProject = JavaCore.create(project);
>> if (javaProject != null)
>> {
>> options = javaProject.getOptions(true);
>> }
>> }
>> }
>> return ToolFactory.createCodeFormatter(options);
>> }
>
>> And if the project doesn't have local options, this should use the
>> globally applicable ones.
>
>> But what you describe is more than formatting. I'm not sure there is
>> a programmatic way to invoke save actions.
>
>
>> Flavio Donzé wrote:
>>> Well I have my own formatter, not the "Eclipse [built-in]". Does it
>>> take the default provided by Eclipse or my selected "Active
>>> profile"? Probably not my profile, for example the toString method:
>>>
>>> // after my save
>>> public String toString() {
>>> if (eIsProxy()) {
>>> return super.toString();
>>> }
>>> // after emf generation
>>> public String toString() {
>>> if (eIsProxy())
>>> return super.toString();
>>>
>>> The braces are missing.
>>>
>>> Ahh, just found out that this is not a formatting but a "Code Style"
>>> option, which is also applied during the "save process".
>>>
>>> Well then, is it possible to apply this code style to the generated
>>> code?
>>>
>>> I disabled the "Code Style" option and saved the class again, I
>>> still get a different output, especially the javadoc comments.
>>>
>>> I still think the default Eclipse formatting is used instead of my
>>> active profile.
>>>
>>> Ed Merks wrote:
>>>
>>>> Flavio,
>>>
>>>> Comments below.
>>>
>>>> Flavio Donzé wrote:
>>>>> Hello
>>>>>
>>>>> In my workspace I have set the "Save Actions" which also formats
>>>>> the code the way I want.
>>>>>
>>>>> Now if I generate code from my genmodel, the output format is
>>>>> different as the rest of my classes. Another problem is the
>>>>> modification of those classes, as soon as I save my changes and
>>>>> want to commit to our svn repository I have a whole lot of changes.
>>>>>
>>>>> I started to modify the
>>>>> org.eclipse.emf.codegen.ecore/templates/model/Class.javajet, but
>>>>> this can't be the solution.
>>>>>
>>>>> Is it some how possible to tell the generator to use my code
>>>>> formatting or tell it to do a "save" after generation?
>>>>> The genmodel does have a "Code Formatting" option, but that
>>>>> doesn't solve the problem. It doesn't format the way I defined it
>>>>> in the preferences.
>>>> It invokes the regular Eclipse formatter which is based on your
>>>> preferences. But I think save actions can include more than just
>>>> formatting. Is it related to some type of cleanup action rather
>>>> than just formatting?
>>>>>
>>>>> I appreciate any help!
>>>>>
>>>
>>>
>
>
Re: Format generated Code [message #423270 is a reply to message #423269] Thu, 25 September 2008 16:04 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30825
Registered: July 2009
Senior Member
Flavio,

I should point out that we have to be able to do it to an in memory copy
before we do the actual save; we're very careful not to save anything if
the disk version and the in-memory version are the same...


Ed Merks wrote:
> Flavio,
>
> I don't know if there is a programmatic way to invoke that. If
> someone could determine how to do it programatically, that we could
> look at how to invoke that...
>
>
> Flavio Donzé wrote:
>> ok, thanks Ed!
>>
>> I found out that the "Save actions" are almost equal to the "Clean
>> up" preferences.
>> Do you think this would be possible to invoke? That would solve the
>> problem.
>>
>> Ed Merks wrote:
>>
>>> Flavio,
>>
>>> It should be using the project's options:
>>
>>> public static Object createCodeFormatter(Map<?, ?> options,
>>> String workspacePath)
>>> {
>>> if (options == null)
>>> {
>>> IProject project =
>>> ResourcesPlugin.getWorkspace().getRoot().getProject(new
>>> Path(workspacePath).segment(0));
>>> if (project != null)
>>> {
>>> IJavaProject javaProject = JavaCore.create(project);
>>> if (javaProject != null)
>>> {
>>> options = javaProject.getOptions(true);
>>> }
>>> }
>>> }
>>> return ToolFactory.createCodeFormatter(options);
>>> }
>>
>>> And if the project doesn't have local options, this should use the
>>> globally applicable ones.
>>
>>> But what you describe is more than formatting. I'm not sure there
>>> is a programmatic way to invoke save actions.
>>
>>
>>> Flavio Donzé wrote:
>>>> Well I have my own formatter, not the "Eclipse [built-in]". Does it
>>>> take the default provided by Eclipse or my selected "Active
>>>> profile"? Probably not my profile, for example the toString method:
>>>>
>>>> // after my save
>>>> public String toString() {
>>>> if (eIsProxy()) {
>>>> return super.toString();
>>>> }
>>>> // after emf generation
>>>> public String toString() {
>>>> if (eIsProxy())
>>>> return super.toString();
>>>>
>>>> The braces are missing.
>>>>
>>>> Ahh, just found out that this is not a formatting but a "Code
>>>> Style" option, which is also applied during the "save process".
>>>>
>>>> Well then, is it possible to apply this code style to the generated
>>>> code?
>>>>
>>>> I disabled the "Code Style" option and saved the class again, I
>>>> still get a different output, especially the javadoc comments.
>>>>
>>>> I still think the default Eclipse formatting is used instead of my
>>>> active profile.
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Flavio,
>>>>
>>>>> Comments below.
>>>>
>>>>> Flavio Donzé wrote:
>>>>>> Hello
>>>>>>
>>>>>> In my workspace I have set the "Save Actions" which also formats
>>>>>> the code the way I want.
>>>>>>
>>>>>> Now if I generate code from my genmodel, the output format is
>>>>>> different as the rest of my classes. Another problem is the
>>>>>> modification of those classes, as soon as I save my changes and
>>>>>> want to commit to our svn repository I have a whole lot of changes.
>>>>>>
>>>>>> I started to modify the
>>>>>> org.eclipse.emf.codegen.ecore/templates/model/Class.javajet, but
>>>>>> this can't be the solution.
>>>>>>
>>>>>> Is it some how possible to tell the generator to use my code
>>>>>> formatting or tell it to do a "save" after generation?
>>>>>> The genmodel does have a "Code Formatting" option, but that
>>>>>> doesn't solve the problem. It doesn't format the way I defined it
>>>>>> in the preferences.
>>>>> It invokes the regular Eclipse formatter which is based on your
>>>>> preferences. But I think save actions can include more than just
>>>>> formatting. Is it related to some type of cleanup action rather
>>>>> than just formatting?
>>>>>>
>>>>>> I appreciate any help!
>>>>>>
>>>>
>>>>
>>
>>
Previous Topic:Map values as children
Next Topic:open editor by marker in problems view
Goto Forum:
  


Current Time: Wed Jan 29 17:31:16 GMT 2020

Powered by FUDForum. Page generated in 0.02239 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top