MyDslDocumentProvider failed to save [message #1764684] |
Thu, 01 June 2017 11:37 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
I have a EMF metamodel (named DSL) (file extension mydsl)
I create an Xtext project from this metamodel. (file extension my)
When I create a myDsl model, the model can be opened using the textual editor or the EMF editor.
However it is saved a TEXT and not XMI.
For me, It must be an xmi file and saved as XMI
To do that, I add this code in my MyDslUiModule
class MyDslUiModule extends AbstractMyDslUiModule {
def Class<? extends XtextDocumentProvider> bindXtextDocumentProvider() {
MyDslDocumentProvider
}
override Class<? extends IResourceForEditorInputFactory> bindIResourceForEditorInputFactory() {
return MyDslResourceForEditorInputFactory
}
}
and I add the following classes
public class MyDslDocumentProvider extends XtextDocumentProvider {
static {
MyDslStandaloneSetup.doSetup();
}
@Override
protected void setDocumentContent(IDocument document, InputStream contentStream, String encoding)
throws CoreException {
ResourceSet resourceSet = createResourceSet();
Resource xmiResource = resourceSet.createResource(URI.createURI("temp.xmi"));
Resource xtextResource = resourceSet.createResource(URI.createURI("temp.mydsl"));
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
xmiResource.load(contentStream, Collections.emptyMap());
xtextResource.getContents().addAll(xmiResource.getContents());
xtextResource.save(os, Collections.EMPTY_MAP);
} catch (IOException e) {
throw new CoreException(
new Status(IStatus.ERROR, "org.xtext.example.mydsl.ui", "Failed to save", e));
} finally {
try {
os.close();
contentStream.close();
} catch (IOException e) {
throw new CoreException(
new Status(IStatus.ERROR, "org.xtext.example.mydsl.ui", "Failed to load", e));
}
}
document.set(new String(os.toByteArray()));
}
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
throws CoreException {
try {
ResourceSet resourceSet = createResourceSet();
XtextResource xtextResource = (XtextResource) resourceSet.createResource(URI.createURI("temp.mydsl"));
InputStream is = new ByteArrayInputStream(document.get().getBytes());
xtextResource.load(is, Collections.EMPTY_MAP);
is.close();
URI uri = URI.createPlatformResourceURI(
((org.eclipse.ui.part.FileEditorInput) element).getFile().getFullPath().toString(), true);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
Resource xmiResource = resourceSet.getResource(uri, true);
((XMLResource) xmiResource).getDefaultSaveOptions().put(XMLResource.OPTION_URI_HANDLER,
new URIHandlerImpl.PlatformSchemeAware());
xmiResource.getContents().clear();
xmiResource.getContents().addAll(xtextResource.getContents());
EcoreUtil.resolveAll(xmiResource);
xmiResource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
throw new CoreException(
new Status(IStatus.ERROR, "org.xtext.example.mydsl.ui", "Failed to save", e));
}
}
private ResourceSet createResourceSet() {
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(MyDslPackage.eNS_URI, MyDslPackage.eINSTANCE);
return resourceSet;
}
}
and
public class MyDslResourceForEditorInputFactory extends JavaClassPathResourceForIEditorInputFactory {
@Inject
private IStorage2UriMapper storageToUriMapper;
@Inject
private Provider<XtextResource> provider;
@Override
protected Resource createResourceFor(IStorage storage) {
ResourceSet resourceSet = getResourceSet(storage);
URI uri = URI.createPlatformResourceURI(storage.getFullPath().toString(), true);
configureResourceSet(resourceSet, uri);
XtextResource resource = (XtextResource) resourceSet.getResource(uri, false);
// Modified to interpret a null resource and
// so create an XtextResource for an ecore file
if (resource == null) {
resource = (XtextResource) new XtextResourceFactory(provider).createResource(uri);
resourceSet.getResources().add(resource);
}
resource.setValidationDisabled(false);
return resource;
}
@Override
protected Resource createResourceFor(IJarEntryResource storage) {
ResourceSet resourceSet = getResourceSet(storage);
URI uri = storageToUriMapper.getUri(storage);
configureResourceSet(resourceSet, uri);
XtextResource resource = (XtextResource) resourceSet.getResource(uri, false);
// Modified to interpret a null resource and
// so create an XtextResource for an ecore file
if (resource == null) {
resource = (XtextResource) new XtextResourceFactory(provider).createResource(uri);
resourceSet.getResources().add(resource);
}
resource.setValidationDisabled(true);
return resource;
}
}
From now on, hen I try to create mydsl model, I obtain this error and the model is empty
!ENTRY org.eclipse.ui 4 0 2017-06-01 13:31:39.326
!MESSAGE FileDocumentProvider.createElementInfo
!STACK 1
org.eclipse.core.runtime.CoreException: Failed to save
at org.eclipse.cmf.occi.core.xtext.ui.OCCIDocumentProvider.setDocumentContent(OCCIDocumentProvider.java:48)
at org.eclipse.ui.editors.text.FileDocumentProvider.setDocumentContent(FileDocumentProvider.java:425)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.setDocumentContent(XtextDocumentProvider.java:183)
at org.eclipse.ui.editors.text.StorageDocumentProvider.createDocument(StorageDocumentProvider.java:227)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.createDocument(XtextDocumentProvider.java:141)
at org.eclipse.ui.editors.text.FileDocumentProvider.createElementInfo(FileDocumentProvider.java:721)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.createElementInfo(XtextDocumentProvider.java:262)
at org.eclipse.ui.texteditor.AbstractDocumentProvider.connect(AbstractDocumentProvider.java:392)
at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(AbstractTextEditor.java:4178)
at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(StatusTextEditor.java:229)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetInput(AbstractDecoratedTextEditor.java:1466)
at org.eclipse.ui.editors.text.TextEditor.doSetInput(TextEditor.java:150)
at org.eclipse.xtext.ui.editor.XtextEditor.doSetInput(XtextEditor.java:247)
at org.eclipse.ui.texteditor.AbstractTextEditor$5.run(AbstractTextEditor.java:3154)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:437)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:353)
at org.eclipse.ui.internal.WorkbenchWindow$14.run(WorkbenchWindow.java:2184)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2180)
at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3172)
at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3197)
at org.eclipse.xtext.ui.editor.XtextEditor.init(XtextEditor.java:288)
at org.eclipse.ui.internal.EditorReference.initialize(EditorReference.java:362)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:318)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:966)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:931)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:151)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:375)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:294)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:975)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:651)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:757)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:728)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:722)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:706)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1324)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:72)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4814)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:94)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:173)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:617)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:581)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:770)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1214)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3261)
at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3176)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3158)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3153)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3117)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3107)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:563)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:518)
at org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard.performFinish(BasicNewFileResourceWizard.java:103)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:790)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:423)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:618)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1313)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3706)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)
at org.eclipse.jface.window.Window.open(Window.java:794)
at org.eclipse.ui.internal.navigator.wizards.WizardShortcutAction.run(WizardShortcutAction.java:99)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1313)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3706)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
Caused by: org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Fin prématurée du fichier.
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:195)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
at org.eclipse.cmf.occi.core.xtext.ui.OCCIDocumentProvider.setDocumentContent(OCCIDocumentProvider.java:44)
... 128 more
Caused by: org.xml.sax.SAXParseExceptionpublicId: temp.xmi; systemId: file:///Applications/Eclipse%20copie.app/Contents/MacOS/temp.xmi; lineNumber: 1; columnNumber: 1; Fin prématurée du fichier.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1014)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
... 131 more
!SUBENTRY 1 org.occiware.clouddesigner.occi.xtext.ui 4 0 2017-06-01 13:31:39.328
!MESSAGE Failed to save
!STACK 0
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Fin prématurée du fichier.
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:195)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1518)
at org.eclipse.cmf.occi.core.xtext.ui.OCCIDocumentProvider.setDocumentContent(OCCIDocumentProvider.java:44)
at org.eclipse.ui.editors.text.FileDocumentProvider.setDocumentContent(FileDocumentProvider.java:425)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.setDocumentContent(XtextDocumentProvider.java:183)
at org.eclipse.ui.editors.text.StorageDocumentProvider.createDocument(StorageDocumentProvider.java:227)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.createDocument(XtextDocumentProvider.java:141)
at org.eclipse.ui.editors.text.FileDocumentProvider.createElementInfo(FileDocumentProvider.java:721)
at org.eclipse.xtext.ui.editor.model.XtextDocumentProvider.createElementInfo(XtextDocumentProvider.java:262)
at org.eclipse.ui.texteditor.AbstractDocumentProvider.connect(AbstractDocumentProvider.java:392)
at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(AbstractTextEditor.java:4178)
at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(StatusTextEditor.java:229)
at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetInput(AbstractDecoratedTextEditor.java:1466)
at org.eclipse.ui.editors.text.TextEditor.doSetInput(TextEditor.java:150)
at org.eclipse.xtext.ui.editor.XtextEditor.doSetInput(XtextEditor.java:247)
at org.eclipse.ui.texteditor.AbstractTextEditor$5.run(AbstractTextEditor.java:3154)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:437)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:353)
at org.eclipse.ui.internal.WorkbenchWindow$14.run(WorkbenchWindow.java:2184)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2180)
at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3172)
at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3197)
at org.eclipse.xtext.ui.editor.XtextEditor.init(XtextEditor.java:288)
at org.eclipse.ui.internal.EditorReference.initialize(EditorReference.java:362)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:318)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:966)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:931)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:151)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:375)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:294)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:975)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:651)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:757)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:728)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:722)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:706)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1324)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java:72)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4814)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:94)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:173)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:617)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:581)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:770)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1214)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3261)
at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3176)
at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3158)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3153)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3117)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3107)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:563)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:518)
at org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard.performFinish(BasicNewFileResourceWizard.java:103)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:790)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:423)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:618)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1313)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3706)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:818)
at org.eclipse.jface.window.Window.open(Window.java:794)
at org.eclipse.ui.internal.navigator.wizards.WizardShortcutAction.run(WizardShortcutAction.java:99)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4256)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1501)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1524)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1509)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1313)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4080)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3706)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
Caused by: org.xml.sax.SAXParseExceptionpublicId: temp.xmi; systemId: file:///Applications/Eclipse%20copie.app/Contents/MacOS/temp.xmi; lineNumber: 1; columnNumber: 1; Fin prématurée du fichier.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1014)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
... 131 more
1 [Worker-12] ERROR org.eclipse.xtext.builder.impl.XtextBuilder - Passed org.eclipse.xtext.builder.clustering.CurrentDescriptions is not based on a resource set
java.lang.IllegalStateException: Passed org.eclipse.xtext.builder.clustering.CurrentDescriptions is not based on a resource set
at org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.getResourceSet(ResourceSetBasedAllContainersStateProvider.java:44)
at org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.get(ResourceSetBasedAllContainersStateProvider.java:26)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getState(StateBasedContainerManager.java:81)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.internalGetContainerHandle(StateBasedContainerManager.java:106)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getVisibleContainers(StateBasedContainerManager.java:59)
at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager.isAffected(DefaultResourceDescriptionManager.java:138)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.queueAffectedResources(ClusteringBuilderState.java:525)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.doUpdate(ClusteringBuilderState.java:300)
at org.eclipse.xtext.builder.builderState.AbstractBuilderState.update(AbstractBuilderState.java:116)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:287)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:267)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:161)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
!ENTRY org.apache.log4j 4 0 2017-06-01 13:31:39.450
!MESSAGE org.eclipse.xtext.builder.impl.XtextBuilder - Passed org.eclipse.xtext.builder.clustering.CurrentDescriptions is not based on a resource set
!STACK 0
java.lang.IllegalStateException: Passed org.eclipse.xtext.builder.clustering.CurrentDescriptions is not based on a resource set
at org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.getResourceSet(ResourceSetBasedAllContainersStateProvider.java:44)
at org.eclipse.xtext.resource.containers.ResourceSetBasedAllContainersStateProvider.get(ResourceSetBasedAllContainersStateProvider.java:26)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getState(StateBasedContainerManager.java:81)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.internalGetContainerHandle(StateBasedContainerManager.java:106)
at org.eclipse.xtext.resource.containers.StateBasedContainerManager.getVisibleContainers(StateBasedContainerManager.java:59)
at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager.isAffected(DefaultResourceDescriptionManager.java:138)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.queueAffectedResources(ClusteringBuilderState.java:525)
at org.eclipse.xtext.builder.clustering.ClusteringBuilderState.doUpdate(ClusteringBuilderState.java:300)
at org.eclipse.xtext.builder.builderState.AbstractBuilderState.update(AbstractBuilderState.java:116)
at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:287)
at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:267)
at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:161)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Any idea/suggestion/example please?
|
|
|
|
|
|
|
|
|
|
|
Re: MyDslDocumentProvider failed to save [message #1764784 is a reply to message #1764725] |
Fri, 02 June 2017 09:14 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
Thanks Chrisitan. It works perfectly.
So, the main issue is not here.
I just wanted to create a framework that corresponds to my real case.
The problem concerns the dsl itself.
Let me explain:
I have this metamodel
package myDsl : myDsl = 'http://www.xtext.org/example/mydsl/MyDsl'
{
class Model
{
property greetings : Greeting[*|1] { ordered composes };
}
class Greeting
{
attribute name : String[?];
attribute condition : Boolean[1] = 'true';
}
}
Just a small precision, in my genmodel, the Resource Type == XMI ("none" is the default value in the genmodel)
Then, I generate a Xtext grammar from this metamodel
// automatically generated by Xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.xtext.org/example/mydsl/MyDsl"
Model returns Model:
{Model}
'(' greetings+=Greeting* ')'
;
Greeting returns Greeting:
'Hello'
name=ID
(condition?='condition')?
'!'
;
The main problem concerns the condition attribute.
Two sub-problems exist:
1) when condition is false
When opening the resource with the textual editor, this error appears.
java.lang.RuntimeException: Could not serialize Greeting via backtracking.
Constraint: Greeting_Greeting returns Greeting: (name=ID condition?='condition'?);
Values: name(1), condition(1)
Semantic Object: Model.greetings[0]->Greeting'Eclipseee'
URI: temp.my
Context: Greeting returns Greeting
As explained previously here https://www.eclipse.org/forums/index.php?t=msg&th=1086278&goto=1763635&#msg_1763635
It is necessary to customize the MyDslTransientValueService by adding the following code.
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
override Class<? extends ITransientValueService> bindITransientValueService() {
MyDslTransientValueService
}
}
public class MyDslTransientValueService extends DefaultTransientValueService {
override boolean isTransient(EObject owner, EStructuralFeature feature, int index) {
if (feature == MyDslPackage.Literals.GREETING__CONDITION) {
var Boolean value = owner.eGet(feature) as Boolean;
if (value === null) {
return false;
} else if (value == Boolean.FALSE) {
return true;
}
}
return super.isTransient(owner, feature, index);
}
}
Therefore, this sub-problem is resolved.
2) when condition is true
This is the real problem.
If condition is true (shown by the emf editor), the "condition" keyword doesn't appear in the textual model.
In addition, when I try to add it manually, It is hidden during the save.
I saw that in the xmi, the condition attribute doesn't appear when it is true.
As explained in the EMF forum, to serialize the default value, it is necessary to customize the MyDslResourceImpl by overriding the doSave method as shown in the following.
public class MyDslResourceImpl extends XMIResourceImpl {
/**
* Creates an instance of the resource.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param uri the URI of the new resource.
* @generated
*/
public MyDslResourceImpl(URI uri) {
super(uri);
}
@Override
public void doSave(OutputStream outputStream, Map<?,?> options) throws
IOException {
this.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT,
Boolean.TRUE);
super.doSave(outputStream, options);
}
} //MyDslResourceImpl
Consequently, the condition attribute is serialized when it is true.
However, the "condition" keyword doesn't appear in the textual model.
And, when I edit the textual model (add white space for example); during saving, the xmi is changed by removing condition="true" from the xmi.
To conclude, my questions are:
How can I show the "condition" keyword when the condition attribute is true?
How can I inhibit Xtext removing condition="true" from the xmi?
I added a demo in the attachment to more explain the issue.
I share Also the source code with an example project.
best regards,
-
Attachment: MyDslXtext.mov
(Size: 13.14MB, Downloaded 89 times) -
Attachment: xtext.zip
(Size: 1.71MB, Downloaded 214 times)
|
|
|
Re: MyDslDocumentProvider failed to save [message #1764797 is a reply to message #1764784] |
Fri, 02 June 2017 09:56 |
|
(1) i dont understand your org.xtext.example.mydsl.ui.MyDslDocumentProvider.doSaveDocument(IProgressMonitor, Object, IDocument, boolean)
(2) you may need to customize and bind
public class CustomLegacyTransientValueService extends LegacyTransientValueService {
@Override
public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) {
//TODO
return super.isValueTransient(semanticObject, feature);
}
@Override
protected boolean defaultValueIsSerializeable(EStructuralFeature feature) {
//TODO
return super.defaultValueIsSerializeable(feature);
}
}
def Class<? extends org.eclipse.xtext.serializer.sequencer.ITransientValueService> bindITransientValueServiceOld() {
CustomLegacyTransientValueService
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
Re: MyDslDocumentProvider failed to save [message #1764802 is a reply to message #1764797] |
Fri, 02 June 2017 10:27 |
|
//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
=> without commenting out your factory is not used.
and i miss a customization of nothing => value = false
e.g. via
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parser.DefaultEcoreElementFactory;
import myDsl.Greeting;
public class CustomDefaultEcoreElementFactory extends DefaultEcoreElementFactory {
@Override
public EObject create(EClassifier classifier) {
EObject created = super.create(classifier);
if (created instanceof Greeting) {
((Greeting) created).setCondition(false);
}
return created;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Re: MyDslDocumentProvider failed to save [message #1764862 is a reply to message #1764809] |
Fri, 02 June 2017 16:02 |
Fy Za Messages: 245 Registered: March 2010 |
Senior Member |
|
|
I customize CustomLegacyTransientValueService like that
public class CustomLegacyTransientValueService extends LegacyTransientValueService {
@Override
public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) {
if (feature.getName().equals("condition")) {
if (((Greeting) semanticObject).isCondition())
return ValueTransient.NO;
else
return ValueTransient.YES;
} else {
return super.isValueTransient(semanticObject, feature);
}
}
@Override
protected boolean defaultValueIsSerializeable(EStructuralFeature feature) {
return super.defaultValueIsSerializeable(feature);
}
}
I comment the following lines
//resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
and
// static {
// MyDslStandaloneSetup.doSetup();
// }
the following class CustomDefaultEcoreElementFactory, where must be localized?
I put it in org.xtext.example.mydsl.
is it correct?
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.parser.DefaultEcoreElementFactory;
import myDsl.Greeting;
public class CustomDefaultEcoreElementFactory extends DefaultEcoreElementFactory {
@Override
public EObject create(EClassifier classifier) {
EObject created = super.create(classifier);
if (created instanceof Greeting) {
((Greeting) created).setCondition(false);
}
return created;
}
}
I am very near to resolve the issue.
Actually, when I change from the emf model, the changes are propagated to the textual model (changing condition to true, "condition" keyword appears, changing condition to false, "condition" keyword removed).
The only issue at this moment, it that, when I remove "condition" keyword from my textual model, it reappears when I save.
If you reproduced my case study, can you please share the code after your customizations please?
|
|
|
Re: MyDslDocumentProvider failed to save [message #1764863 is a reply to message #1764862] |
Fri, 02 June 2017 16:10 |
|
this is what i meant !?!
did you bind the factory:
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
override Class<? extends ITransientValueService> bindITransientValueService() {
MyDslTransientValueService
}
def Class<? extends org.eclipse.xtext.serializer.sequencer.ITransientValueService> bindITransientValueServiceOld() {
CustomLegacyTransientValueService
}
override bindIAstFactory() {
CustomDefaultEcoreElementFactory
}
}
public class CustomLegacyTransientValueService extends LegacyTransientValueService {
@Override
public ValueTransient isValueTransient(EObject semanticObject, EStructuralFeature feature) {
if (feature == MyDslPackage.Literals.GREETING__CONDITION) {
if ((boolean)semanticObject.eGet(feature)) {
return ValueTransient.NO;
}
}
return super.isValueTransient(semanticObject, feature);
}
@Override
protected boolean defaultValueIsSerializeable(EStructuralFeature feature) {
if (feature == MyDslPackage.Literals.GREETING__CONDITION) {
return true;
}
return super.defaultValueIsSerializeable(feature);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
|
|
Powered by
FUDForum. Page generated in 0.05971 seconds