Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » ImportURI for newbs(What am I doing wrong here?)
icon5.gif  ImportURI for newbs [message #676175] Fri, 03 June 2011 06:14 Go to next message
Jack  is currently offline Jack Friend
Messages: 12
Registered: May 2011
Junior Member
I just can't figure out how to implement ImportURI scoping for my plugin. I've had a look at the Xtext documentation, and also this blog post: http://www.eclipse.org/forums/index.php/mv/msg/207406/664109/#msg_664109

... but I'm still doing something wrong Embarrassed .
Perhaps someone can tell me what's missing in the example below?

My example grammar looks like this:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:	statements+=Statement*;
Statement:	Import | Function | Execute ;

Import	:	'Import'	ImportURI=STRING ;
Function:	'Function'	name=ID 'END';
Execute	: 	'Execute'	name=[Function];


My "test project" looks like this:
\MyProject\File1.dsl
Function PlantTree END
Function WaterTree END

\MyProject\File2.dsl
Function PruneTree END

\MyProject\File3.dsl
Import 'file1.dsl'

// these should resolve (File1.dsl):
Execute PlantTree
Execute WaterTree

 // this should error (File2.dsl not imported):
Execute PruneTree



I have made the following changes to the xtext project:
Modified:
...
var grammarURI = "classpath:/org/xtext/example/mydsl/MyDsl.xtext"
var file.extensions = "dsl"
var projectName = "org.xtext.example.mydsl"
var runtimeProject = "../${projectName}"

...etc
			// java-based API for validation 
			fragment = validation.JavaValidatorFragment {
				composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
				// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
				// registerForImportedPackages = true
			}

			// scoping and exporting API
			 fragment = scoping.ImportURIScopingFragment {}
			 fragment = exporting.SimpleNamesFragment {}

			// scoping and exporting API 
//			fragment = scoping.ImportNamespacesScopingFragment {}
//			fragment = exporting.QualifiedNamesFragment {}
//			fragment = builder.BuilderIntegrationFragment {}
... etc


Modified:
public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
		public Class<? extends ImportUriResolver> bindimporturiResolver() {
			return MyDslImportUriResolver.class;
		}

}


New class:
public class MyDslImportUriResolver extends ImportUriResolver {
	
	@Override
	public String resolve(EObject object) {
		return "platform:/resource/MyProject/"+super.resolve(object);
	}
}


New class:
public class MyDslImportUriGlobalScopeProvider extends ImportUriGlobalScopeProvider{

	@Override
	public IScope getScope(EObject context, EReference reference) {
		return super.getScope(context, reference);
	}
	
}


What else am I missing? (Thanks in advance)

[Updated on: Fri, 03 June 2011 06:15]

Report message to a moderator

Re: ImportURI for newbs [message #676198 is a reply to message #676175] Fri, 03 June 2011 07:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

First you usually do not need customizations to ImportUriGlobalScopeProvider and ImportUriResolver so take the default impls here.
Second the feature must be named importURI and not ImportURI.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
(no subject) [message #676203 is a reply to message #676175] Fri, 03 June 2011 07:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

First you usually do not need customizations to ImportUriGlobalScopeProvider and ImportUriResolver so take the default impls here.
Second the feature must be named importURI and not ImportURI.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: ImportURI for newbs [message #676402 is a reply to message #676175] Sat, 04 June 2011 07:13 Go to previous message
Jack  is currently offline Jack Friend
Messages: 12
Registered: May 2011
Junior Member
As per your suggestions:
- Changed feature in grammar from "ImportURI" to "importURI"
- Removed change to Runtime class
- Deleted custom resolver and global scope provider classes

...it works!

Thanks heaps!
Previous Topic:How to check on source name?
Next Topic:Managing LocalScopeProvider
Goto Forum:
  


Current Time: Fri Apr 26 10:55:53 GMT 2024

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

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

Back to the top