Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Adding definition in global scope provider
Adding definition in global scope provider [message #1753282] Fri, 03 February 2017 05:08 Go to next message
Eclipse UserFriend
I tried to create a jar to add it as a plugin but it is more complicated than I thought. Thus, I decided to change the global scope provider instead. But I did not have much luck in adding the definition to the global scope provider manually.
There are some entries that are added only during generator part as the user does not need to specify it.

Hello admin age 99!
Hello sample age 2!
Bye sample ! see you  sept;


my grammar is:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=(Greeting| Test)*;
	
Greeting:
	'Hello' sample=[Test] 'age' age=INT '!';
Test:
	'Bye' sName=ID '!' 'see' 'you' date=ID ';'
;

I called MydslFactory::eInstance.createGreeting and set the variables in main.java before all the resource are loaded, but the error is still there. Are there any articles that shows how to do it in global scope provider and resource service provider?

Re: Adding definition in global scope provider [message #1753287 is a reply to message #1753282] Fri, 03 February 2017 05:23 Go to previous messageGo to next message
Eclipse UserFriend
whats the problem with the libary approach in the first place? is it your main method? what do you there? it should be no problem to traverste the lib jar directly or indirectly there

there is no tutorial.
many years ago i did something like (dont know if this still works)

public class MyDslGSP extends DefaultGlobalScopeProvider {

	@Inject
	IResourceDescription.Manager mgr;

	@Override
	public IScope getScope(Resource resource, EReference reference, Predicate<IEObjectDescription> filter) {
		URI libaryResourceURI = URI.createURI("dummy://demo/test.mydsl");
		Resource libaryResource = resource.getResourceSet().getResource(libaryResourceURI, false);
		if (libaryResource == null) {
			System.out.println("LOOOOOOOOAAAAADDDDD");
			libaryResource = resource.getResourceSet().createResource(libaryResourceURI);
			try {
				libaryResource.load(new StringInputStream("Hello Libary1! Hello Libary2 from Libary1!"), null);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		IResourceDescription resourceDescription = mgr.getResourceDescription(libaryResource);
		Iterable<IEObjectDescription> libary = resourceDescription.getExportedObjects();
		return new SimpleScope(super.getScope(resource, reference, filter), libary, false);
	}

}
Re: Adding definition in global scope provider [message #1753717 is a reply to message #1753287] Thu, 09 February 2017 04:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi Christian,
Thanks this works for me. I added this in my main.java though. The library approach did not work for me because I usually export a jar file, and don't know how to create a plugin.
Re: Adding definition in global scope provider [message #1753719 is a reply to message #1753717] Thu, 09 February 2017 04:40 Go to previous message
Eclipse UserFriend
hi i still cannot folow your problem.
as i said the solution would be much cleaner.
Previous Topic:ValidateTestHelper.asserError arguments
Next Topic:How to deresolve a URI
Goto Forum:
  


Current Time: Tue Jun 24 10:13:25 EDT 2025

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

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

Back to the top