Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » content assist across files(can one create template proposals across files)
content assist across files [message #763432] Fri, 09 December 2011 18:54 Go to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Hi,
if i have an autocompletion that lists all elements for some rule, now if i defined another dsl file with some aditional elements, can the autocompletion list all proposals from the two dsl files?

Thank you,
Mokhtar
Re: content assist across files [message #763446 is a reply to message #763432] Fri, 09 December 2011 19:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13769
Registered: July 2009
Senior Member
Hi,

i do not understand your question. it would be helpful if youd explain it with an example

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: content assist across files [message #763452 is a reply to message #763446] Fri, 09 December 2011 20:00 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
ok sorry.
Grammar is:
MyRule: 'Hey du ' Person;
Person: name = ID;

assume now that this code in model1.dsl:
Hey du mokhtar
Hey du tim
and this in model2.dsl
Hey du john
Hey du anne
=========
if i used the content assist stub for MyRule to list the person names, could this list them across the two files?

Hope i convey it correctly!
Mokhtar
Re: content assist across files [message #763457 is a reply to message #763452] Fri, 09 December 2011 20:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13769
Registered: July 2009
Senior Member
Hi,

yes e.g. by querying the index (via ResourceDescriptionsProvider). but please note: i still dont understand why you dont use cross references. this would give you everyting for free!!!!!!!!!!

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: content assist across files [message #763464 is a reply to message #763457] Fri, 09 December 2011 20:27 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Thank you! could you please tell me where and how to use the "ResourceDescriptionsProvider"?
for your question, actually, i am making dsl for prolog like language, given:

ct(head,condition(true),idcreation(skip),transformation(add(getter))).
ct(copyField(Field1,Field2,V),condition(true),idcreation(skip),transformation(replace(Field1,Field2))).
ctseq(doStuff,ct(head)).
ctseq(doStuff2,ct(copyField(F,F,value))).

those were say 4 prolog facts, in the third and fourth you note that i reused ct(head) and ct(copyField(..)) from their defining facts above. So i can't easily reference that part of prolog fact to the other fact providing at same time flexibility to user to change the arguments. SO prolog is type unsafe and you should beable in same program to change the structure of the predicates, so cross-reference FAILED Sad and i think to do that job in IDE runtime
Thank you,
Mokhtar
Re: content assist across files [message #763466 is a reply to message #763464] Fri, 09 December 2011 20:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13769
Registered: July 2009
Senior Member
Hi,

here a simple example

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID value=ID '!';


public class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	@Inject
	ResourceDescriptionsProvider rdp;
	
	@Override
	public void completeGreeting_Value(EObject model, Assignment assignment,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		IResourceDescriptions rd = rdp.getResourceDescriptions(model.eResource());
		for (IEObjectDescription d : rd.getExportedObjectsByType(MyDslPackage.Literals.GREETING)) {
			acceptor.accept(createCompletionProposal(d.getQualifiedName().toString(), context));
		}
	}

}


for perf reasons you may habe to add stuff to the user data of the ieobjectdesription using a custom DefaultResourceDescriptionStrategy
and store the information about the params there.
(use EObjectDescription.create(qualifiedName, eObject, userData) in the code.
alternatively you would have to do proxy resolving on IEObjectDescription.getEObjectOrProxy
which might be perf hell when having many/big files

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: content assist across files [message #763473 is a reply to message #763466] Fri, 09 December 2011 20:44 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar AbduFriend
Messages: 104
Registered: November 2011
Senior Member
Thank you so much for this valuable help. We won't be having big files in our new DSL because it is declarative.
Gute Nacht,
Mokhtar
Re: content assist across files [message #763474 is a reply to message #763473] Fri, 09 December 2011 20:47 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13769
Registered: July 2009
Senior Member
Just to be complete here a demo of the strategy

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID number=INT value=ID '!';


public class MydslResourceDescriptionStrategy extends
		DefaultResourceDescriptionStrategy {
	
	@Override
	public boolean createEObjectDescriptions(EObject eObject,
			IAcceptor<IEObjectDescription> acceptor) {
		if (getQualifiedNameProvider() == null)
			return false;
		try {
			QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(eObject);
			if (qualifiedName != null) {
				
				Map<String, String> userData = new HashMap<String, String>();
				if (eObject instanceof Greeting) {
					userData.put("number", ((Greeting)eObject).getNumber()+"");
				}
				acceptor.accept(EObjectDescription.create(qualifiedName, eObject, userData ));
			}
		} catch (Exception exc) {
			
		}
		return true;
	}

}


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	public Class<? extends IDefaultResourceDescriptionStrategy> bindIDefaultResourceDescriptionStrategy() {
		return MydslResourceDescriptionStrategy.class;
	}
	
}


public class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	@Inject
	ResourceDescriptionsProvider rdp;
	
	@Override
	public void completeGreeting_Value(EObject model, Assignment assignment,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		IResourceDescriptions rd = rdp.getResourceDescriptions(model.eResource());
		for (IEObjectDescription d : rd.getExportedObjectsByType(MyDslPackage.Literals.GREETING)) {
			acceptor.accept(createCompletionProposal(d.getQualifiedName().toString()+d.getUserData("number"), context));
		}
	}

}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Xtext 2.2] NPE in JvmMemberRenameStrategy in a JDT project
Next Topic:[Xtext 2.1.1] interface segregation
Goto Forum:
  


Current Time: Sun Mar 07 06:21:54 GMT 2021

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

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

Back to the top