Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Regarding cross-references between different files.
Regarding cross-references between different files. [message #1785039] Sun, 08 April 2018 10:38 Go to next message
Eclipse UserFriend
Hello Christian,


I made my grammar with Xtext and it contains cross-references between elements. The cross-references are available from one file to another which I have not imported. I want to restrict cross-referencing to elements only present in the imported file. As far as I understand I have to override the IGlobalScopeProvider but which function I have to override to enable the required functionality.

Thanks in Advance..
Re: Regarding cross-references between different files. [message #1785040 is a reply to message #1785039] Sun, 08 April 2018 10:45 Go to previous messageGo to next message
Eclipse UserFriend
Doing these bindings (pseudo code) should do the trick

override bindIGlobalScopeProvider() { importuriglobalscopeprovider }

override configureIScopeProviderDelegate(Binder binder) { binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) .to(SimpleLocalScopeProvider); }

(+Potentially SimpleNameProvider)
Re: Regarding cross-references between different files. [message #1785041 is a reply to message #1785040] Sun, 08 April 2018 11:00 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the help. I have written
override configureIScopeProviderDelegate(Binder binder) { binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)) .to(SimpleLocalScopeProvider); } in my scopeProvider but I am not able to understand override bindIGlobalScopeProvider() { importuriglobalscopeprovider } ??


Do I also need to create my custom class that extends ImportedNamespaceAwareLocalScopeProvider.

Re: Regarding cross-references between different files. [message #1785043 is a reply to message #1785041] Sun, 08 April 2018 11:05 Go to previous messageGo to next message
Eclipse UserFriend
no

as a said this is pseudo code :(((((((((((

import com.google.inject.Binder
import com.google.inject.name.Names
import org.eclipse.xtext.scoping.IScopeProvider
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider
import org.eclipse.xtext.scoping.impl.ImportUriGlobalScopeProvider
import org.eclipse.xtext.scoping.impl.SimpleLocalScopeProvider

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	override bindIGlobalScopeProvider() { 
		ImportUriGlobalScopeProvider
	}

	override configureIScopeProviderDelegate(Binder binder) {
		binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(
			SimpleLocalScopeProvider);
	}

}

Re: Regarding cross-references between different files. [message #1785044 is a reply to message #1785043] Sun, 08 April 2018 11:30 Go to previous messageGo to next message
Eclipse UserFriend
Hey Christian,

Thanks a ton. You are a Genius!!!.. :-) Last query for the day. Now I am getting the references as required but they are coming in QualifiedName i.e for ex.

interface ClientIntern extends Chat.Main.ClientGUI

I need only interface ClientIntern extends ClientGUI..

How can I use the QualifiedName identifier here to get the simple name?

Thanks for the help... :-)


Re: Regarding cross-references between different files. [message #1785045 is a reply to message #1785044] Sun, 08 April 2018 12:07 Go to previous messageGo to next message
Eclipse UserFriend
AS i said

Bind simplenAmeprovider AS iqualifiednameprovider
Re: Regarding cross-references between different files. [message #1785047 is a reply to message #1785045] Sun, 08 April 2018 13:22 Go to previous messageGo to next message
Eclipse UserFriend
Done...again, thank you so much :)
Re: Regarding cross-references between different files. [message #1785052 is a reply to message #1785047] Sun, 08 April 2018 15:25 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christian,

Sorry to bother you again, actually I tested for the local references within a file and it is working perfectly fine, but import statement across the files is not showing the references of the imported file using the import statement. Please find the grammar below.

Antlr Grammar

// Module declaration
module_decl : 'module' QualifiedName ';'
module_export*
module_import*
;

module_export : 'export'
( '*' | s+=QualifiedName (',' s+=QualifiedName)*)
('from' f=QualifiedName)?
';'
;

module_import : 'import'
( '*' 'from' f=QualifiedName ';'
| s+=QualifiedName (',' s+=QualifiedName)* 'from' f=QualifiedName ';'
| s+=QualifiedName (',' s+=QualifiedName)* ';'
)
;

Xtext Grammar

//Module_declaration
Module_decl:'module' name=QualifiedName ';'
module_export+=Module_export* module_import+=Module_import*
;


//Module_export
Module_export:{Module_export}'export'
('*' |anyPackage1=QualifiedName(',' anyPackage+=QualifiedName)*)
('from' importedNamespace=[Module_decl|QualifiedName])? ';'
;

//Module_import
Module_import:'import'
( '*' 'from' importedNamespace+=[Module_decl|QualifiedName] ';'
|moduleimport1=QualifiedName(',' moduleimport2+=QualifiedName)* ('from' importedNamespace+=[Module_decl|QualifiedName])? ';' )

;

Thanks Again...

Re: Regarding cross-references between different files. [message #1785053 is a reply to message #1785052] Sun, 08 April 2018 16:05 Go to previous messageGo to next message
Eclipse UserFriend
Arrrg you don't use import Uris at alll?????.??

What do you import ?

What is
The two semantics you have in imports

Why are sometimes qualifiednames and sometimes references ?
And what does that Imports mean
I'f you have some own strange semantics you have to implement that own strange spentics
Eg by implementing scoping
Re: Regarding cross-references between different files. [message #1785054 is a reply to message #1785053] Sun, 08 April 2018 16:17 Go to previous messageGo to next message
Eclipse UserFriend
Is you really work with imported namespaces you should use the
Defaultglobalscopeprovider and adapt importednamespaceawarelocalscopeprovider to produce the imports you need
And again the iqualifiednameprovider needes to define the correct names
And there is still the problems with places where you have cross references

Cause imports by name only shorten names, but don't forbid them to be full names (qualified)
But again I don't know anything on your semantics
Re: Regarding cross-references between different files. [message #1785055 is a reply to message #1785053] Sun, 08 April 2018 16:24 Go to previous messageGo to next message
Eclipse UserFriend
Arrrg you don't use import Uris at alll?????.??

-->I have used importURI but still, it didn't work.

What do you import ?

-->I need to import the module name and all the content of that file.

What is
The two semantics you have in imports

-->import * from fileName and other is to import specific element from fileName.

Why are sometimes qualifiednames and sometimes references ?
--> I need to import Module name, classes, interfaces from one file to another file.

Let's make it more clear with the example:

File 1:

module helloWorld;

interface A {
sayhello();
}

class Test implements A{
sayhello(){
print('All good');
}
}

File 2:

module byeWorld;

import * from helloWorld;// include all the content of the File 1

class Test1 implements A{
sayhello(){
print('All IS WELL');
}
}
Re: Regarding cross-references between different files. [message #1785056 is a reply to message #1785055] Sun, 08 April 2018 16:30 Go to previous messageGo to next message
Eclipse UserFriend
But that means you simply have a strange writing for

Import a.b.c.*
For that you can adapt importednamespaceawrelocalscopeprovider
Re: Regarding cross-references between different files. [message #1785058 is a reply to message #1785056] Sun, 08 April 2018 16:56 Go to previous messageGo to next message
Eclipse UserFriend
Hello Christian,

I have made changes accordingly but still, I am not getting the references while importing one file to another as described above.

class MyRuntimeModule extends AbstractMyRuntimeModule {
override bindIGlobalScopeProvider() {
ImportUriGlobalScopeProvider
}

override bindIQualifiedNameProvider() {
SimpleNameProvider
}



override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(
ImportedNamespaceAwareLocalScopeProvider);
}
}


//Module_import
Module_import:'import'
( '*' 'from' importedNamespace=QualifiedName ';'
|moduleimport1=QualifiedName(',' moduleimport2+=QualifiedName)* ('from' importedNamespace=QualifiedName)? ';')
;
Re: Regarding cross-references between different files. [message #1785059 is a reply to message #1785058] Sun, 08 April 2018 16:59 Go to previous messageGo to next message
Eclipse UserFriend
arrrggg

Is is hard to support if you mix up things
Obviously you have namespace imports and qualified names not uri imports and simple names

1 use defaultglobalscopeprovider
2 use defaultdeclarativequalifiednameprovider
3 customize ImportedNamespaceAwareLocalScopeProvider and produce proper imports

[Updated on: Sun, 08 April 2018 17:00] by Moderator

Re: Regarding cross-references between different files. [message #1785570 is a reply to message #1785059] Mon, 16 April 2018 19:28 Go to previous messageGo to next message
Eclipse UserFriend
HI,

I have the grammar
//Module_import
Module_import:'import' (star=MULT 'from' importedNamespace=ANY_IDENTIFIER ';'
|name+=ANY_IDENTIFIER(',' name+=ANY_IDENTIFIER)* 'from' importedNamespace=ANY_IDENTIFIER ';'
|name+=ANY_IDENTIFIER(',' name+=ANY_IDENTIFIER)* ';')

As, you said I have override the following methods in my Run-time module (in org.xtext.XXX package)

override public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return MyQualifiedNameProvider;
}

override bindIGlobalScopeProvider() {
DefaultGlobalScopeProvider
}


override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE)).to(CustomNamespace);
}


where my custom class is.
public class CustomNamespace extends ImportedNamespaceAwareLocalScopeProvider which overrides createImportedNamespaceResolver,getImportedNamespace methods

but I am not sure whether these methods are the ones which I need to override to produce my proper import implementation.

Thanks in advance.
Re: Regarding cross-references between different files. [message #1785574 is a reply to message #1785570] Tue, 17 April 2018 00:44 Go to previous message
Eclipse UserFriend
You should customize internalGetImportedNamespaceResolvers
Previous Topic:What is the best way to make the extension of my language dynamic?
Next Topic:Integration with Xbase - reference to model elements and java-like methodscalls
Goto Forum:
  


Current Time: Sun Jun 15 06:02:03 EDT 2025

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

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

Back to the top