Reference elements from a different file [message #1314637] |
Fri, 25 April 2014 13:57 |
|
Hey,
I', pretty new to xtext and am trying to assemble my first real grammar 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 #1319299 is a reply to message #1315093] |
Mon, 28 April 2014 05:08 |
|
hey, great, that's nearly what i need 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 #1319447 is a reply to message #1319392] |
Mon, 28 April 2014 07:10 |
|
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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03260 seconds