|
|
|
|
|
|
|
|
Re: Tutorial about Quick Fixes [message #1386627 is a reply to message #1386622] |
Wed, 18 June 2014 20:13 |
|
Hi,
there is actually a difference between quickfixes and quick assist.
xtext can only quick fixes for Isses Produced by the validator
But let us asume you have the xtext hello world example
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
class MyDslValidator extends AbstractMyDslValidator {
public static val GREETING_NOT_USED = 'GREETING_NOT_USED'
@Check
def checkGreetingStartsWithCapital(Greeting greeting) {
warning('Greeting is not in use',
MyDslPackage.Literals.GREETING__NAME,
GREETING_NOT_USED)
}
}
class MyDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix(MyDslValidator.GREETING_NOT_USED)
def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove Greeting', 'Remove the Greeting from the file', 'upcase.png') [
eobject, context |
if (eobject instanceof Greeting) {
val g = eobject as Greeting
EcoreUtil2.getContainerOfType(g, Model).greetings -= g
}
]
}
}
for real quick assist i thing you have to do all the stuff yourself (XtextQuickAssistProcessor)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Tutorial about Quick Fixes [message #1386731 is a reply to message #1386627] |
Thu, 19 June 2014 23:03 |
Félix SILINOU KAMDEM Messages: 96 Registered: April 2013 |
Member |
|
|
Hi Christian,
I have tried what you told for a specific element in my grammar. I can have a quick fixes remove. But When I am clicking on it, no element is remove.
Here is my code:
grammar org.ramses.mydsl.RamsesDsl with org.eclipse.xtext.common.Terminals
generate ramsesDSL "http://www.ramses.org/mydsl/RamsesDSL"
import 'http://www.eclipse.org/emf/2002/Ecore' as refModel
Ramses: contents+=Contents*;
Contents: Altern | Decision | Result ;
Altern: name=Alternative;
/********************** Alternative *************************/
Alternative:
'Alternative' id=INT ':'
'for' element=ElementSyntaxName 'select' ':'
rule=Rule (params+=RuleList)* ';' ;
RuleList: 'or' rule=Rule ;
...
...
...
/********************** End Alternative **********************/
class RamsesDslValidator extends AbstractRamsesDslValidator {
public static val REMOVE_ELT = 'RomevedElement'
@Check
def removeAlternativeDecision(Altern altern) {
// faire un traitement pour vérifier que les éléments doivent être enlever
error('Alternative and decision should be remove after taking your decision', RamsesDSLPackage.Literals.ALTERN__NAME, REMOVE_ELT)
}
}
class RamsesDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix(RamsesDslValidator::REMOVE_ELT)
def removeGreeting(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove Alternative and decision', 'Remove Alternative and decision from the file after making your choice', 'upcase.png') [
eobject, context |
if (eobject instanceof Altern) {
val g = eobject as Altern
EcoreUtil2.getContainerOfType(g, Ramses).contents -= g
}
]
}
}
Best Regards,
Felix
|
|
|
|
|
|
|
|
|
Re: Tutorial about Quick Fixes [message #1386758 is a reply to message #1386752] |
Fri, 20 June 2014 07:23 |
|
Sorry i had misread your Grammar,
in such situations using a debugger is helpful.
this showed that there is actually a exception
java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null contents+=Contents+ null
Values:
Semantic Object: Ramses
Context: Ramses
if you have a look at the Grammar rule Ramses you can see a warning
Ramses: contents+=Contents*;
thus the model can be entirely empty. xtext does not be able to handle that in the serializer.
could you file a bug for that
as a workaround change the entry rule to
Ramses: {Ramses}contents+=Contents*;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Tutorial about Quick Fixes [message #1386844 is a reply to message #1386758] |
Sat, 21 June 2014 14:34 |
Félix SILINOU KAMDEM Messages: 96 Registered: April 2013 |
Member |
|
|
Hi Christian,
I have debugging it but I didn't get the same error as yours.
I did something like this :
def removeGreeting(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove Alternative and decision', 'Remove Alternative and decision from the file after making your choice.', 'upcase.png') [
eobject, context |
if (eobject instanceof Altern) {
val g = eobject as Altern
val list = EcoreUtil2.getContainerOfType(g, Contents).eContents
print("first size of my list " + list.size)
println(list)
list.forEach[
println("\t"+it.eClass().name)
]
list -= g
print("second size of my list " + list.size)
println(list)
}
]
}
I realized that my list has the same size with the same element after removing it. Even this isn't working : [b]"list.remove(g)"[/b]
And Below you see the containt of my log file
!ENTRY org.eclipse.ui 4 0 2014-06-21 15:38:44.553
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.egit.ui.internal.repository.tree.FolderNode cannot be cast to org.eclipse.egit.ui.internal.repository.tree.FileNode
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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)
Caused by: java.lang.ClassCastException: org.eclipse.egit.ui.internal.repository.tree.FolderNode cannot be cast to org.eclipse.egit.ui.internal.repository.tree.FileNode
at org.eclipse.egit.ui.internal.repository.tree.command.AddToIndexCommand.execute(AddToIndexCommand.java:34)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 33 more
!ENTRY org.eclipse.ui 4 0 2014-06-21 15:38:50.817
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.egit.ui.internal.repository.tree.FolderNode cannot be cast to org.eclipse.egit.ui.internal.repository.tree.FileNode
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:231)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:212)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:131)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:171)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:831)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.handleWidgetSelection(HandledContributionItem.java:724)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.access$7(HandledContributionItem.java:708)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem$4.handleEvent(HandledContributionItem.java:647)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
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:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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)
Caused by: java.lang.ClassCastException: org.eclipse.egit.ui.internal.repository.tree.FolderNode cannot be cast to org.eclipse.egit.ui.internal.repository.tree.FileNode
at org.eclipse.egit.ui.internal.repository.tree.command.AddToIndexCommand.execute(AddToIndexCommand.java:34)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
... 33 more
[Updated on: Sat, 21 June 2014 14:36] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.15822 seconds