Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Is it possible to define built-in EObjects
Is it possible to define built-in EObjects [message #846677] Mon, 16 April 2012 12:06 Go to next message
Eclipse UserFriend
Hi all,

We face a problem to properly manage predefined functions (native functions) in our Xtext based language.

Suppose that we have an EObject subclass A.

We would like to declare in our grammar (or in our Java code) some predefined instances of A, that have a specific name (native/a1 and native/a2 for instance).

If I declare A that way:

A :
name=(Name | "native/a1" | "native/a2")

Then the built in functions are properly recognized but as simple keywords, not as an instance of A.

Is there a way to prepopulate A with two instances corresponding to those built in functions?

Daniel
Re: Is it possible to define built-in EObjects [message #857741 is a reply to message #846677] Thu, 26 April 2012 16:32 Go to previous message
Eclipse UserFriend
You can define built-in objects in your DSL language - place them in a file in your plug-in and make sure you include those files in build.properties. Then bind your own IGlobalScopeProvider:

public class DSLRuntimeModule extends AbstractDSLRuntimeModule {
...
    @Override
    public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
    	return DSLImportUriGlobalScopeProvider.class;
    }
...
}


And make it look something like this:

public class DSLImportUriGlobalScopeProvider extends
		ImportUriGlobalScopeProvider {

	@Override
	protected LinkedHashSet<URI> getImportedUris(final Resource resource) {
		LinkedHashSet<URI> temp = super.getImportedUris(resource);
		temp.add(URI.createURI("platform:/plugin/<plugin id>/resources/builtin_functions.inc"));
		temp.add(URI.createURI("platform:/plugin/<plugin id>/resources/builtin_variables.inc"));
		return temp;
	}
}


This worked wonderfully for us, but now we're using Namespaces scoping (which I believe is the default) and I'm trying to find out how to do it without this URI approach...
Previous Topic:new xtext
Next Topic:[Solved] XbaseHoverDocumentationProvider
Goto Forum:
  


Current Time: Fri Jul 25 01:01:16 EDT 2025

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

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

Back to the top