Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with QuickFixes (ISemanticModification)
Problem with QuickFixes (ISemanticModification) [message #755186] Mon, 07 November 2011 15:55 Go to next message
Romain  Aïssat is currently offline Romain AïssatFriend
Messages: 16
Registered: June 2011
Junior Member
Hi all,

I've got some troubles with QuickFix as title says. As usual, here is a short example showing what I'd like to do and what the problem is.

Here is the grammar :

Model:
	(arithObjects += ArithObject)*;
	
ArithObject :
	name = ID '=' exp = Expression ';';
	
Expression :
	  AddRule;
	
AddRule returns Expression :
	MultRule 
	
	( {Add.left = current} '+' right = MultRule
	| {Sub.left = current} '-' right = MultRule)*;
	
MultRule returns Expression :
	TerminalExpression
	
	( {Mult.left = current} '*' right = TerminalExpression
	| {Div.left = current} '/' right = TerminalExpression)*;
	
TerminalExpression returns Expression :
Reference | '(' Expression ')' | Constant;

Constant returns Expression:
	{Constant} value = INT;
	
Reference :
	referenced = [ArithObject];


So I've got no problem with quickFix using IModification. For example, if I want to forbid the use of ID "x" for any ArithObject, I add this check :

@Check
public void checkNoXName(ArithObject o){
    if(o.getName().equals("x"))
        error("name is x",o,ArithPackage.Literals.ARITH_OBJECT__NAME,NAME_IS_X);
}


and this method to my QuickFixProvider :

@Fix(ArithJavaValidator.NAME_IS_X)
public void fixName(final Issue issue, IssueResolutionAcceptor acceptor){
    acceptor.accept(issue,
        "Name is x",
	"...",
	"",
	new IModification(){
	    public void apply(IModificationContext context){
	        IXtextDocument xtextDocument = context.getXtextDocument();
		try{
                    xtextDocument.replace(issue.getOffset(), 1,"y");
		}
		catch (Exception e){}
            }
	}
    );
}


This works fine.

Now I want to do this using an ISemanticModification, so here is the code, supposed to do the same as above :

@Fix(ArithJavaValidator.NAME_IS_X)
public void fixName(final Issue issue, IssueResolutionAcceptor acceptor){
    acceptor.accept(issue,
        "Name is x",
        "...",
	"",
	new ISemanticModification(){
	    public void apply(EObject element, IModificationContext context){
	        ArithObject o = (ArithObject) element;
		o.setName("y");
	    }
	}
    );
}


But when I select this quickFix in the popup, i've got this errors and can't understand why and how to solve this :

!ENTRY org.eclipse.ui 4 0 2011-11-07 16:49:37.257
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.emf.common.util.WrappedException: java.lang.RuntimeException: The context 'Model' is not valid for type 'ArithObject'
Recommended contexts for type 'ArithObject': ArithObject
The context 'Model' is valid for types: Model, null

Semantic Object: Model.arithObjects[0]->ArithObject'y'
	at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:50)
	at org.eclipse.xtext.ui.editor.quickfix.QuickAssistCompletionProposal.apply(QuickAssistCompletionProposal.java:32)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertProposal(CompletionProposalPopup.java:935)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.insertSelectedProposalWithMask(CompletionProposalPopup.java:881)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$27(CompletionProposalPopup.java:877)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$5.widgetDefaultSelected(CompletionProposalPopup.java:657)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:119)
	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:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	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:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.RuntimeException: The context 'Model' is not valid for type 'ArithObject'
Recommended contexts for type 'ArithObject': ArithObject
The context 'Model' is valid for types: Model, null

Semantic Object: Model.arithObjects[0]->ArithObject'y'
	at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:66)
	at org.xtext.serializer.AbstractArithSemanticSequencer.createSequence(AbstractArithSemanticSequencer.java:148)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:68)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:80)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:87)
	at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:42)
	at org.eclipse.xtext.serializer.impl.Serializer.serializeReplacement(Serializer.java:100)
	at org.eclipse.xtext.ui.editor.model.edit.DefaultTextEditComposer.getObjectEdits(DefaultTextEditComposer.java:163)
	at org.eclipse.xtext.ui.editor.model.edit.DefaultTextEditComposer.getTextEdit(DefaultTextEditComposer.java:138)
	at org.eclipse.xtext.ui.editor.model.edit.DefaultTextEditComposer.endRecording(DefaultTextEditComposer.java:122)
	at org.eclipse.xtext.ui.editor.model.edit.ReconcilingUnitOfWork.exec(ReconcilingUnitOfWork.java:38)
	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:189)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.internalModify(XtextDocument.java:98)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.modify(XtextDocument.java:91)
	at org.eclipse.xtext.ui.editor.model.edit.SemanticModificationWrapper.apply(SemanticModificationWrapper.java:31)
	at org.eclipse.xtext.ui.editor.quickfix.IssueResolution.apply(IssueResolution.java:48)
	... 31 more


Any help would be really wellcome, thanks in advance!

Romain
Re: Problem with QuickFixes (ISemanticModification) [message #755187 is a reply to message #755186] Mon, 07 November 2011 16:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you share a example model too? i cannot reproduce it using a dummy model.
btw which xtext version do you use?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with QuickFixes (ISemanticModification) [message #755196 is a reply to message #755187] Mon, 07 November 2011 16:18 Go to previous messageGo to next message
Romain  Aïssat is currently offline Romain AïssatFriend
Messages: 16
Registered: June 2011
Junior Member
By example model, do you mean an example of "code" which you could apply the quick fix on? In this case "x = 0;" should do it =) (using Xtext 2.0)

But the 8-th post of this topic gives the solution :

http://www.eclipse.org/forums/index.php/m/696530/?srch=quickfix#msg_696530

"I take you created a new project with Xtext 2.0 with the "Experimental
features" configuration. The new serializer as of June 23rd could not
handle partial serialization. I'd recommend to enable the
ParseTreeConstructorFragment instead of the SerializerFragment in your
workflow."

Remaking a new Xtext project, disabling Experimental Features and SerializerFragment and enabling ParseTreeConstructorFragment instead works indeed.

Thanks for your help Christian!
Re: Problem with QuickFixes (ISemanticModification) [message #755197 is a reply to message #755196] Mon, 07 November 2011 16:19 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Btw. this problem is already fixed in 2.0.1 / 2.1.0

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Xtend] constructors with arguments, class methods?
Next Topic:Implementing a pre-defined DSL: some approach questions
Goto Forum:
  


Current Time: Thu Apr 25 20:43:34 GMT 2024

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

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

Back to the top