Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Regarding cross-references between different files.
Regarding cross-references between different files. [message #1785039] Sun, 08 April 2018 14:38 Go to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 14:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding cross-references between different files. [message #1785041 is a reply to message #1785040] Sun, 08 April 2018 15:00 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 15:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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);
	}

}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding cross-references between different files. [message #1785044 is a reply to message #1785043] Sun, 08 April 2018 15:30 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 16:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
AS i said

Bind simplenAmeprovider AS iqualifiednameprovider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding cross-references between different files. [message #1785047 is a reply to message #1785045] Sun, 08 April 2018 17:22 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 19:25 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 20:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding cross-references between different files. [message #1785054 is a reply to message #1785053] Sun, 08 April 2018 20:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding cross-references between different files. [message #1785055 is a reply to message #1785053] Sun, 08 April 2018 20:24 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 20:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
But that means you simply have a strange writing for

Import a.b.c.*
For that you can adapt importednamespaceawrelocalscopeprovider


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Regarding cross-references between different files. [message #1785058 is a reply to message #1785056] Sun, 08 April 2018 20:56 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 20:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 08 April 2018 21:00]

Report message to a moderator

Re: Regarding cross-references between different files. [message #1785570 is a reply to message #1785059] Mon, 16 April 2018 23:28 Go to previous messageGo to next message
Mohd Danish is currently offline Mohd DanishFriend
Messages: 49
Registered: October 2017
Member
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 04:44 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
You should customize internalGetImportedNamespaceResolvers

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
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: Thu Mar 28 18:58:02 GMT 2024

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

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

Back to the top