Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to execute two different types of resolution in same unit of work?
How to execute two different types of resolution in same unit of work? [message #959108] Fri, 26 October 2012 13:06 Go to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi,

I'm trying to create a quickfix that does two different types of changes in same unit of work. One is based in semantic and the other based in the offset.

I follow the DefaultQuickfixProvider's createLinkingIssueResolutions method, but using a xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() instead.
I tried something like the code below. I use the ISemanticModification to add the offset change :
public void createQualifiedNameIssueResolutions(final Issue issue,
			final IssueResolutionAcceptor issueResolutionAcceptor) {
final IModificationContext modificationContext = getModificationContextFactory()
				.createModificationContext(issue);
final IXtextDocument xtextDocument = modificationContext
				.getXtextDocument();
	if (xtextDocument == null)
			return;
	xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() {
	@Override
	public void process(XtextResource state) throws Exception {
		EObject target = state.getEObject(issue.getUriToProblem()
						.fragment());
		EReference reference = getUnresolvedEReference(issue, target);
		if (reference == null)
					return;
		String issueString = xtextDocument.get(issue.getOffset(),
						issue.getLength());
		String simpleName = getQualifiedNameConverter()
						.toQualifiedName(issueString).getLastSegment()
						.toString();
		createImportResolution(target, issueString, issue,
						issueResolutionAcceptor, issueString, simpleName);
			}
		});
	}


protected void createImportResolution(final EObject target,
			final String issueString, final Issue issue,
			final IssueResolutionAcceptor issueResolutionAcceptor,
			final String importText, final String simpleName) {
issueResolutionAcceptor.accept(issue, label, description,
				null, new ISemanticModification() {

public void apply(EObject element,IModificationContext context) throws Exception {
IXtextDocument xtextDocument = context.getXtextDocument();
xtextDocument.replace(issue.getOffset(),issue.getLength(), simpleName);
ComponentTemplateLibrary library = EcoreUtil2.getContainerOfType(
element, ComponentTemplateLibrary.class);
Import importobj = ComponentTemplateLibraryDslFactory.eINSTANCE.createImport();

IJvmTypeProvider typeProvider = typeProviderFactory.findOrCreateTypeProvider(library.eResource().getResourceSet());
JvmType jvmType = typeProvider.findTypeByName(importText);			importobj.setImportedType(jvmType);						library.getImports().add(importobj);
						}
					}
				});



With the two change I'm getting the error below. When I comment one of the two changes, the execution for both is normal.
!STACK 0
org.eclipse.emf.common.util.WrappedException: java.lang.RuntimeException: org.eclipse.text.edits.MalformedTreeException: End position lies outside document range
	at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:82)
	at org.eclipse.xtext.ui.editor.quickfix.QuickAssistCompletionProposal.apply(QuickAssistCompletionProposal.java:32)
	at org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.apply(AnnotationWithQuickFixesHover.java:525)
	at org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.access$2(AnnotationWithQuickFixesHover.java:502)
	at org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl$5.widgetSelected(AnnotationWithQuickFixesHover.java:496)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4134)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1458)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1481)
	at org.eclipse.swt.widgets.Widget.sendSelectionEvent(Widget.java:1531)
	at org.eclipse.swt.widgets.Link.textView_clickOnLink_atIndex(Link.java:117)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5807)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:221)
	at org.eclipse.swt.widgets.Widget.mouseDownSuper(Widget.java:1093)
	at org.eclipse.swt.widgets.Widget.mouseDown(Widget.java:1085)
	at org.eclipse.swt.widgets.Control.mouseDown(Control.java:2538)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5493)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:221)
	at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2102)
	at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2299)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5557)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
	at org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5002)
	at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5151)
	at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
	at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3616)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.RuntimeException: org.eclipse.text.edits.MalformedTreeException: End position lies outside document range
	at org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:46)
	at org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:1)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.modify(AbstractReadWriteAcces.java:49)
	at org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:181)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:90)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.modify(XtextDocument.java:83)
	at org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper.apply(SemanticModificationWrapper.java:31)
	at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:80)
	... 51 more
Caused by: org.eclipse.text.edits.MalformedTreeException: End position lies outside document range
	at org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(TextEditProcessor.java:178)
	at org.eclipse.text.edits.TextEdit.dispatchCheckIntegrity(TextEdit.java:743)
	at org.eclipse.text.edits.TextEditProcessor.performEdits(TextEditProcessor.java:151)
	at org.eclipse.text.edits.TextEdit.apply(TextEdit.java:711)
	at org.eclipse.text.edits.TextEdit.apply(TextEdit.java:735)
	at org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:42)
	... 58 more


Could someone point me how could I accomplish this?

thanks

Cristiano
Re: How to execute two different types of resolution in same unit of work? [message #960505 is a reply to message #959108] Sat, 27 October 2012 14:47 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Cristiano,

that's not possible. You have to perform the complete changes in one and
the same way, e.g. everything based on the text or everything based on
the semantic model. Otherwise the produced text edits will not be in sync.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 26.10.12 15:06, schrieb Cristiano Gaviao:
> Hi,
>
> I'm trying to create a quickfix that does two different types of changes
> in same unit of work. One is based in semantic and the other based in
> the offset.
>
> I follow the DefaultQuickfixProvider's createLinkingIssueResolutions
> method, but using a xtextDocument.modify(new
> IUnitOfWork.Void<XtextResource>() instead. I tried something like the
> code below. I use the ISemanticModification to add the offset change :
>
> public void createQualifiedNameIssueResolutions(final Issue issue,
> final IssueResolutionAcceptor issueResolutionAcceptor) {
> final IModificationContext modificationContext =
> getModificationContextFactory()
> .createModificationContext(issue);
> final IXtextDocument xtextDocument = modificationContext
> .getXtextDocument();
> if (xtextDocument == null)
> return;
> xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() {
> @Override
> public void process(XtextResource state) throws Exception {
> EObject target = state.getEObject(issue.getUriToProblem()
> .fragment());
> EReference reference = getUnresolvedEReference(issue, target);
> if (reference == null)
> return;
> String issueString = xtextDocument.get(issue.getOffset(),
> issue.getLength());
> String simpleName = getQualifiedNameConverter()
> .toQualifiedName(issueString).getLastSegment()
> .toString();
> createImportResolution(target, issueString, issue,
> issueResolutionAcceptor, issueString, simpleName);
> }
> });
> }
>
>
>
> protected void createImportResolution(final EObject target,
> final String issueString, final Issue issue,
> final IssueResolutionAcceptor issueResolutionAcceptor,
> final String importText, final String simpleName) {
> issueResolutionAcceptor.accept(issue, label, description,
> null, new ISemanticModification() {
>
> public void apply(EObject element,IModificationContext context) throws
> Exception {
> IXtextDocument xtextDocument = context.getXtextDocument();
> xtextDocument.replace(issue.getOffset(),issue.getLength(), simpleName);
> ComponentTemplateLibrary library = EcoreUtil2.getContainerOfType(
> element, ComponentTemplateLibrary.class);
> Import importobj =
> ComponentTemplateLibraryDslFactory.eINSTANCE.createImport();
>
> IJvmTypeProvider typeProvider =
> typeProviderFactory.findOrCreateTypeProvider(library.eResource().getResourceSet());
>
> JvmType jvmType = typeProvider.findTypeByName(importText);
> importobj.setImportedType(jvmType);
> library.getImports().add(importobj);
> }
> }
> });
>
>
>
> With the two change I'm getting the error below. When I comment one of
> the two changes, the execution for both is normal.
> !STACK 0
> org.eclipse.emf.common.util.WrappedException:
> java.lang.RuntimeException:
> org.eclipse.text.edits.MalformedTreeException: End position lies outside
> document range
> at
> org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:82)
>
> at
> org.eclipse.xtext.ui.editor.quickfix.QuickAssistCompletionProposal.apply(QuickAssistCompletionProposal.java:32)
>
> at
> org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.apply(AnnotationWithQuickFixesHover.java:525)
>
> at
> org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl.access$2(AnnotationWithQuickFixesHover.java:502)
>
> at
> org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover$AnnotationInformationControl$5.widgetSelected(AnnotationWithQuickFixesHover.java:496)
>
> at
> org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
> at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4134)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1458)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1481)
> at org.eclipse.swt.widgets.Widget.sendSelectionEvent(Widget.java:1531)
> at
> org.eclipse.swt.widgets.Link.textView_clickOnLink_atIndex(Link.java:117)
> at org.eclipse.swt.widgets.Display.windowProc(Display.java:5807)
> at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
> at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:221)
> at org.eclipse.swt.widgets.Widget.mouseDownSuper(Widget.java:1093)
> at org.eclipse.swt.widgets.Widget.mouseDown(Widget.java:1085)
> at org.eclipse.swt.widgets.Control.mouseDown(Control.java:2538)
> at org.eclipse.swt.widgets.Display.windowProc(Display.java:5493)
> at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
> at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:221)
> at org.eclipse.swt.widgets.Widget.windowSendEvent(Widget.java:2102)
> at org.eclipse.swt.widgets.Shell.windowSendEvent(Shell.java:2299)
> at org.eclipse.swt.widgets.Display.windowProc(Display.java:5557)
> at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
> at
> org.eclipse.swt.widgets.Display.applicationSendEvent(Display.java:5002)
> at org.eclipse.swt.widgets.Display.applicationProc(Display.java:5151)
> at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
> at
> org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(NSApplication.java:128)
>
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3616)
> at
> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
>
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
>
> at
> org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
>
> at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
> at
> org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
> at
> org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
> Caused by: java.lang.RuntimeException:
> org.eclipse.text.edits.MalformedTreeException: End position lies outside
> document range
> at
> org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:46)
>
> at
> org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:1)
>
> at
> org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.modify(AbstractReadWriteAcces.java:49)
>
> at
> org.eclipse.xtext.ui.editor.model.XtextDocument$XtextDocumentLocker.modify(XtextDocument.java:181)
>
> at
> org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:90)
>
> at
> org.eclipse.xtext.ui.editor.model.XtextDocument.modify(XtextDocument.java:83)
>
> at
> org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper.apply(SemanticModificationWrapper.java:31)
>
> at
> org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:80)
>
> ... 51 more
> Caused by: org.eclipse.text.edits.MalformedTreeException: End position
> lies outside document range
> at
> org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(TextEditProcessor.java:178)
>
> at
> org.eclipse.text.edits.TextEdit.dispatchCheckIntegrity(TextEdit.java:743)
> at
> org.eclipse.text.edits.TextEditProcessor.performEdits(TextEditProcessor.java:151)
>
> at org.eclipse.text.edits.TextEdit.apply(TextEdit.java:711)
> at org.eclipse.text.edits.TextEdit.apply(TextEdit.java:735)
> at
> org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:42)
>
> ... 58 more
>
>
> Could someone point me how could I accomplish this?
>
> thanks
>
> Cristiano
Re: How to execute two different types of resolution in same unit of work? [message #960638 is a reply to message #960505] Sat, 27 October 2012 17:15 Go to previous message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hey Sebastian,

I would like to change the qualified name by a simple name and same time insert an import statement. Could you suggest me a way to do that using one of the two approaches?

thanks a lot,

Cristiano
Previous Topic:testing autocompletion (and other UI stuff)
Next Topic:Packages should be imported by their namespace URI.
Goto Forum:
  


Current Time: Mon Sep 28 21:21:19 GMT 2020

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

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

Back to the top