Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Content Assist, enum types and templates
Content Assist, enum types and templates [message #723840] Fri, 09 September 2011 16:20 Go to next message
Michel Simeon is currently offline Michel SimeonFriend
Messages: 130
Registered: December 2009
Senior Member
In a previous thread of this forum (http://www.eclipse.org/forums/index.php/t/236795/) I was given indications on how to solve my problem using completeKeyword in the ui proposal provider. I got it to solve my problem but I do not fully understand the way things work !!!

In order to test if an enum type value had been assigned to a variable or not I had to add dummy values such as:

enum PlanInPlanType:
PlanInPlanTypeNull |
annual = "annual" | phastot = "phastot"
| phasadd = "phasadd" | phasold = "phasold"
;

Now I would like to have some templates like:

<template name="-PlanPlanItem" description="template for a PlanPlanItem"
id="fr.msimeon.mads.mads.PlanPlanItem"
context="fr.msimeon.mads.Mads.PlanItem"
enabled="true">${Plan:CrossReference('PlanItem.planItemRef')} ${planCalcType:Enum('PlanInPlanType')} [ 0 0 ]; // or read function
</template>

corresponding to one of the options of the PlanItem rule:
PlanItem: (
('run' scriptRef = [Script|ID] SEMI)
| ( planItemRef = [Entity|ID]
(
commCalcType = CommInPlanType
| planCalcType = PlanInPlanType
| herdCalcType = HerdInPlanType // can only be phased
)
(('[' (values+= Value )+ ']')| (levelvalues=ReadFunc))
SEMI
)
);

Although direct CA (through custom completeKeyword) gives me a list with only the four meaningful values, the list from the template also includes the PlanInPlanTypeNull value. Is there a reasonable way to control that ?

Thanks again to the XText team for its great support.

MS

Re: Content Assist, enum types and templates [message #723879 is a reply to message #723840] Fri, 09 September 2011 18:47 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

just as you adapted content assist, you will probably have to adapt the template variable resolution. Start looking at EnumTemplateVariableResolver. At a first glance, it should not be too difficult to adapt that code to your needs.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Content Assist, enum types and templates [message #723928 is a reply to message #723879] Fri, 09 September 2011 21:42 Go to previous messageGo to next message
Michel Simeon is currently offline Michel SimeonFriend
Messages: 130
Registered: December 2009
Senior Member
Thanks Alex for the quick reaction.

I'll give it a try and write a custom EnumTemplateVariableResolver.

But I have no idea on where it fits. There is a hook to adapt the proposal provider where I could put my own completeKeyword method. Where do I include, insert, bind or inject my resolver ?

MS
Re: Content Assist, enum types and templates [message #723931 is a reply to message #723928] Fri, 09 September 2011 21:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

	public Class<? extends EnumTemplateVariableResolver> bindEnumTemplateVariableResolver() {
		return MyEnumTemplateVariableResolver.class;
	}


doesn't work?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assist, enum types and templates [message #723997 is a reply to message #723931] Sat, 10 September 2011 08:47 Go to previous messageGo to next message
Michel Simeon is currently offline Michel SimeonFriend
Messages: 130
Registered: December 2009
Senior Member
As a matter of fact it does ! This is what I had none but for some odd reason I thought it was not working.

I still have to complete MyEnumTemplateVariableResolver, but that should be no problem.

Thanks again
MS
Re: Content Assist, enum types and templates [message #724178 is a reply to message #723997] Sun, 11 September 2011 08:59 Go to previous message
Michel Simeon is currently offline Michel SimeonFriend
Messages: 130
Registered: December 2009
Senior Member
For those dealing with similar problems, you should know that the XText framework also includes a cross-reference variable resolver (org.eclipse.xtext.ui.editor.templates.CrossReferenceTemplateVariableResolver) that can also be adapted as easily as the Enum one.

Great framework indeed !!!

MS
Previous Topic:[XBase] Overwriting Xbase Grammar Elements
Next Topic:Resolving references across different models using ImportedNamespaceAwareLocalScopeProvider
Goto Forum:
  


Current Time: Fri Apr 19 01:41:08 GMT 2024

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

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

Back to the top