Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » correct reference problem with import statement and unti-test(No reference between import-statement and calling other files. No reference bewtween files at unit-testing.)
correct reference problem with import statement and unti-test [message #1241881] Sat, 08 February 2014 17:52 Go to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
Hello,

I want to create a dsl with xtext. The new dsl should describe the sequence of tests. With an xml-generator i convert the new dsl to a xml file that a programm can read.
I have a problem with the import-statement and the references. I search two days at the internet, but found no solution for my problem.

Here is my project (simplified):

The Target:
please look into the file at-files.txt (i cannot load the code here)

Explanation:
run and call are key words. With run you can run a test and with call you can call a other test (full test (call AT01) or a test step (call AT01.method1)).

The problem:
When I have the folowing project structure:
/root/files1/AT02.atd
/root/files1/AT01.atd
/root/files2/AT01.atd

The reference in the file AT02.atd are not always correct. Sometimes there are the reference to /root/files2/AT01.atd or sometimes to /root/files1/AT01.atd. There are no check if the import file existes or a reference between the import-statement at the top of the file and the call statement.
I want the exact reference to the file AT01.atd with the import-statment. A nive-to-have is an autocomplete for the import-statement. But I do not know how to Sad .


The implementation:


The Grammar:
please look into the file grammar.xtext (i cannot load the code here)

The workflow (snippet):
I have these lines at the workflow for the import problem

// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
fragment = exporting.QualifiedNamesFragment auto-inject {}
fragment = builder.BuilderIntegrationFragment auto-inject {}


Unit-testing with import-references:
My second problem is the import-references at the unit-testing.
introduction: I want to test the xml-generator. So I create in the package *.tests a file GeneratorTest.xtend. In a other package *.files I have the files AT01.atd and AT02.atd (from above) and the correct xml-files (self-written) to these atd-files.
My Attempt: I read in the GeneratorTest.xtend the files AT01.atd and AT02.atd. Then I call the generator and I have in the package *.files.gen the new xml-files). Then I want to compare the self-written xml-files and the generated xml-files.
The Problem: There are no references between the files.

please look into the file unitTest.xtend (i cannot load the code here)

The Problem: the res is null.
How can I test correct my xml-generator (compare self written xml file with generated xml file).
Re: correct reference problem with import statement and unti-test [message #1242858 is a reply to message #1241881] Mon, 10 February 2014 07:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

you are the guy who has to load all relevant files into the resource set yourself, not only one.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1242950 is a reply to message #1242858] Mon, 10 February 2014 10:00 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
Christian I do not understand. What exactly do you mean? Which resource set do you mean?
Re: correct reference problem with import statement and unti-test [message #1242959 is a reply to message #1242950] Mon, 10 February 2014 10:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
the one in the test????

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1242985 is a reply to message #1242959] Mon, 10 February 2014 10:57 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
I still do not understand Sad
Do you mean this line : "val resource = resourceSet.getResource(fileURI, true);" ?
For every file I call the method doGenerate(...) and then for every file I make a "new ResourceSetImpl();". So I do not load all files into the same resource set.
With the ResourceSetImpl I want only to get the Resource of the file.
But why it is wrong to load more files into a resouce set? A resource set is a "collection of resources" or am I wrong?
How could I fix it in your opinion?
Re: correct reference problem with import statement and unti-test [message #1242988 is a reply to message #1242985] Mon, 10 February 2014 11:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes


you have to do

val resource1 = resourceSet.getResource(fileURI1, true);"
val resource2 = resourceSet.getResource(fileURI2, true);"
val resource3 = resourceSet.getResource(fileURI3, true);"


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1242989 is a reply to message #1242988] Mon, 10 February 2014 11:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
and it is not wrong. you have todo it but you dont do it!
if you would do it you would not have unresolved reference problems


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1243148 is a reply to message #1242989] Mon, 10 February 2014 15:33 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
Ah clear. Great, thank you. It works. Sorry I was confused.
Do you know the solution of my first problem too (Not in the unit test)? With the correct import-statement so i can call the right file (when i have two with the same name in a folder tree). Thus i have no reference between import-statement (import files1.AT01) and call-statement (call AT01)?
Re: correct reference problem with import statement and unti-test [message #1243157 is a reply to message #1243148] Mon, 10 February 2014 15:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Did you try to switch to import uri based scoping?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1243597 is a reply to message #1243157] Tue, 11 February 2014 07:22 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
Did you mean write this line in the workflow: "fragment = scoping.ImportURIScopingFragment auto-inject {}" ? This do not work. And I try in the grammar "'import' importURI=STRING;" but this do not work, too.
Re: correct reference problem with import statement and unti-test [message #1243635 is a reply to message #1243597] Tue, 11 February 2014 08:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Make sure you remove xbase and types generator and importednamespace
fragments

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1243653 is a reply to message #1243635] Tue, 11 February 2014 09:02 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
Here are my actual workflow. When I remove the line "fragment = types.TypesGeneratorFragment auto-inject {}" there are no references and errors at my dsl.
Re: correct reference problem with import statement and unti-test [message #1243711 is a reply to message #1243653] Tue, 11 February 2014 10:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

do you use xbase in your dsl?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1243747 is a reply to message #1243711] Tue, 11 February 2014 11:39 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
No I use only the super grammar org.eclipse.xtext.common.Terminals.
Re: correct reference problem with import statement and unti-test [message #1243754 is a reply to message #1243747] Tue, 11 February 2014 11:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Then I do not understand that. What is the symptoms exactly you get?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1243770 is a reply to message #1243754] Tue, 11 February 2014 12:18 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
In my dsl I have this folder structure:

ProjectFolder/
|-- src/
|-- packA.packB/
|-- AT01.atd
|-- AT02.atd
|-- packA.packB/
|-- AT02.atd
|-- src-gen/

AT01.atd look like this:

---
import packA.packB.AT02
test AT01 {
call AT02 //(here is a link to packA.packC.AT02 and not to packA.packB.AT02!)
}
---

So when I click on AT02 and press F3 I go to packA.packC.AT02 and that it not what I expect/want (my grammar is at the first post). So I have no reference between my import-statement and my call-statement (I can also let off statement). And I do not find any solution on the internet (I try) that works.
Re: correct reference problem with import statement and unti-test [message #1243775 is a reply to message #1243770] Tue, 11 February 2014 12:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i get more and more confused.

do you want to import packages or do you want to import uris

if packages: are they explicitely declared or derived from the folder.
if they are derived from the folder did you customize the nameprovider for your root object
to give its package name as name


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1243842 is a reply to message #1243775] Tue, 11 February 2014 14:25 Go to previous messageGo to next message
Marcel Lgs is currently offline Marcel LgsFriend
Messages: 9
Registered: February 2014
Junior Member
Sorry. It should actually ony folders (but with packages it should work too, but it do not):

ProjectFolder/src/folderA/folderB/AT01.atd
ProjectFolder/src/folderA/folderB/AT02.atd
ProjectFolder/src/folderA/folderC/AT02.atd

The import should work like java. With the statement "import folderA.folderB.AT02" I want to call the file AT02.atd in the folder ProjectFolder/src/folderA/folderB/
I try to add a package declaration to the grammar but without success.
Re: correct reference problem with import statement and unti-test [message #1243855 is a reply to message #1243842] Tue, 11 February 2014 14:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

i have no access to your grammar.
so do you have packagesa there or not?

ifyou have only folders you have to adaot the nameprovider and calculent the package from the roots eResource URI


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: correct reference problem with import statement and unti-test [message #1244562 is a reply to message #1243770] Wed, 12 February 2014 14:22 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
It sounds like the qualified name provider use the simple name, and
doesn't include the package.

You need to either have a special implementation of
IQualifiedNameProvider (and bind it via your guice module) or you change
your grammar such that the
test element are contained in something with a name, which denotes the
package.

i.e.

File :
'package' name=QualifiedName

tests += Test*

;

Test :
'test' name=ID ...

;

hope that helps,
Sven


Am 11/02/14 13:18, schrieb Marcel Lgs:
> In my dsl I have this folder structure:
>
> ProjectFolder/
> |-- src/
> |-- packA.packB/
> |-- AT01.atd
> |-- AT02.atd
> |-- packA.packB/
> |-- AT02.atd
> |-- src-gen/
>
> AT01.atd look like this:
>
> ---
> import packA.packB.AT02
> test AT01 {
> call AT02 //(here is a link to packA.packC.AT02 and not to
> packA.packB.AT02!)
> }
> ---
>
> So when I click on AT02 and press F3 I go to packA.packC.AT02 and that
> it not what I expect/want (my grammar is at the first post). So I have
> no reference between my import-statement and my call-statement (I can
> also let off statement). And I do not find any solution on the internet
> (I try) that works.


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Previous Topic:Generated ecore models refer to Xbase using relative paths
Next Topic:[Solved] DocumentTokenSource Injection
Goto Forum:
  


Current Time: Thu Mar 28 09:55:52 GMT 2024

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

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

Back to the top