Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Reference elements from a different file
Reference elements from a different file [message #1314637] Fri, 25 April 2014 09:57 Go to next message
Markus Duft is currently offline Markus Duft
Messages: 91
Registered: February 2013
Member
Hey,

I', pretty new to xtext and am trying to assemble my first real grammar Smile so please excuse noobish questions, but i was unable to find a solution.

i have files like this:

package common;

type MyType : String {
  property label "MyLabel";
}


and in a separate file:

package common;

structure MyStruct {
  attribute myAttr : MyType;
  attribute myFqnAttr : common.MyType;
}


Now i have a slight scoping problem. I made it that the second attribute works (qualified name used), however i have troubles getting the short version to run.

I have no real clue on how to do it, really. I have tried to delegate the scope calculation for the type reference to the top-level container, for which i calculate a qualified name equal to the package (so all file containing "package common;" have the same qualified name "common" (bad idea?)). Now if i delegate the scope calculation i get a scope that will contain all elements from the current file, but not from the first one, defining the actually requested element.

How the heck am i able to do something like this?? I found a 2009'ish blog about the "index", however none of the API seems to exist anymore...

(if that is of interest: the only actual modification to the pre-generated files, apart from my tries to get this to work is that qualified name calculation for top-level elements in each file. the qualified name for MyType will be prefixed by the package name of it's container (thus common.MyType now works)).

Thankful for any comment!

Thanks in advance, Markus
Re: Reference elements from a different file [message #1314675 is a reply to message #1314637] Fri, 25 April 2014 10:30 Go to previous messageGo to next message
Markus Duft is currently offline Markus Duft
Messages: 91
Registered: February 2013
Member
maybe to be more clear:

i want it to behave as if i have an 'importNamespace' rule that imports exactly the elements that i'm missing... when i add such a rule and import the things that are unresolved everything is working...
Re: Reference elements from a different file [message #1315093 is a reply to message #1314675] Fri, 25 April 2014 15:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6214
Registered: July 2009
Senior Member
do you mean implicit imports? org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getImplicitImports(boolean)
Re: Reference elements from a different file [message #1319299 is a reply to message #1315093] Mon, 28 April 2014 01:08 Go to previous messageGo to next message
Markus Duft is currently offline Markus Duft
Messages: 91
Registered: February 2013
Member
hey, great, that's nearly what i need Smile just need to know now for which model element i'm calculating imprlicit imports now, is this possible? (i.e. i have the "package" declarative at the top of the file and want to implicitly import from that package.

Thanks a ton!
Re: Reference elements from a different file [message #1319392 is a reply to message #1319299] Mon, 28 April 2014 02:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6214
Registered: July 2009
Senior Member
hi,
that is rather a explicit import => change org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider.getImportedNamespace(EObject)
Re: Reference elements from a different file [message #1319447 is a reply to message #1319392] Mon, 28 April 2014 03:10 Go to previous messageGo to next message
Markus Duft is currently offline Markus Duft
Messages: 91
Registered: February 2013
Member
thanks a lot, i changed my scope provider to this, and it works like a charm!

class WDLScopeProvider extends ImportedNamespaceAwareLocalScopeProvider {

        override protected getImportedNamespace(EObject object) {
                if (object instanceof Package) {
                        (object as Package).name + ".*"
                } else {
                        super.getImportedNamespace(object)
                }
        }
}


btw. i tried something like "switch(object) { case Package: object.name + ".*" }" but it did not match the type somehow (debugger says PackageImpl vs. Class<Package> IIRC)? also the switch does not seem to cast object to Package for the case block... am i missing something?
Re: Reference elements from a different file [message #1319454 is a reply to message #1319447] Mon, 28 April 2014 03:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6214
Registered: July 2009
Senior Member
hi, xtend type guard work differently:
http://www.eclipse.org/xtend/documentation.html#switchExpression
Re: Reference elements from a different file [message #1319744 is a reply to message #1319454] Mon, 28 April 2014 07:05 Go to previous message
Markus Duft is currently offline Markus Duft
Messages: 91
Registered: February 2013
Member
ah, thanks - too many 'case' i guess Smile
Previous Topic:Horstmann style formatter
Next Topic:Read my DSL model "as a whole"
Goto Forum:
  


Current Time: Sat Aug 23 15:53:32 EDT 2014

Powered by FUDForum. Page generated in 0.06373 seconds