Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Auto-edit after reference completion
Auto-edit after reference completion [message #1016365] Wed, 06 March 2013 09:06 Go to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi,

In my grammar, I have a rule like that:

PartProvidedPortReference returns spead::PortReferenceWA:
	{PartProvidedPortReference}
	declaringComponent=[spead::ComponentInstance|ValidID] '.'
	port=[spead::ProvidedPort|ValidID];


Is it possible to have the dot '.' auto-inserted after completion of declaringComponent using content-assist?

Thank you!
Re: Auto-edit after reference completion [message #1016981 is a reply to message #1016365] Fri, 08 March 2013 12:52 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Hi, I take the liberty of "uping" this post Smile
Re: Auto-edit after reference completion [message #1016993 is a reply to message #1016981] Fri, 08 March 2013 14:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi guess there is not out of the box solution for that, you can try to hook into

(a)

org.eclipse.xtext.ui.editor.contentassist.AbstractJavaBasedContentProposalProvider.DefaultProposalCreator.DefaultProposalCreator(AbstractJavaBasedContentProposalProvider, ContentAssistContext, String, IQualifiedNameConverter)

by overriding

org.eclipse.xtext.ui.editor.contentassist.AbstractJavaBasedContentProposalProvider.getProposalFactory(String, ContentAssistContext)

(b) org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider.createCompletionProposal(String, StyledString, Image, ContentAssistContext)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-edit after reference completion [message #1017013 is a reply to message #1016993] Fri, 08 March 2013 15:44 Go to previous messageGo to next message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Thank you for these details, in the end I extended XbaseReferenceProposalCreator (and injected it in my UiModule) so that I can check the type of the feature that is being completed and then I tweaked the proposalCreator.

It gives me something like that for the record, I hope I didn't forget anything when modifying the proposal that is created:

public class SpeADLReferenceProposalCreator extends XbaseReferenceProposalCreator {

	@Override
	protected Function<IEObjectDescription, ICompletionProposal> getWrappedFactory(
			final EObject model, final EReference reference,
			final Function<IEObjectDescription, ICompletionProposal> proposalFactory) {
		
		if (reference.equals(SpeADPackage.Literals.PORT_REFERENCE__DECLARING_INSTANCE)) {
			return new Function<IEObjectDescription, ICompletionProposal>() {
				public ICompletionProposal apply(IEObjectDescription from) {
					ConfigurableCompletionProposal result = (ConfigurableCompletionProposal) proposalFactory.apply(from);
					// TODO why null??!!
					if (result != null) {
						result.setReplacementString(result.getReplacementString() + ".");
						result.setCursorPosition(result.getCursorPosition()+1);
					}
					return result;
				}
			};
		}
		return super.getWrappedFactory(model, reference, proposalFactory);
	}
	
}


As you can see in my TODO comment, I don't know why, sometimes result is null.
Actually, when triggering completion, the proposal creator is called twice per candidate reference!
Re: Auto-edit after reference completion [message #1017051 is a reply to message #1017013] Fri, 08 March 2013 18:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it may be null e.g. if the qualified name of your thing is not serializable at this point



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Auto-edit after reference completion [message #1017108 is a reply to message #1017051] Sat, 09 March 2013 12:15 Go to previous message
Victor Noël is currently offline Victor NoëlFriend
Messages: 112
Registered: June 2010
Senior Member
Ok, that must be it I think Smile

Thank you for the explanation!
Previous Topic:2-step generating
Next Topic:Duplicate Name Default Error
Goto Forum:
  


Current Time: Thu Apr 18 11:37:33 GMT 2024

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

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

Back to the top