Modifying a file that's not open in an editor? [message #859596] |
Fri, 27 April 2012 14:11  |
Eclipse User |
|
|
|
Hi,
I'm implementing an Xtext quickfix that needs to modify more than one file.
For the file showing the validation issue I'm using an ISemanticModification,
whereas for any secondary files more indirections seem to be necessary.
I have a solution that works IFF the other file is currently open in an Xtext editor.
However, if the file is not open this call
XtextDocumentUtil.get(fileResource)
returns null. Can anyone recommend how to proceed?
- is IXtextDocument the appropriate object to operate on or can I apply my modifications (a la ISemanticModification) using a different API?
- can I obtain an IXtextDocument even if the file is not open in an editor?
- should I force load the file into an Xtext editor (behind the scenes?)?
thanks,
Stephan
|
|
|
|
|
|
|
Re: Modifying a file that's not open in an editor? [message #865444 is a reply to message #865169] |
Mon, 30 April 2012 07:55   |
Eclipse User |
|
|
|
Hi Stephan,
please file a ticket. IModificationContext#getXtextDocument could work
with the plain IXtextDocument and use the IDocumentProvider to save the
changes.
You may want to customize the
org.eclipse.xtext.ui.editor.model.edit.IssueModificationContext.Factory
to achieve that for your language.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 30.04.12 11:13, schrieb Stephan Herrmann:
> Thanks for suggestions.
>
> Christian Dietrich wrote on Fri, 27 April 2012 21:48
>> Hi,
>>
>> what about letting Xtext opening the editor for you by calling
>> org.eclipse.xtext.ui.editor.model.edit.IModificationContext.getXtextDocument(URI)
>>
>>
>> ~Christian
>
>
> This seems to be the one closest to what I want to do, great.
>
> One caveat: it seems the URI must be a platform URI, classpath: doesn't
> work (might be worth documenting in API doc :)
>
> Actually opening editors for secondary files is tolerable in my case
> since normally only one additional file is affected. However, if a quick
> fix should affect more files opening all these might become an issue.
>
> Especially when I start implementing refactorings I don't want to open
> all affected files in editors.
> Is there any other API for rewriting that does not depend on an editor?
> Anything similar to JDT's ASTRewrite? (I wouldn't want to go back to
> serializing entire files because the layout of the source code must be
> preserved as much as possible.)
>
> thanks,
> Stephan
|
|
|
|
|
|
|
|
Re: Modifying a file that's not open in an editor? [message #866031 is a reply to message #865931] |
Mon, 30 April 2012 13:54  |
Eclipse User |
|
|
|
Christian Dietrich wrote on Mon, 30 April 2012 18:52it is hard to give advice since i did not leverage the rename refactoring myself. but it is there. you can use it out of the box. no quickfix, no menu action.
In my case renaming some elements is only part of a compound operation. So unless the refactoring can be easily composed into such a compound operation (how?) using it out of the box doesn't help.
Quote: for everything else you have to dig into the code yourself i fear. use the package org.eclipse.xtext.ui.refactoring and its subpackages in the org.eclipse.xtext.ui plugin as starting point
Hm, that's quite a lot of code to dig through just to get an answer to this question:
- when performing changes to multiple files as part of a quickfix operation: how do I ensure that serializing the final result doesn't blow up because of the use of an outdated scope?
Maybe s.o. else has a hint?
Stephan
|
|
|
Powered by
FUDForum. Page generated in 0.30809 seconds