Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » failed to reference element from jar in the classpath(cross reference from an external jar in the classpath)
failed to reference element from jar in the classpath [message #1769029] Wed, 26 July 2017 01:12 Go to next message
paul lu is currently offline paul luFriend
Messages: 34
Registered: April 2013
Member
Hi,

Below is a simple grammar:
Model:
(greetings+=Element)*;

Element:
Decl | Greeting
;
Decl:
'name' ':' name=ID
;
Greeting:
'Hello' nameRef=[Decl] '!';

Then I defined lib.mydsl inside a maven java project with the content:
name : Paul

and mvn packaged the java project so I got the jar:
$ jar tf ./target/my-app-1.0-SNAPSHOT.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/mycompany/
com/mycompany/app/
com/mycompany/app/App.class
lib.mydsl
...

Note lib.mydsl is packaged inside the jar.

Then I added the jar to another java project's classpath (using eclipse Java Build Path -> Add JARS)
Then the cross reference is not resolved in my project using the previous jar:
Hello Paul ! //could not resolve reference to Decl Paul

I read something saying this should work out of the box, is there anything to customize, for example, in the global scope provider ?

Thanks !
Re: failed to reference element from jar in the classpath [message #1769035 is a reply to message #1769029] Wed, 26 July 2017 04:02 Go to previous messageGo to next message
paul lu is currently offline paul luFriend
Messages: 34
Registered: April 2013
Member
I got it working after I added an import section:
Import:
'import' importURI=STRING
;
Replace DefaultGlobalScopeProvider with ImportUriGlobalScopeProvider.

And change the dsl code to:
import "classpath:/lib.mydsl"
Hello Paul !

But then the functions in DefaultGlobalScopeProvider is missing. I guess maybe it's better to add ImportUriGlobalScopeProvider to the current scope provider (by creating a custom global scope provider)

Re: failed to reference element from jar in the classpath [message #1769036 is a reply to message #1769035] Wed, 26 July 2017 04:05 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11388
Registered: July 2009
Senior Member
Could be https://bugs.eclipse.org/bugs/show_bug.cgi?id=519528
But you would,have to debug. That

And it was reported for xbase langs only


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: failed to reference element from jar in the classpath [message #1769051 is a reply to message #1769036] Wed, 26 July 2017 05:50 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11388
Registered: July 2009
Senior Member
Hi,

i just gave it a try and it seemed to work for me.


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: failed to reference element from jar in the classpath [message #1769055 is a reply to message #1769036] Wed, 26 July 2017 06:17 Go to previous messageGo to next message
paul lu is currently offline paul luFriend
Messages: 34
Registered: April 2013
Member
Oh, I forgot I used xtext 2.10, I tried my example on xtext 2.11, it does work without adding importURI support.
Thanks ~
Re: failed to reference element from jar in the classpath [message #1769057 is a reply to message #1769055] Wed, 26 July 2017 06:22 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11388
Registered: July 2009
Senior Member
yes there were some bugs fixed around this recently

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: failed to reference element from jar in the classpath [message #1769062 is a reply to message #1769057] Wed, 26 July 2017 06:48 Go to previous messageGo to next message
paul lu is currently offline paul luFriend
Messages: 34
Registered: April 2013
Member
Hi,

I tried the same steps for xbase, and found a problem. Below is the grammar:

grammar org.xtext.example.mydsl.MyDsl with
                                      org.eclipse.xtext.xbase.Xbase
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=Element*;

Element: 
    Decl | Greeting
;
Decl: 
    name=ID ':' type=JvmTypeReference
;

Greeting:
	'Hello' name=[Decl] '!';



I defined a "Decl" in lib.mydsl and packaged it into a jar:
Paul: String

and the reference below does not work:
Hello Paul !

But this reference resolves to the "Decl" in lib.mydsl:
Hello name !

Please also see the attached screenshot.
Re: failed to reference element from jar in the classpath [message #1769064 is a reply to message #1769062] Wed, 26 July 2017 06:58 Go to previous message
paul lu is currently offline paul luFriend
Messages: 34
Registered: April 2013
Member
Oh, never mind, it works, I have forgotten to regenerate the code.
Sorry

Maybe some uncleaned state produced from the previous version of the grammar I created.

[Updated on: Wed, 26 July 2017 07:03]

Report message to a moderator

Previous Topic:Handling semantic whitespace: forcefully avoiding it
Next Topic:Collection of open source grammars
Goto Forum:
  


Current Time: Thu Nov 23 15:17:26 GMT 2017

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

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