Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Tracking rename of elements in my DSL(... even without using the rename refactoring ...)
Tracking rename of elements in my DSL [message #1711659] Mon, 19 October 2015 07:12 Go to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
Hey,

I'm looking for a way to somehow hook up into the editor, my EObjects or anything else to allow me to detect whenever an element in my DSL is renamed, both using the rename refactoring, /and also/ when simply typing a new name into the editor manually.

How would I go for that? Reason behind is that for renames (of elements and their attributes) in our model I'd like to offer the user special operations on saving the related file...

Cheers, Thanks,
Markus
Re: Tracking rename of elements in my DSL [message #1711673 is a reply to message #1711659] Mon, 19 October 2015 08:16 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
Hi,

Maybe if you bind your own RenameStrategy implementation that could extend DefaultJvmModelRenameStrategy,
you could override createDeclarationUpdates or applyDeclarationChange ?
Re: Tracking rename of elements in my DSL [message #1711674 is a reply to message #1711673] Mon, 19 October 2015 08:25 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
Thanks for the quick reply - will try to do so Smile
Re: Tracking rename of elements in my DSL [message #1711677 is a reply to message #1711674] Mon, 19 October 2015 08:32 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
hm, does not seem to do what i want.

applyDeclarationChange is called when i use the rename refactoring, but not otherwise. Also (even worse) when undoing the rename (CTRL+Z), the method is not called, so I cannot track state using this method, not even if I would force developers to rename using only this method Neutral

Thanks for the hint anyway!
Re: Tracking rename of elements in my DSL [message #1711691 is a reply to message #1711677] Mon, 19 October 2015 10:02 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
"but not otherwise"

What do you mean ?

"Also (even worse) when undoing the rename (CTRL+Z)"

Maybe you can look at the revertDeclarationChange method.

Re: Tracking rename of elements in my DSL [message #1711846 is a reply to message #1711691] Tue, 20 October 2015 06:34 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
As stated in the first post, I'd also like to detect a rename if the user simply types a new name in the editor, without using the rename refactoring - yes, people do this - even more frequently than using the rename refactoring... Thanks for the revert pointer though.

Currently I'm thinking about something like hooking up to every semantic object that is present in an editor for my DSL somehow - would this be possible?
Re: Tracking rename of elements in my DSL [message #1711853 is a reply to message #1711846] Tue, 20 October 2015 07:30 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
For the records, I played with the IXtextEditorCallback to remember semantic object names in afterCreatePartControl and comparing them in afterSave or onValidateEditorInputState to no avail. The semantic object instances are not stable, thus an instance comparison fails Sad
Re: Tracking rename of elements in my DSL [message #1711855 is a reply to message #1711846] Tue, 20 October 2015 07:37 Go to previous messageGo to next message
Stefan Oehme is currently offline Stefan OehmeFriend
Messages: 159
Registered: April 2010
Location: Kiel
Senior Member

Hooking into the AST won't help, as it is recreated when the user types. I think telling the user to use rename refactoring to benefit from your advanced tooling is the best idea.

If you want to support simple typing in the editor, then you will have to diff the persistent state against the dirty state. But that still leaves you with tough decisions whether something was a rename or a delete+add. You'd probably have to ask the user.
Re: Tracking rename of elements in my DSL [message #1711858 is a reply to message #1711846] Tue, 20 October 2015 07:49 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
As far as I know refactoring will set a new name to the target element and trigger change notification but
the problem is that the model is regenerated when you save after a modification so I guess you would have to reattach a change notification listener every time. Not efficient !

So maybe you would have to make some kind of model diff comparison between the old and the new model and see if there was a change of the name attribute of an element in the diff ?

I hope somebody competant can answer you because I am also very interested into this.
Re: Tracking rename of elements in my DSL [message #1711862 is a reply to message #1711858] Tue, 20 October 2015 07:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi there is no hook default hook for that. thus you would have to build it yourself

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Tracking rename of elements in my DSL [message #1711864 is a reply to message #1711862] Tue, 20 October 2015 07:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
On 2015-10-20 07:55:41 +0000, Christian Dietrich said:

> hi there is no hook default hook for that. thus you would have to build
> it yourself

P.S: if the name signture of a file changes the builder will be aware
of that. but this might be way to late for your usecase. can you be a
bit more specific on what you want to achieve?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Tracking rename of elements in my DSL [message #1711868 is a reply to message #1711858] Tue, 20 October 2015 08:13 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
Just thinking EMF compare could be the way to go ?
In the matching engine you could compare EAttributes named "name" and check if their owner are the same (maybe by comparing a unique ID ?).
Re: Tracking rename of elements in my DSL [message #1711869 is a reply to message #1711868] Tue, 20 October 2015 08:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
another possibility would be to simply track the old and new names. the main question would be which corner cases should work as well? renaming via text editor. renaming by updating from version control etc

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Tracking rename of elements in my DSL [message #1711886 is a reply to message #1711869] Tue, 20 October 2015 09:10 Go to previous messageGo to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
OK, maybe a little more about the actual use case. We're modeling our database with a DSL, something like this:

persistent ActivityProtocol {
	data-category Protocol;

	property label "Activity protocol";
	property no_unique_constraint;

	/**
	 * Part of the unique identifier.
	 */
	oid id : ARTIFICIAL_PK;

	/**
	 * Date and time of the activity.
	 */
	attribute time : ARCHIVE_DATETIME {
		property label "Timestamp";
	}
	...
}


We also have a very complex migration framework that allows to automatically detect changes and migrate old databases to the current state after changing a persistent. This is all in place already. This migration framework works based on diffing the source and target schemes and determining steps to perform for migration. The migration of structure is done automatically, but the migration of actual /data/ needs to be done by the developer. So when renaming an attribute (or a persistent), the developer needs to know that he/she needs to write an update statement like "update ActivityProtocol set newTime=time" if he'd rename the "time" attribute in the example above.

If i would be able to detect that a developer changes the name of an attribute I could suggest to automatically generate the according update statement - it does not work always, but is generally generateable quite good.

Thus I'd like to /somehow/ get a chance to detect (on saving a file) whether an attribute or persistent in that file (or editor) has been renamed to suggest automatic generation of those migration statement(s).

Hope that clarifies the actual use case Smile Thanks for all the responses!
Re: Tracking rename of elements in my DSL [message #1711938 is a reply to message #1711886] Tue, 20 October 2015 11:11 Go to previous messageGo to next message
aurel pestell is currently offline aurel pestellFriend
Messages: 90
Registered: October 2013
Location: Sweden
Member
So it's only renaming solely through the editor and by no other mean ?
Re: Tracking rename of elements in my DSL [message #1711943 is a reply to message #1711938] Tue, 20 October 2015 11:43 Go to previous message
Markus Duft is currently offline Markus DuftFriend
Messages: 35
Registered: March 2015
Member
Yes, I will not try to figure out what happened in the GIT history, nor will I want to support editing in VIM and checking at commit time or something like that - sounds like too much overhead (although I would accept such a solution if easier than hooking into the xtext framework Wink). I'm assuming (and I'm 99% sure that assumption will hold) that all edits in those files happen in the xtext editor. And yes, only renaming is of interest (for now) as developers tend to forget these update statements Smile
Previous Topic:create a new IResourceDescriptions
Next Topic:generating xtext artifacts error
Goto Forum:
  


Current Time: Wed Apr 24 18:17:41 GMT 2024

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

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

Back to the top