[solved] Content Assist with "dynamic templates" [message #642432] |
Wed, 01 December 2010 10:24 |
|
Hello,
I have a simple DSL
Model: AbstractObject | InstanzObject;
AbstractObject: 'AbstractObject' name=ID
'{'
(propertyDecls+=PropertyDecl)*
'}';
InstanzObject : 'InstanzObject' name=ID 'implements' base=[AbstractObject]
'{'
(propertyDefs+=PropertyDefs)*
'}';
PropertyDecl: type=TYPE name=ID;
PropertyDef: name=[PropertyDecl] ':=' value=VALUE;
to describe object models like
AbstractObject BaseObject
{
int PropertyA
string PropertyB
}
InstanzObject Object1 implements BaseObject
{
PropertyA := 5
PropertyB := "Hello World"
}
Now I want to achieve the user may type up to
InstanzObject Object1 implements BaseObject
and to get a template implementation like
{
PropertyA := <int>
PropertyB: = <string>
}
automatically by consulting the content assist. Thus the user has only to fill in the values.
Currently the content assist only gives me the '{' as an option after "BaseObject". Instead it should generate the whole block depending on the referenced AbstractObject.
Is it possible to do it? Can somebody give me a hint which completion method inside the MyDslProposalProvider I have to implement? And how to get the relevant data from the reference?
Thank you in advance,
Jonatan
[Updated on: Thu, 16 December 2010 09:31] Report message to a moderator
|
|
|
|
|
|
Re: Content Assist with "dynamic templates" [message #645251 is a reply to message #642679] |
Thu, 16 December 2010 09:30 |
|
Hello all,
thank you for your ideas.
I have figured out a solution. It is not the best way I guess, but the way I was able to do it quickly.
I have just enhanced the org.xtext.mydsl.ui.MyDSLProposalProvider class.
public void completeInstanzObject_base(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
super.completeInstanzObject_base(model, assignment, context, acceptor);
InstanzObject instanz = (InstanzObject)context.getCurrentModel();
AbstractObject abstract = instanz.getbase();
EList<PropertyDecl> properties = abstract.getpropertyDefs();
String dstr = abstract.getname() + " { [..] } - Instanz Template";
String pstr = abstract.getname() + "\r\n";
pstr += "{\r\n";
for (PropertyDecl property: properties) {
pstr += property.getname() + ":= <" + property.gettype() + ">\r\n";
}
pstr += "}\r\n";
ICompletionProposal proposal = createCompletionProposal(pstr, dstr, null, context);
acceptor.accept(proposal);
}
This way the template is constructed on the fly.
Jonatan
|
|
|
|
Powered by
FUDForum. Page generated in 0.03483 seconds