Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » cross-reference linking and xbase
cross-reference linking and xbase [message #1734949] Tue, 14 June 2016 05:26 Go to next message
Johannes Beichter is currently offline Johannes BeichterFriend
Messages: 5
Registered: November 2011
Junior Member
Hi,

I'm having trouble getting cross-references between two containment
subtrees of my dsl to work with xbase, I get "cannot be resolved" for
the reference "L2a.L3a" in the following example. The scope doesn't seem
to be the problem since "L2a.L3a" is proposed by auto completion.

level1 L1 {
level2a L2a {
level3a L3a
}
level2b L2b {
level3b ref L2a.L3a
}
}

Here's the grammar (with common.Terminals the linking works OOTB):

//grammar org.xtext.example.mydsl.MyDsl with
org.eclipse.xtext.common.Terminals // -> works
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase
// -> ref cannot be resolved

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

Model:
Level1;

Level1:
'level1' name=ID '{'
childrenA+=Level2A*
childrenB+=Level2B*
'}';

Level2A:
'level2a' name=ID '{'
children+=Level3A*
'}';

Level3A:
'level3a' name=ID;

Level2B:
'level2b' name=ID '{'
children+=Level3B*
'}';

Level3B:
'level3b' 'ref' level3a=[Level3A|QualifiedName];

QualifiedName:
(ID '.')* ID;

Thank you for any help on this problem!
Re: cross-reference linking and xbase [message #1734952 is a reply to message #1734949] Tue, 14 June 2016 05:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
first of all your grammar gives this warning

warning(200): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:424:3: Decision can match input such as "RULE_ID '.' RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

xbase solves this by

QualifiedName:
ValidID (=>'.' ValidID)*;

and you should do that as well

then there is another problem when using xbase:

xbase does not allow relative imports.

if you have name a.b.c

and do a import a.*

then b.c is not allowed.

this is caused by

org.eclipse.xtext.xbase.scoping.XImportSectionNamespaceScopeProvider.doCreateImportNormalizer(QualifiedName, boolean, boolean)

see javadoc of AbstractNestedTypeAwareImportNormalizer

so the question is: do you actually need xbase?
do you import java types and non java types as well?

and if so how shall relative imports behave?
do you want realative implicit imports at all?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-reference linking and xbase [message #1734953 is a reply to message #1734952] Tue, 14 June 2016 06:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
you may comment on https://bugs.eclipse.org/bugs/show_bug.cgi?id=495047

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-reference linking and xbase [message #1735029 is a reply to message #1734952] Tue, 14 June 2016 19:10 Go to previous messageGo to next message
Johannes Beichter is currently offline Johannes BeichterFriend
Messages: 5
Registered: November 2011
Junior Member
Thank you very much for all the advice. Content assist made me think
that links were intended to work the way it completes the references,
but as I understand it that's only a bug with content assist.

> so the question is: do you actually need xbase?
> do you import java types and non java types as well?

The answer to the second question is NO, there are no links to Java.

And I would really prefer to get rid of xbase if I don't need it.

So I'll post the problem that made me include xbase into my grammar in
the first place separately. Then maybe someone can help me out with a
more elegant, xbase-free solution for my original problem. Then the
cross-linking should work OOTB. If not I'll follow this path again.

Thanks again.
Re: cross-reference linking and xbase [message #1828901 is a reply to message #1735029] Sun, 21 June 2020 19:18 Go to previous messageGo to next message
Denis Kuniß is currently offline Denis KunißFriend
Messages: 12
Registered: March 2015
Junior Member
Hi all.
I have a similar problem when using Xbase and the default Xbase scope provider.
For the following DSL source which is quite similar like a class hierarchy with fields
package p {
    integration u0
        in i: String
        out o: String
    {
        .i -> u1.o ;
    }
    integration u1
        in o: String
    {}
}

I get a linker error "u1.o cannot be resolved".

When I execute the scope computation explicitly in a test (similar to a suggestion made by Lorenzo Bettini in his Xtext book) I get a list of all aliases which also contains "u1.o"
println(u1_o_ref.getScope(ref).allElements.map[name].join(", "))
// prints "i, o, u0, u0.i, u0.o, u1, u1.o, p.u0, p.u0.i, p.u0.o, p.u1, p.u1.o"


However, if I looking up the qualified name specifically, "u1.o" is not found, but the full qualified name "p.u1.o" is found:
println(u1_o_ref.getScope(ref).getSingleElement(QualifiedName.create("p","u1","o")))
// prints "p.u1.o" -- object description found
println(u1_o_ref.getScope(ref).getSingleElement(QualifiedName.create("u1","o")))
// prints "null" -- not found anything


I have read the issue https://bugs.eclipse.org/bugs/show_bug.cgi?id=495047 but my issue here is not related to proposals.

Nevertheless, it seems somehow related to my issues and Xbase and its scope implementation. Unfortunately, I need Xbase due to Java type references (see the "String" reference).
So, I'm wondering whether there is a a workaround for this issue.
Or, am I doing something wrong?

Regards, Denis
Re: cross-reference linking and xbase [message #1828906 is a reply to message #1828901] Mon, 22 June 2020 05:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
Xbase does scoping based on classes and fields/methods so you seem to do something wrong in your inferrer

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-reference linking and xbase [message #1828907 is a reply to message #1828906] Mon, 22 June 2020 06:16 Go to previous messageGo to next message
Denis Kuniß is currently offline Denis KunißFriend
Messages: 12
Registered: March 2015
Junior Member
Hm.
My inferrer is currently empty, not implemented yet. Scoping too.
I only implemented validator functions.
I mean, at the end my problem is very similar to Johannnes one. But I need Xbase.
Denis
Re: cross-reference linking and xbase [message #1828925 is a reply to message #1828907] Mon, 22 June 2020 13:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
xbase requires you to implement a jvmmodelinferrer. otherwise it wont work

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-reference linking and xbase [message #1828930 is a reply to message #1828925] Mon, 22 June 2020 15:51 Go to previous messageGo to next message
Denis Kuniß is currently offline Denis KunißFriend
Messages: 12
Registered: March 2015
Junior Member
... I know. But, I'm not at this point yet in my implementation.
As I understood, the inferrer is not required for the linking logic, isn't it?
I planned to do the frontend first and then the backend (inferrer).
Re: cross-reference linking and xbase [message #1828936 is a reply to message #1828930] Mon, 22 June 2020 16:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
it is. cause the inferrer defines the context of expressions. e.g. method, status method, field, constructor etc

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: cross-reference linking and xbase [message #1828940 is a reply to message #1828936] Mon, 22 June 2020 16:56 Go to previous messageGo to next message
Denis Kuniß is currently offline Denis KunißFriend
Messages: 12
Registered: March 2015
Junior Member
Understand.
So, I can postpone my problem (FQN are resolved, but relative QN not) until the inferrer is implemented and then it should disappear automatically (when the inferrer is done right)?
Denis
Re: cross-reference linking and xbase [message #1828961 is a reply to message #1828940] Tue, 23 June 2020 09:39 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13641
Registered: July 2009
Senior Member
yes (assuming a.b. is a field/parameter/getter call chain)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How should I write an Xtext rule that refers to itself?
Next Topic:Is it possible to parse a subset of the grammar
Goto Forum:
  


Current Time: Wed Oct 28 06:41:58 GMT 2020

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

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

Back to the top