Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Including custom models for default imports
Including custom models for default imports [message #722358] Mon, 05 September 2011 13:45 Go to next message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
I have a grammar which has support for builtin types (like Int, Bool, String etc.). I initially implemented these with

type=[Type] | basicType=BasicType


but decided to change this to the cleaner approach of defining those types in a different dsl. However, I don't want to force users to import this dsl manually, so I followed the second approach outlined in Xtext cross references and scoping an overview (Part 3).

My grammar already uses Imported Namespaces thanks to a rule:

ClassDecl:
	'class' name=Word
	( 'extends' importedNamespace=[ClassDecl] )?
	( classParams += ClassParam )*
	SEMICOLON;


so I followed the second approach in the above guide, ending up with:

public class UnrealscriptImportedNamespaceAwareLocalScopeProvider extends
		ImportedNamespaceAwareLocalScopeProvider 
{
	@Override
	protected List<ImportNormalizer> getImplicitImports(boolean ignoreCase) 
	{
		System.out.println("getImplicitImports called");
		List<ImportNormalizer> temp = new ArrayList<ImportNormalizer>();
		temp.add(new ImportNormalizer(
			QualifiedName.create("array"),
			true, ignoreCase));
		return temp;
	}
}


Now, I have a file "builtins.uc", with the following content:

class array;

struct byte
{
};

struct int
{
};

struct float
{
};

struct string
{
};

struct bool
{
};

struct name
{
};


and I can't quite figure out where I should embed this file so that the scope provider is able to locate it but it doesn't appear in the user's workspace.

[Updated on: Mon, 05 September 2011 13:46]

Report message to a moderator

Re: Including custom models for default imports [message #722362 is a reply to message #722358] Mon, 05 September 2011 13:58 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

there is a blog post on default imports. The idea is to ship the model file with your language plugin and have it on the classpath of the "referencing" plugin. That way it is indexed, you can navigate to the file, but you can't edit it.

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: Including custom models for default imports [message #722364 is a reply to message #722362] Mon, 05 September 2011 14:04 Go to previous messageGo to next message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Hi Alex,

Thanks for the prompt reply. Like I said, the blog post is the one I followed (couldn't link to it since I haven't posted five messages yet). I was under the impression that classpaths are applicable only to imported URIs and not to imported namespaces. Does setting a classpath work with imported namespaces too?

~Amey

[Updated on: Mon, 05 September 2011 14:04]

Report message to a moderator

Re: Including custom models for default imports [message #722367 is a reply to message #722364] Mon, 05 September 2011 14:14 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I did not mean setting the class path uri in the scope provider, but making the plugin containing your models depend on the plugin that contains builtins.uc.

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: Including custom models for default imports [message #722371 is a reply to message #722367] Mon, 05 September 2011 14:39 Go to previous messageGo to next message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Hi Alex,

Forgive me, for this'll probably sound like a stupid question, but what do you mean by "the plugin containing your models"?

I thought there was only one plugin, the one that contains builtins.uc, and the models were contained inside a project. And since it's not a Java project, I can't set the classpath for it.

Thanks,
~Amey
Re: Including custom models for default imports [message #722439 is a reply to message #722371] Mon, 05 September 2011 19:13 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Amey,

you could try to load the builtin.uc by means of a URI of the form
"platform:/plugin/your.plugin/model/builtin.uc" into your resource set.
This could by done in your scope provider implementation. This way, no
dependency is necessary. Unfortunately you'll have to provide the list
of builtin types explicitly because they won't be indexed.
Please note also, that platform:/plugin is unlikely to work in a
standalone environment.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 05.09.11 16:39, amey.par wrote:
> Hi Alex,
>
> Forgive me, for this'll probably sound like a stupid question, but what
> do you mean by "the plugin containing your models"?
>
> I thought there was only one plugin, the one that contains builtins.uc,
> and the models were contained inside a project. And since it's not a
> Java project, I can't set the classpath for it.
>
> Thanks,
> ~Amey
Re: Including custom models for default imports [message #722763 is a reply to message #722439] Tue, 06 September 2011 16:29 Go to previous message
amey.par is currently offline amey.parFriend
Messages: 17
Registered: July 2011
Junior Member
Hi Sebastian,

Thanks, but I decided to inject DefaultGlobalScopeProvider and hide builtins.uc inside the project folder so that it gets indexed.

~Amey
Previous Topic:creating a typereference from xtend class
Next Topic:Using xText content assist from an proprietary plugin
Goto Forum:
  


Current Time: Tue Apr 16 21:21:45 GMT 2024

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

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

Back to the top