Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » refactoring in xtext 2.0 - getting started
refactoring in xtext 2.0 - getting started [message #664147] Thu, 07 April 2011 15:30 Go to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Hi,
I am doing my first steps with the new refactoring API in Xtext 2.0.
Looking at the domainmodel example, this topic seems to be quite
complex. I noticed that renaming is the only aspect covered so far.
So what would be the starting point for a very limited refactoring, e.g.
creating a new element? This would be simple, as no external resources
are affected. I thought of a context menu entry in the outline to access
a wizard.


--
Best regards,
Sebastian Paul
Re: refactoring in xtext 2.0 - getting started [message #664299 is a reply to message #664147] Fri, 08 April 2011 10:16 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
The domainmodel is especially tricky because we infer a JvmModel that we
link against, so this has to be refatored, too.

For most cases, it should suffice to add the RefactorElementNameFragment
to the workflow, regenerate and synchronize the plugin.xml of the UI
plugin with the generated version.

see also
http://www.eclipse.org/forums/index.php?t=msg&goto=66344 4&S=d5e5539b9cd14582691e859920304950


Am 07.04.11 17:30, schrieb Sebastian Paul:
> Hi,
> I am doing my first steps with the new refactoring API in Xtext 2.0.
> Looking at the domainmodel example, this topic seems to be quite
> complex. I noticed that renaming is the only aspect covered so far.
> So what would be the starting point for a very limited refactoring, e.g.
> creating a new element? This would be simple, as no external resources
> are affected. I thought of a context menu entry in the outline to access
> a wizard.
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: refactoring in xtext 2.0 - getting started [message #664385 is a reply to message #664299] Fri, 08 April 2011 15:28 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Am 2011-04-08 12:16, schrieb Jan Koehnlein:
> For most cases, it should suffice to add the RefactorElementNameFragment
> to the workflow, regenerate and synchronize the plugin.xml of the UI
> plugin with the generated version.
Yes, this works fine. Now I can rename.
But where do I start when implementing a new refactoring, e.g. "create
new xxx"? Is this done like in Xtext 1.0 (see
http://koehnlein.blogspot.com/2010/06/semantic-model-access- in-xtext.html)?
Or is there another way which provides a real undo (apart from "Undo
typing")? I don't need an in-depth tutorial, just a few hints ;)

--
Best regards,
Sebastian Paul
Re: refactoring in xtext 2.0 - getting started [message #664567 is a reply to message #664385] Mon, 11 April 2011 08:01 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Depends on what your refactoring is going to do. The current
architecture is focusing on rename refactorings. Maybe you can map the
fuctionality to existing components. Here's a short description

IRenameStrategy: defines how to perform the actual refactoring
(applyDeclarationChange) and how to revert it (revertDeclarationChange)
both in terms of the semantic model (EMF model).

IDependentElementsCalculator: Defines which elements are changed
indirectly by the refactoring, such that references to them have to be
updated to

IReferenceUpdater: Loads referring models and updates references
therein. There is a generic default implementation for Xtext based
resources and for genric EMF resources. Refererences must be indexed
(contained as IReferenceDescription in the IResourceDescription).

If it doesn't work, you can still implement the ltk refactorings. You
might be able to reuse some code from the RenameElementProcessor and its
components. Code templates and quick fixes could also be worth a look at.

Am 08.04.11 17:28, schrieb Sebastian Paul:
> Am 2011-04-08 12:16, schrieb Jan Koehnlein:
>> For most cases, it should suffice to add the RefactorElementNameFragment
>> to the workflow, regenerate and synchronize the plugin.xml of the UI
>> plugin with the generated version.
> Yes, this works fine. Now I can rename.
> But where do I start when implementing a new refactoring, e.g. "create
> new xxx"? Is this done like in Xtext 1.0 (see
> http://koehnlein.blogspot.com/2010/06/semantic-model-access- in-xtext.html)?
> Or is there another way which provides a real undo (apart from "Undo
> typing")? I don't need an in-depth tutorial, just a few hints ;)
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: refactoring in xtext 2.0 - getting started [message #664571 is a reply to message #664567] Mon, 11 April 2011 08:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Jan, Sebastian

Non-trivial refactorings are really M2Ms, so it would be great if there
was some configurable facility with a UI vaguely analogous to the
templates that allowed new refactorings to be supplied by providing an
M2M (Xtend/ATL/Epsilon/QVT/Java/XSLT/...). May need distinct canExecute,
execute entry points for which some M2Ms may realize canExecute as an
LHS match, and execute as LHS match and RHS generate.

Regards

Ed Willink

On 11/04/2011 09:01, Jan Koehnlein wrote:
> Depends on what your refactoring is going to do. The current
> architecture is focusing on rename refactorings. Maybe you can map the
> fuctionality to existing components. Here's a short description
>
> IRenameStrategy: defines how to perform the actual refactoring
> (applyDeclarationChange) and how to revert it
> (revertDeclarationChange) both in terms of the semantic model (EMF
> model).
>
> IDependentElementsCalculator: Defines which elements are changed
> indirectly by the refactoring, such that references to them have to be
> updated to
>
> IReferenceUpdater: Loads referring models and updates references
> therein. There is a generic default implementation for Xtext based
> resources and for genric EMF resources. Refererences must be indexed
> (contained as IReferenceDescription in the IResourceDescription).
>
> If it doesn't work, you can still implement the ltk refactorings. You
> might be able to reuse some code from the RenameElementProcessor and
> its components. Code templates and quick fixes could also be worth a
> look at.
>
> Am 08.04.11 17:28, schrieb Sebastian Paul:
>> Am 2011-04-08 12:16, schrieb Jan Koehnlein:
>>> For most cases, it should suffice to add the
>>> RefactorElementNameFragment
>>> to the workflow, regenerate and synchronize the plugin.xml of the UI
>>> plugin with the generated version.
>> Yes, this works fine. Now I can rename.
>> But where do I start when implementing a new refactoring, e.g. "create
>> new xxx"? Is this done like in Xtext 1.0 (see
>> http://koehnlein.blogspot.com/2010/06/semantic-model-access- in-xtext.html)?
>>
>> Or is there another way which provides a real undo (apart from "Undo
>> typing")? I don't need an in-depth tutorial, just a few hints ;)
>>
>
>
Re: refactoring in xtext 2.0 - getting started [message #664577 is a reply to message #664147] Mon, 11 April 2011 09:27 Go to previous messageGo to next message
Sylvain EVEILLARD is currently offline Sylvain EVEILLARDFriend
Messages: 556
Registered: July 2009
Senior Member
Well maybe there could be a link with the incubating EMF Refactor there
Re: refactoring in xtext 2.0 - getting started [message #664630 is a reply to message #664567] Mon, 11 April 2011 13:12 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Am 2011-04-11 10:01, schrieb Jan Koehnlein:
> Depends on what your refactoring is going to do. The current architecture is focusing on rename refactorings.
For example, I want to provide a wizard for creating a new element. This
wizard could be accessed via the outline context menu. Such a change is
actually no refactoring, but I hoped that the new API in XText could
assist me with changing the *semantic* model.

> IRenameStrategy: defines how to perform the actual refactoring
> (applyDeclarationChange) and how to revert it (revertDeclarationChange)
> both in terms of the semantic model (EMF model).
This is a bit confusing, as applyDeclarationChange is only called by
RenamedElementTracker.renameAndTrack(...), which itself calls
revertDeclarationChange in the same method. I guess, this is just done
to get the map for URI changes. It turns out that
IRenameStrategy.createDeclarationUpdates applies the actual changes.
The DefaultRenameStrategy implements this method on the text level
(TextEdit).

> If it doesn't work, you can still implement the ltk refactorings.
I have the feeling that current refactoring approach in Xtext is
focussed around *text* changes, not changes to semantic model. We
already had a thread about this, where I complained that the undo
history always contains "Undo typing" when using the approach from
http://koehnlein.blogspot.com/2010/06/semantic-model-access- in-xtext.html .
I got the advise that the new API may help me, but I'm stuck with the
text-centric stuff.
I'd prefer implementing an IUnitOfWork, and XText does all the ltk
refactoring behind the scenes. Is there already something which goes
that direction?
At the end, all I currently need is a change of the semantic model with
a custom text in the undo history ;)


--
Best regards,
Sebastian Paul
Re: refactoring in xtext 2.0 - getting started [message #664661 is a reply to message #664630] Mon, 11 April 2011 14:35 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

semantic modifications are already covered by IXtextDocument#modify where you pass IUnitOfWork.

Alex
Re: refactoring in xtext 2.0 - getting started [message #664665 is a reply to message #664661] Mon, 11 April 2011 14:41 Go to previous messageGo to next message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Thanks for the hint. How can I change the text in the undo history to
something different from "undo typing"?

Am 2011-04-11 16:35, schrieb Alexander Nittka:
> Hi,
>
> semantic modifications are already covered by IXtextDocument#modify
> where you pass IUnitOfWork.
>
> Alex


--
Best regards,
Sebastian Paul
Re: refactoring in xtext 2.0 - getting started [message #664855 is a reply to message #664630] Tue, 12 April 2011 09:19 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Am 11.04.11 15:12, schrieb Sebastian Paul:
>> IRenameStrategy: defines how to perform the actual refactoring
>> (applyDeclarationChange) and how to revert it (revertDeclarationChange)
>> both in terms of the semantic model (EMF model).
> This is a bit confusing, as applyDeclarationChange is only called by
> RenamedElementTracker.renameAndTrack(...), which itself calls
> revertDeclarationChange in the same method. I guess, this is just done
> to get the map for URI changes. It turns out that
> IRenameStrategy.createDeclarationUpdates applies the actual changes.
> The DefaultRenameStrategy implements this method on the text level
> (TextEdit).

You are right, the declaration change that is applied is done in the
createDeclarationChange method.

We have recently changed createDeclarationUpdates to also take the
ResourceSet, so you're free to apply any change you want. Have a look at
EmfResourceRenameStrategy for an example. The IRefactoringUpdateAcceptor
accepts (and aggregates) text edits or alternatively can be fed with an
ltk Change. You can customize the text as well as the behavior of that
change as you like. Currently, we only feed text changes.

>> If it doesn't work, you can still implement the ltk refactorings.
> I have the feeling that current refactoring approach in Xtext is
> focussed around *text* changes, not changes to semantic model. We
> already had a thread about this, where I complained that the undo
> history always contains "Undo typing" when using the approach from
> http://koehnlein.blogspot.com/2010/06/semantic-model-access- in-xtext.html .
> I got the advise that the new API may help me, but I'm stuck with the
> text-centric stuff.
> I'd prefer implementing an IUnitOfWork, and XText does all the ltk
> refactoring behind the scenes. Is there already something which goes
> that direction?
> At the end, all I currently need is a change of the semantic model with
> a custom text in the undo history ;)

Xtext is text centric, so we try to manage the the issues in a text
centric way first.

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: refactoring in xtext 2.0 - getting started [message #664921 is a reply to message #664855] Tue, 12 April 2011 13:49 Go to previous message
Sebastian Paul is currently offline Sebastian PaulFriend
Messages: 106
Registered: July 2009
Senior Member
Am 2011-04-12 11:19, schrieb Jan Koehnlein:
> We have recently changed createDeclarationUpdates to also take the
> ResourceSet, so you're free to apply any change you want. Have a look at
> EmfResourceRenameStrategy for an example. The IRefactoringUpdateAcceptor
> accepts (and aggregates) text edits or alternatively can be fed with an
> ltk Change. You can customize the text as well as the behavior of that
> change as you like. Currently, we only feed text changes.
That looks promising. I got the latest snapshots and check this.

> Xtext is text centric, so we try to manage the the issues in a text
> centric way first.
Our current project requires lots of GUI assistance (such as wizards).
This is needed, as the old software was completely UI based. To ease the
initial start and gain acceptance, we want to mix the text-centric and
GUI approach where possible.

--
Best regards,
Sebastian Paul
Previous Topic:How to load a model conformant to the generated metamodel of an XText DSL?
Next Topic:How should I extend WorkspaceProjectsState?
Goto Forum:
  


Current Time: Thu Apr 25 04:32:54 GMT 2024

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

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

Back to the top