Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Couldn't resolve reference to ...
Couldn't resolve reference to ... [message #1753036] Wed, 01 February 2017 10:13 Go to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
I have this grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=(Greeting| Test)*;
	
Greeting:
	'Hello' test=[Test] 'age' age=INT '!';
Test:
	'Bye' sName=ID '!' 'see' 'you' date=ID ';'
;



But I get an error with this configuration:
Hello sample age 2!
Bye sample ! see you  sept;


The error is:
Description Resource Path Location Type
Couldn't resolve reference to Test 'sample'. test.mydsl /sample line: 1 /sample/test.mydsl MyDsl Problem

I need to use the variable sName, any hints how to configure xtext to accept sName instead of name?

[Updated on: Wed, 01 February 2017 10:14]

Report message to a moderator

Re: Couldn't resolve reference to ... [message #1753039 is a reply to message #1753036] Wed, 01 February 2017 10:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
https://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to ... [message #1753116 is a reply to message #1753039] Thu, 02 February 2017 02:42 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hi Christian,
I am still getting the same error.

package org.xtext.example.mydsl;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.xtext.example.mydsl.myDsl.Greeting;
import org.xtext.example.mydsl.myDsl.Test;

public class MyDslQNP extends DefaultDeclarativeQualifiedNameProvider {
	QualifiedName qualifiedName(Greeting e) {
        Test p = (Test) e.eContainer();
        return QualifiedName.create(p.getSName(), e.getSample().getSName());
    }
}


My xtext is this:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	greetings+=(Greeting| Test)*;
	
Greeting:
	'Hello' sample=[Test] 'age' age=INT '!';
Test:
	'Bye' sName=ID '!' 'see' 'you' date=ID ';'
;



I have also modified the Runtime Module.
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	override Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
        return MyDslQNP;
       }
}



And I have added the scopeProvider in my mwe workflow.
scopeProvider = scoping.ImportNamespacesScopingFragment2 {
				
			}


Am I missing something?

[Updated on: Thu, 02 February 2017 03:54]

Report message to a moderator

Re: Couldn't resolve reference to ... [message #1753121 is a reply to message #1753116] Thu, 02 February 2017 04:45 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Hi Chris,

The following code should work for you

       @Override
	protected QualifiedName qualifiedName(Object obj) {
		if (obj instanceof Test) {
			final Test test = (Test) obj;
			return QualifiedName.create(test.getSName()); 
		}
		return super.qualifiedName(obj);
	}


Tx


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Re: Couldn't resolve reference to ... [message #1753128 is a reply to message #1753121] Thu, 02 February 2017 06:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
QualifiedName qualifiedName(Test e) {
return QualifiedName.create(e.getSName());}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to ... [message #1753132 is a reply to message #1753128] Thu, 02 February 2017 07:07 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Thanks, it works perfectly now. But I am encountering some problem.

There are some entries that are added only during generator part as the user does not need to specify it.

Hello admin age 99!
Hello sample age 2!
Bye sample ! see you  sept;


I manually add the "admin" during generator part by default. However, this gives me an error "Couldn't resolve reference to Test 'admin'". How can I make xtext aware that admin is a valid reference? Is there a way to add it before the references are checked?

[Updated on: Thu, 02 February 2017 07:40]

Report message to a moderator

Re: Couldn't resolve reference to ... [message #1753148 is a reply to message #1753132] Thu, 02 February 2017 09:06 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hmm.. should this be added under scoping?
Re: Couldn't resolve reference to ... [message #1753152 is a reply to message #1753148] Thu, 02 February 2017 09:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
there are multiple options that depend on your scenario

- pack the admin definition and put it as jar to the classpath (if the model project is a java project)
- adapt e.g. global scope provder and add the libary defintions there

(both options have up and downsides and if possible/feasible id go the first way


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to ... [message #1753163 is a reply to message #1753152] Thu, 02 February 2017 10:54 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hi Christian,
Can you give me any hints on how to go on adapting the global scope provider and add the library definitions? what are the downsides in this approach?
Re: Couldn't resolve reference to ... [message #1753164 is a reply to message #1753163] Thu, 02 February 2017 10:55 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
How to pack the definition as a jar? I am not very familiar on how to do this. A link to an example will be very helpful.
Re: Couldn't resolve reference to ... [message #1753167 is a reply to message #1753164] Thu, 02 February 2017 11:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
in eclipse create a project
create you definition model there
use export wizard (rightklick)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to ... [message #1753187 is a reply to message #1753036] Thu, 02 February 2017 14:41 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
It works now! I had encountered another error though.

I have to different files:
File 1 is in d:\test\sample\a\trial1
It contains this:
Hello sample age 2!


File 2 is in d:\test\sample\b\trial2
Bye sample! See you sept;


I am getting an error because the sample reference couldn't be resolved.
Do I need to set something in my myDslQNP class? I followed the qualifiedname method that neeraj has given as I have more than one grammar to cross-reference.

[Updated on: Thu, 02 February 2017 15:15]

Report message to a moderator

Re: Couldn't resolve reference to ... [message #1753192 is a reply to message #1753187] Thu, 02 February 2017 15:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i assumed you to my qnp.
this should work fine
make sure
- build automatically i on
- project has xtext nature
- file extension is case sensitive correct


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to ... [message #1753249 is a reply to message #1753192] Fri, 03 February 2017 02:36 Go to previous messageGo to next message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hi Christian,
I am using a Runnable JAR file to read the files. I export it as Runnable JAR and copy required libraries to subfolder next to the generated JAR. I run it as:
java -jar test.jar ..\a\trial1\test1.mydsl ..\b\trial2\test2.mydsl

How can I make it "wait" for all files to be processed before checking for the cross-references? I have no problem if I am running an Eclipse application and do the configurations there with the steps you mentioned.

[Updated on: Fri, 03 February 2017 03:29]

Report message to a moderator

Re: Couldn't resolve reference to ... [message #1753250 is a reply to message #1753249] Fri, 03 February 2017 04:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
What does your code do?
Is your libary inside the runnable jar file?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Couldn't resolve reference to ... [message #1753252 is a reply to message #1753250] Fri, 03 February 2017 06:13 Go to previous message
chris yo is currently offline chris yoFriend
Messages: 146
Registered: February 2013
Senior Member
Hi Christian, I managed to make it work. I changed main.java to load all resources first, before calling validate.

Thank you for your help!
Previous Topic:Xtext web services validate
Next Topic:Remove unused import warning
Goto Forum:
  


Current Time: Fri Apr 19 21:02:46 GMT 2024

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

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

Back to the top