Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Couldn't resolve reference to ...
Couldn't resolve reference to ... [message #1753036] Wed, 01 February 2017 05:13 Go to next message
Eclipse UserFriend
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 05:14] by Moderator

Re: Couldn't resolve reference to ... [message #1753039 is a reply to message #1753036] Wed, 01 February 2017 05:33 Go to previous messageGo to next message
Eclipse UserFriend
https://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/
Re: Couldn't resolve reference to ... [message #1753116 is a reply to message #1753039] Wed, 01 February 2017 21:42 Go to previous messageGo to next message
Eclipse UserFriend
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: Wed, 01 February 2017 22:54] by Moderator

Re: Couldn't resolve reference to ... [message #1753121 is a reply to message #1753116] Wed, 01 February 2017 23:45 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Couldn't resolve reference to ... [message #1753128 is a reply to message #1753121] Thu, 02 February 2017 01:22 Go to previous messageGo to next message
Eclipse UserFriend
QualifiedName qualifiedName(Test e) {
return QualifiedName.create(e.getSName());}
Re: Couldn't resolve reference to ... [message #1753132 is a reply to message #1753128] Thu, 02 February 2017 02:07 Go to previous messageGo to next message
Eclipse UserFriend
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 02:40] by Moderator

Re: Couldn't resolve reference to ... [message #1753148 is a reply to message #1753132] Thu, 02 February 2017 04:06 Go to previous messageGo to next message
Eclipse UserFriend
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 04:20 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Couldn't resolve reference to ... [message #1753163 is a reply to message #1753152] Thu, 02 February 2017 05:54 Go to previous messageGo to next message
Eclipse UserFriend
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 05:55 Go to previous messageGo to next message
Eclipse UserFriend
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 06:25 Go to previous messageGo to next message
Eclipse UserFriend
in eclipse create a project
create you definition model there
use export wizard (rightklick)
Re: Couldn't resolve reference to ... [message #1753187 is a reply to message #1753036] Thu, 02 February 2017 09:41 Go to previous messageGo to next message
Eclipse UserFriend
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 10:15] by Moderator

Re: Couldn't resolve reference to ... [message #1753192 is a reply to message #1753187] Thu, 02 February 2017 10:36 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Couldn't resolve reference to ... [message #1753249 is a reply to message #1753192] Thu, 02 February 2017 21:36 Go to previous messageGo to next message
Eclipse UserFriend
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: Thu, 02 February 2017 22:29] by Moderator

Re: Couldn't resolve reference to ... [message #1753250 is a reply to message #1753249] Thu, 02 February 2017 23:04 Go to previous messageGo to next message
Eclipse UserFriend
What does your code do?
Is your libary inside the runnable jar file?
Re: Couldn't resolve reference to ... [message #1753252 is a reply to message #1753250] Fri, 03 February 2017 01:13 Go to previous message
Eclipse UserFriend
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 Jul 25 01:44:58 EDT 2025

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

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

Back to the top