Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext and scopes
Xtext and scopes [message #895574] Fri, 13 July 2012 11:38 Go to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Hello,

I've tried for the fifth time to wrap my brain about the explanation of scopes in the documentation (http://www.eclipse.org/Xtext/documentation.html#scoping). I know a little bit about Java and parsers (proof: I have 80K points on stackoverflow.com)

But I just don't get it and that made me wonder why not? So here is my view/feelings/thoughts about the current state of the documentation.

I think the problem lies not in the amount and depth of the documentation. When I read the documentation then I learn a lot about scopes and IScopeProviders and a dozen other related types.

But I don't understand how I could achieve some desired goal. Let's look at the beginning:

Quote:
A single IScope (src) represents an element of a linked list of scopes. That means that a scope can be nested within an outer scope. Each scope works like a symbol table or a map where the keys are strings and the values are so called IEObjectDescription (src), which is effectively an abstract description of a real EObject (src).


That's good to know but it doesn't answer any of my questions:

How do I create an IEObjectDescription?

In the paragraph above this one, you mention "target candidates". What's that? Is that related to IEObjectDescription in some way? How?

Actually, I don't care that much about scopes. My question is usually "I have property 'x' in type Foo and have some filter that tells me which instances of my model are allowed as value for 'x'. How does that translate into Xtext code?

You see, the documentation explains a lot of details but I'm missing code examples which explains the two most common cases:

1. Supply a list of possible values for a property
2. Take an existing scope and reduce the values by applying a filter

Instead of focusing on the theoretical background, start with some simple examples and build on that. UML diagrams are nice to see how types are related but they don't explain how to use them.

Code that I'd like to see:

1. How do I find all instances of a certain type in a resource/resource set? (= how do I get all the possible values)
2. How do I filter this list, for example, to remove the node for which I create the list?
3. How do I turn this list into an IScope?
4. How do I configure Xtext to use this new scope?

I'm sure most of these questions are very simple to answer for someone who knows Xtext but I only have "ERROR:Couldn't resolve reference to Foo 'base'" and Xtext refuses to tell me where it looked for "base".

Regards,

A. Digulla
Re: Xtext and scopes [message #895591 is a reply to message #895574] Fri, 13 July 2012 13:22 Go to previous messageGo to next message
Cristiano Gaviao is currently offline Cristiano Gaviao
Messages: 253
Registered: July 2009
Senior Member
Hi,

I had to agree with you, the docs are very simpler for this so important concepts and definitively lacks good examples and references.
I had to dig the web for days to get more details and of course lot of help here.

I recommend you to take a look at the org.eclipse.xtext.example.arithmetics, specifically at this class: org.eclipse.xtext.example.arithmetics.scoping.ArithmeticsScopeProvider

there is an example on how to filter the contents of a scope.

Here there are some useful links about scope that could help you too:
http://blogs.itemis.de/stundzig/archives/773
http://www.eclipse.org/forums/index.php/mv/tree/367348/895077/#msg_895077
http://www.eclipse.org/forums/index.php/mv/tree/367426/895423/#msg_895423

regards,

Cristiano
Re: Xtext and scopes [message #895594 is a reply to message #895574] Fri, 13 July 2012 13:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6205
Registered: July 2009
Senior Member
Hi,

theoretical stuff is hard to explain. so why dont you come up with a
concrete example.

the basic pain point is the kind of filtering you want to do,
and the creteria you want to use.
this influences the solution a lot.
never the less having a look at the class

org.eclipse.xtext.scoping.Scopes

and considering this simple statement might help

return new FilteringScope(delegateGetScope(context, ref), new
Predicate<IEObjectDescription>() {

@Override
public boolean apply(IEObjectDescription input) {
return true;
}
});

Depending on the kind of information you need to filter
ImportedNamespaceAwareLocalScopeProvider
and
DefaultResourceDescriptionStrategy
might have to be changes too.

but this depends on how your dsls work
(specially regarding global visibility)

~Christian


On 2012-07-13 15:38:22 +0000, Aaron Digulla said:

> Hello,
>
> I've tried for the fifth time to wrap my brain about the explanation of
> scopes in the documentation
> (http://www.eclipse.org/Xtext/documentation.html#scoping). I know a
> little bit about Java and parsers (proof: I have 80K points on
> stackoverflow.com)
>
> But I just don't get it and that made me wonder why not? So here is my
> view/feelings/thoughts about the current state of the documentation.
>
> I think the problem lies not in the amount and depth of the
> documentation. When I read the documentation then I learn a lot about
> scopes and IScopeProviders and a dozen other related types.
>
> But I don't understand how I could achieve some desired goal. Let's
> look at the beginning:
>
> Quote:
>> A single IScope (src) represents an element of a linked list of scopes.
>> That means that a scope can be nested within an outer scope. Each scope
>> works like a symbol table or a map where the keys are strings and the
>> values are so called IEObjectDescription (src), which is effectively an
>> abstract description of a real EObject (src).
>
>
> That's good to know but it doesn't answer any of my questions:
>
> How do I create an IEObjectDescription?
>
> In the paragraph above this one, you mention "target candidates".
> What's that? Is that related to IEObjectDescription in some way? How?
>
> Actually, I don't care that much about scopes. My question is usually
> "I have property 'x' in type Foo and have some filter that tells me
> which instances of my model are allowed as value for 'x'. How does that
> translate into Xtext code?
>
> You see, the documentation explains a lot of details but I'm missing
> code examples which explains the two most common cases:
>
> 1. Supply a list of possible values for a property
> 2. Take an existing scope and reduce the values by applying a filter
>
> Instead of focusing on the theoretical background, start with some
> simple examples and build on that. UML diagrams are nice to see how
> types are related but they don't explain how to use them.
>
> Code that I'd like to see:
>
> 1. How do I find all instances of a certain type in a resource/resource
> set? (= how do I get all the possible values)
> 2. How do I filter this list, for example, to remove the node for which
> I create the list?
> 3. How do I turn this list into an IScope?
> 4. How do I configure Xtext to use this new scope?
>
> I'm sure most of these questions are very simple to answer for someone
> who knows Xtext but I only have "ERROR:Couldn't resolve reference to
> Foo 'base'" and Xtext refuses to tell me where it looked for "base".
>
> Regards,
>
> A. Digulla


--
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
Re: Xtext and scopes [message #895855 is a reply to message #895574] Mon, 16 July 2012 06:29 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

thanks for your feedback. I extracted some parts of it into
https://bugs.eclipse.org/bugs/show_bug.cgi?id=385159

Regarding your questions 1 to 4:

1) delegateGetScope will take care of that since "all compatible
elements" is the default content of the scope. You should stop thinking
in terms of resource and especially resource set. It's more about
containers, project setup and the like that influences the scope.
2) You should not remove that from the scope but use custom validation
and custom content assist instead. This improves the feedback for the
user while still allowing to navigate to the erroneous element.
3) Did you try to visualize the type hierarchy of IScope. There is
MapBasedScope, MultimapBasedScope and SimpleScope. All of them are
documented. You'll usually find a #create(..) method that allows to
instantiate a scope.
4) The scope provider stub is already bound in the runtime module thus
Xtext already uses that one. If you implement the right method (see the
docs), it will be invoked.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 13.07.12 17:38, schrieb Aaron Digulla:
> Hello,
>
> I've tried for the fifth time to wrap my brain about the explanation of
> scopes in the documentation
> (http://www.eclipse.org/Xtext/documentation.html#scoping). I know a
> little bit about Java and parsers (proof: I have 80K points on
> stackoverflow.com)
>
> But I just don't get it and that made me wonder why not? So here is my
> view/feelings/thoughts about the current state of the documentation.
>
> I think the problem lies not in the amount and depth of the
> documentation. When I read the documentation then I learn a lot about
> scopes and IScopeProviders and a dozen other related types.
>
> But I don't understand how I could achieve some desired goal. Let's look
> at the beginning:
>
> Quote:
>> A single IScope (src) represents an element of a linked list of
>> scopes. That means that a scope can be nested within an outer scope.
>> Each scope works like a symbol table or a map where the keys are
>> strings and the values are so called IEObjectDescription (src), which
>> is effectively an abstract description of a real EObject (src).
>
>
> That's good to know but it doesn't answer any of my questions:
>
> How do I create an IEObjectDescription?
>
> In the paragraph above this one, you mention "target candidates". What's
> that? Is that related to IEObjectDescription in some way? How?
>
> Actually, I don't care that much about scopes. My question is usually "I
> have property 'x' in type Foo and have some filter that tells me which
> instances of my model are allowed as value for 'x'. How does that
> translate into Xtext code?
>
> You see, the documentation explains a lot of details but I'm missing
> code examples which explains the two most common cases:
>
> 1. Supply a list of possible values for a property
> 2. Take an existing scope and reduce the values by applying a filter
>
> Instead of focusing on the theoretical background, start with some
> simple examples and build on that. UML diagrams are nice to see how
> types are related but they don't explain how to use them.
>
> Code that I'd like to see:
>
> 1. How do I find all instances of a certain type in a resource/resource
> set? (= how do I get all the possible values)
> 2. How do I filter this list, for example, to remove the node for which
> I create the list?
> 3. How do I turn this list into an IScope?
> 4. How do I configure Xtext to use this new scope?
>
> I'm sure most of these questions are very simple to answer for someone
> who knows Xtext but I only have "ERROR:Couldn't resolve reference to Foo
> 'base'" and Xtext refuses to tell me where it looked for "base".
>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #896513 is a reply to message #895594] Wed, 18 July 2012 11:40 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Christian Dietrich wrote on Fri, 13 July 2012 19:26
Hi,
theoretical stuff is hard to explain. so why dont you come up with a
concrete example.


Ok. I get this error: "ERROR:Couldn't resolve reference to library 'base'. (test.mset line : 2)"

How do I find out what causes this error? Is there a way to see all active scopes when such an error happens?

Christian Dietrich wrote on Fri, 13 July 2012 19:26

never the less having a look at the class

org.eclipse.xtext.scoping.Scopes


This class looks very useful and it's mentioned in the Xtext docs 0 times. Can you please change this?

Christian Dietrich wrote on Fri, 13 July 2012 19:26

and considering this simple statement might help

return new FilteringScope(delegateGetScope(context, ref), new 
Predicate<IEObjectDescription>() {
			
			@Override
			public boolean apply(IEObjectDescription input) {
				return true;
			}
		});


What does delegateGetScope() do? There no documentation for it.

Christian Dietrich wrote on Fri, 13 July 2012 19:26

Depending on the kind of information you need to filter
ImportedNamespaceAwareLocalScopeProvider
and
DefaultResourceDescriptionStrategy
might have to be changes too.


I checked the docs for ImportedNamespaceAwareLocalScopeProvider; at first it doesn't seem to apply because the docs say "It adds namespace support to your language, which is comparable and similar to the one in Scala and C#."

I'm not using name spaces and I don't know Scala or C# well enough to understand what the reference means. But looking further, it seems the provider can also be used to implement Java-style "import" statements but I couldn't find any explanation for that.

Maybe the documentation there is too dense:

Quote:
The imported namespace aware scoping is based on qualified names and namespaces. It adds namespace support to your language, which is comparable and similar to the one in Scala and C#. Scala and C# both allow to have multiple nested packages within one file and you can put imports per namespace, so that imported names are only visible within that namespace. See the domain model example: its scope provider extends ImportedNamespaceAwareLocalScopeProvider (src).


Next, the docs mention that you can override how the qualified name is built. Only after this example, it goes on to say that you can use this for Java's "import" but there is no code example what exactly you need to make this work.

My criticism here is that there in no clear path that the documentation follows. It mentions a lot of things but there is no strategy to help readers get the big picture or help them to solve specific problems. All it says "this can be done" but it doesn't say how.

The domain model example is similar. It contains two very simple parser test cases, 2 code generator tests (one fails) and 440 Xbase tests. What I'm missing:

# Tests for validation rules
# Tests for formatting
# Some explanations what the different formatting rules try to achieve
# Is there a web site which explains the different features of the domain model step by step? For example, DomainmodelJvmModelInferrer looks very interesting but what does it do?
# Tests for more complex domain models
# There is no code generator in the example; How does the domain model generate its code? If I didn't have the Xtext sources installed, then the reference to CompilationTestHelper would be useless.
# The code coverage by the domain model tests is 64% for the base plug-in (but only 30% of the non-generated code is covered) and 0% for the UI code.

I think this is cause by you being inside the problem. The people working on the scope documentation have been developing Xtext for 2-3 years, now. They don't see anymore what newcomers don't know.

Writing better documentation is something that interests me but I'm under some stress right now, so I can't offer my help except by giving you input Sad

Regards,

A. Digulla
Re: Xtext and scopes [message #896527 is a reply to message #896513] Wed, 18 July 2012 12:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6205
Registered: July 2009
Senior Member
Since I am not an Xtext committer I cannot change the situation
besides answering (specific) questions and doing some blogging here
and then. If you find docs insufficient please file a bug or
enhancement request. If you have any specific examples/problems do
not hesitate to ask

Regards Christian

--
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
Re: Xtext and scopes [message #896638 is a reply to message #896513] Thu, 19 July 2012 04:40 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

thanks again for your feedback. Such recommendations would be very
helpful if they were added to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=385159

One major thing that you have to keep in mind is that the documentation
is not meant to be a cook book but a reference documentation. It is
simply not possible for use (resource-wise) to document even the more
common use cases by means of detailled examples. What we try to achieve
is that the concepts are described rather than implementation details
and how-to. I know that we still scratch only the surface conceptually,
too ...

Therefore you have to keep in mind that code archeology is and will
always be helpful - and that does not depend on the framework that you
use but holds for basically any library. E.g. the class Scopes is in the
very same package as the interface IScope. If you want to learn about
that one, browse the Javadocs. We usually use the plural form to denote
utility classes. If you use Xtext, you'll get used to that convention.

Regarding the suggestion to improve the tests for the domainmodel:
Please keep in mind that it is an example and meant to be easy to
understand. Having much more tests to get some artififial covering of
9x% or something is not our goal and out of scope.

Nevertheless, your feedback is highly appreciated. I attached some of
your suggestions to the bug.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 18.07.12 17:40, schrieb Aaron Digulla:
> Christian Dietrich wrote on Fri, 13 July 2012 19:26
>> Hi,
>> theoretical stuff is hard to explain. so why dont you come up with a
>> concrete example.
>
>
> Ok. I get this error: "ERROR:Couldn't resolve reference to library
> 'base'. (test.mset line : 2)"
>
> How do I find out what causes this error? Is there a way to see all
> active scopes when such an error happens?
>
> Christian Dietrich wrote on Fri, 13 July 2012 19:26
>> never the less having a look at the class
>>
>> org.eclipse.xtext.scoping.Scopes
>
>
> This class looks very useful and it's mentioned in the Xtext docs 0
> times. Can you please change this?
>
> Christian Dietrich wrote on Fri, 13 July 2012 19:26
>> and considering this simple statement might help
>>
>> return new FilteringScope(delegateGetScope(context, ref), new
>> Predicate<IEObjectDescription>() {
>>
>> @Override
>> public boolean apply(IEObjectDescription input) {
>> return true;
>> }
>> });
>
>
> What does delegateGetScope() do? There no documentation for it.
>
> Christian Dietrich wrote on Fri, 13 July 2012 19:26
>> Depending on the kind of information you need to filter
>> ImportedNamespaceAwareLocalScopeProvider
>> and
>> DefaultResourceDescriptionStrategy
>> might have to be changes too.
>
>
> I checked the docs for ImportedNamespaceAwareLocalScopeProvider; at
> first it doesn't seem to apply because the docs say "It adds namespace
> support to your language, which is comparable and similar to the one in
> Scala and C#."
>
> I'm not using name spaces and I don't know Scala or C# well enough to
> understand what the reference means. But looking further, it seems the
> provider can also be used to implement Java-style "import" statements
> but I couldn't find any explanation for that.
>
> Maybe the documentation there is too dense:
>
> Quote:
>> The imported namespace aware scoping is based on qualified names and
>> namespaces. It adds namespace support to your language, which is
>> comparable and similar to the one in Scala and C#. Scala and C# both
>> allow to have multiple nested packages within one file and you can put
>> imports per namespace, so that imported names are only visible within
>> that namespace. See the domain model example: its scope provider
>> extends ImportedNamespaceAwareLocalScopeProvider (src).
>
>
> Next, the docs mention that you can override how the qualified name is
> built. Only after this example, it goes on to say that you can use this
> for Java's "import" but there is no code example what exactly you need
> to make this work.
>
> My criticism here is that there in no clear path that the documentation
> follows. It mentions a lot of things but there is no strategy to help
> readers get the big picture or help them to solve specific problems. All
> it says "this can be done" but it doesn't say how.
>
> The domain model example is similar. It contains two very simple parser
> test cases, 2 code generator tests (one fails) and 440 Xbase tests. What
> I'm missing:
>
> # Tests for validation rules
> # Tests for formatting
> # Some explanations what the different formatting rules try to achieve
> # Is there a web site which explains the different features of the
> domain model step by step? For example, DomainmodelJvmModelInferrer
> looks very interesting but what does it do?
> # Tests for more complex domain models
> # There is no code generator in the example; How does the domain model
> generate its code? If I didn't have the Xtext sources installed, then
> the reference to CompilationTestHelper would be useless.
> # The code coverage by the domain model tests is 64% for the base
> plug-in (but only 30% of the non-generated code is covered) and 0% for
> the UI code.
>
> I think this is cause by you being inside the problem. The people
> working on the scope documentation have been developing Xtext for 2-3
> years, now. They don't see anymore what newcomers don't know.
>
> Writing better documentation is something that interests me but I'm
> under some stress right now, so I can't offer my help except by giving
> you input :(
>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #896759 is a reply to message #896638] Thu, 19 July 2012 11:48 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Thu, 19 July 2012 10:40

One major thing that you have to keep in mind is that the documentation
is not meant to be a cook book but a reference documentation. It is
simply not possible for use (resource-wise) to document even the more
common use cases by means of detailled examples. What we try to achieve
is that the concepts are described rather than implementation details
and how-to. I know that we still scratch only the surface conceptually,
too ...


On my side (consumer of Xtext), I find about 5 thousand classes which are related to scopes and I don't understand what any of those does. DI/IoC is very useful to create a loosely coupled system that no one can understand without running and debugging it.

I spent about four hours today to debug my "Couldn't resolve reference" but failed to understand what is going on. I see the big picture (scopes nest) and that you get some parts here and some parts there but I'm missing a tool to debug a broken scope to see why something can't be found.

Would it be a good idea to ask for a scope "debugger"?

Regards,

A. Digulla
Re: Xtext and scopes [message #896762 is a reply to message #896759] Thu, 19 July 2012 12:07 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

Am 19.07.12 17:48, schrieb Aaron Digulla:
>
> On my side (consumer of Xtext), I find about 5 thousand classes which
> are related to scopes

I doubt that. You are probably refering to 35 to 65 classes. But I get
your point.

and I don't understand what any of those does.
> DI/IoC is very useful to create a loosely coupled system that no one can
> understand without running and debugging it.

Type hierarchy and call hierarchy are very useful tools in Eclipse. I
can only recommend to use them often. It's far more helpful to get a
complete picture than using the debugger which will likely change the
observed system due to #toString invocations that may trigger otherwise
lazily computed things.

>
> I spent about four hours today to debug my "Couldn't resolve reference"
> but failed to understand what is going on.

It pretty much depends on your customizing. I remember that you wrote
something about two resource sets and stuff. That's nothing that the
framework did for you. My first question would be to remove that stuff,
take a step backwards and reconsider your approach. If I'm not mistaken,
you want to add library models to your scope. The approach would usually
be to add synthetic visible containers that by means of the container
manager.


I see the big picture (scopes
> nest) and that you get some parts here and some parts there but I'm
> missing a tool to debug a broken scope to see why something can't be found.
>
> Would it be a good idea to ask for a scope "debugger"?

What would you expect from such a tool?

Best regards,
Sebastian

>
> Regards,
>
> A. Digulla

--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Xtext and scopes [message #896912 is a reply to message #896762] Fri, 20 July 2012 08:20 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Thu, 19 July 2012 18:07

> I spent about four hours today to debug my "Couldn't resolve reference"
> but failed to understand what is going on.

It pretty much depends on your customizing.


As I said, I didn't do any customizing that I'm aware of. Xtext simply doesn't find references at the global scope and I don't understand why.

Or to put it another way: Do I have to do any customizing when my models are spread over several files?

Sebastian Zarnekow wrote on Thu, 19 July 2012 18:07

I remember that you wrote
something about two resource sets and stuff. That's nothing that the
framework did for you.


I have *one* resource *set* and two *resources* in this single set. For some reason, the elements defined in one resource aren't *always* available in the other.

Sebastian Zarnekow wrote on Thu, 19 July 2012 18:07

> I see the big picture (scopes
> nest) and that you get some parts here and some parts there but I'm
> missing a tool to debug a broken scope to see why something can't be found.
>
> Would it be a good idea to ask for a scope "debugger"?

What would you expect from such a tool?


It should tell me what symbols are provided by a scope at each level, where they came from (maybe resource URL + chain of getters) and which bean added them to the scope.

My mental model of Xtext is probably wrong. I see the scope as the old fashioned symbol table from the Dragon book. But in the debugger, I can't figure out where that symbol table is or how to print all the known symbols in the table. My guess is that this is somehow distributed too much or lazy computed or EMF is doing something odd.

Let's start with EReference. When I look at it, I get this:

(name: libs) (ordered: true, unique: false, lowerBound: 0, upperBound: -1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: false, resolveProxies: true)


I recognize "name". The next block looks like EMF lists (ordered, not unique, 0 or more elements). The next two blocks seem cryptic. I understand the words but not the sentence.

Then we have the mysterious "uri fragment" which looks like "#xtextLink_::0.0::1::/8" All the dots and numbers probably mean something but not for me. How do I translate that into something meaningful? Who creates these links? Where?

But frankly, I don't care for all these questions. All I really want to know is what is in my scope and why.

Regards,

A. Digulla
Re: Xtext and scopes [message #896915 is a reply to message #896912] Fri, 20 July 2012 08:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6205
Registered: July 2009
Senior Member
Hi,

can you share a reproducable example?

did you use the "Open Model Element Dialog" Crtl+Shift+F3 to have a look at the index
if the objects are really there and the name is the one you expect?


~Christian
Re: Xtext and scopes [message #896941 is a reply to message #896912] Fri, 20 July 2012 09:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Am 20.07.12 14:20, schrieb Aaron Digulla:
>
> I have *one* resource *set* and two *resources* in this single set. For
> some reason, the elements defined in one resource aren't *always*
> available in the other.

Well I remembered from another post that you described:

In my test case, I load two resource sets. One defines libraries and the
second contains a reference to one or more libraries ("(libs +=
[LibDef])*" in the grammar)


Sorry that I got that wrong and you have a *single set*. People tend to
become confused if you write two "resource sets" but actually talk about
one.

Please share your code, otherwise it does not seem possible to answer
your question given the sparse information that is provided.

Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Xtext and scopes [message #896947 is a reply to message #896941] Fri, 20 July 2012 09:44 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Which brings me to the question: Did you apply the workaround that was
mentioned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555 for
your project?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 20.07.12 15:37, schrieb Sebastian Zarnekow:
> Am 20.07.12 14:20, schrieb Aaron Digulla:
>>
>> I have *one* resource *set* and two *resources* in this single set. For
>> some reason, the elements defined in one resource aren't *always*
>> available in the other.
>
> Well I remembered from another post that you described:
>
> In my test case, I load two resource sets. One defines libraries and the
> second contains a reference to one or more libraries ("(libs +=
> [LibDef])*" in the grammar)
>
>
> Sorry that I got that wrong and you have a *single set*. People tend to
> become confused if you write two "resource sets" but actually talk about
> one.
>
> Please share your code, otherwise it does not seem possible to answer
> your question given the sparse information that is provided.
>
> Thanks,
> Sebastian
Re: Xtext and scopes [message #897230 is a reply to message #896915] Mon, 23 July 2012 06:02 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Christian Dietrich wrote on Fri, 20 July 2012 14:24

can you share a reproducable example?


I wish Sad

Christian Dietrich wrote on Fri, 20 July 2012 14:24

did you use the "Open Model Element Dialog" Crtl+Shift+F3 to have a look at the index
if the objects are really there and the name is the one you expect?


When I copy the name from the editor and paste it into the dialog, I get two matches.

One is from the source folder of the Maven module which defines the library and the second one is from Maven's target folder (I have configured Eclipse and Xtext to use different folders for compiled output).

What happens in Xtext when there are two matching symbols?

Regards,

A. Digulla
Re: Xtext and scopes [message #897240 is a reply to message #896941] Mon, 23 July 2012 07:19 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Fri, 20 July 2012 15:37

> I have *one* resource *set* and two *resources* in this single set. For
> some reason, the elements defined in one resource aren't *always*
> available in the other.

Well I remembered from another post that you described:

In my test case, I load two resource sets. One defines libraries and the
second contains a reference to one or more libraries ("(libs +=
[LibDef])*" in the grammar)


Sorry that I got that wrong and you have a *single set*. People tend to
become confused if you write two "resource sets" but actually talk about
one.


Sorry, I really wasn't aware that I got that wrong Sad

Sebastian Zarnekow wrote on Fri, 20 July 2012 15:37

Please share your code, otherwise it does not seem possible to answer
your question given the sparse information that is provided.


I'll talk to my boss how to handle this. But it proves my point: When there is a problem in this area, Xtext doesn't provide us with enough information to see what is going on without looking at the source code.

Taking a step back, some more general questions:

If an DSL editor tries to look for a reference (the thing between "[]" in the grammar), where does it look if I don't have any special scoping rules defined?

How can I enumerate all models that my DSL editor can "see" when I'm in a special scoping rule? I tried:

    public Iterable<Model> allModels( ResourceSet rset ) {
        Iterable<EObject> contents = Iterables.concat( Iterables.transform( rset.getResources(), new Function<Resource, Collection<EObject>>() {
            @Override
            public Collection<EObject> apply( Resource r ) {
                return r.getContents();
            }
        }) );
        
        Function<EObject, Model> castToModel = new Function<EObject, Model>() {
            @Override
            public Model apply( EObject o ) {
                return (Model) o;
            }
        };
        return Iterables.transform( contents, castToModel );
    }


but that doesn't seem to work in all cases. What are the rules which Xtext uses in a DSL UI to locate references in models?

Regards,

A. Digulla
Re: Xtext and scopes [message #897262 is a reply to message #897230] Mon, 23 July 2012 08:48 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

the resource description provider explicitly filters resources from the
Java output folder. That mechanism can only reject the output location
that eclipse knows about. If your maven build compiles to a different
location, you'll end upt with duplicate resources. You may want to
override
org.eclipse.xtext.ui.resource.DefaultResourceUIServiceProvider.isJavaTargetFolder(IStorage)
and make it aware of your Maven config.

Xtext will pick the first one if there is more than one matching symbol.
Validation should take care of such conflicts.

Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 23.07.12 12:02, schrieb Aaron Digulla:
> Christian Dietrich wrote on Fri, 20 July 2012 14:24
>> can you share a reproducable example?
>
>
> I wish :(
>
> Christian Dietrich wrote on Fri, 20 July 2012 14:24
>> did you use the "Open Model Element Dialog" Crtl+Shift+F3 to have a
>> look at the index
>> if the objects are really there and the name is the one you expect?
>
>
> When I copy the name from the editor and paste it into the dialog, I get
> two matches.
>
> One is from the source folder of the Maven module which defines the
> library and the second one is from Maven's target folder (I have
> configured Eclipse and Xtext to use different folders for compiled output).
>
> What happens in Xtext when there are two matching symbols?
>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #897264 is a reply to message #897240] Mon, 23 July 2012 08:55 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

see below.

Am 23.07.12 13:19, schrieb Aaron Digulla:

> I'll talk to my boss how to handle this. But it proves my point: When
> there is a problem in this area, Xtext doesn't provide us with enough
> information to see what is going on without looking at the source code.

Yes, that's the spirit that we follow. Unfortunately we don't have the
resources to document everything up to a satisfying level. Therefore the
newsgroup support and for more confidential things the prof support is
available. I find that reasonable.

>
> Taking a step back, some more general questions:
>
> If an DSL editor tries to look for a reference (the thing between "[]"
> in the grammar), where does it look if I don't have any special scoping
> rules defined?

The current resource, all resources in the project, all resources in
dependent projects.

>
> How can I enumerate all models that my DSL editor can "see" when I'm in
> a special scoping rule? I tried:

You should avoid that. Really. Even for debugging purpose that's not a
good idea. Try to use the various queries on the IScope and inspect the
result. That will lead to more trustworthy results and is easier to handle.

You may want to enumerate the content of the IContainers that returned
by IContainer.Manager#getVisibleContainers to find all resources that
are queried.
Things will not be contained in the resource set but often loaded on
demand after they have were found in the index. Therefore the resource
set is not a point of truth.

>
>
> public Iterable<Model> allModels( ResourceSet rset ) {
> Iterable<EObject> contents = Iterables.concat(
> Iterables.transform( rset.getResources(), new Function<Resource,
> Collection<EObject>>() {
> @Override
> public Collection<EObject> apply( Resource r ) {
> return r.getContents();
> }
> }) );
> Function<EObject, Model> castToModel = new Function<EObject,
> Model>() {
> @Override
> public Model apply( EObject o ) {
> return (Model) o;
> }
> };
> return Iterables.transform( contents, castToModel );
> }
>
>
> but that doesn't seem to work in all cases. What are the rules which
> Xtext uses in a DSL UI to locate references in models?

Basically what's documented in the reference docs and the Java docs
around IResourceDescription, IContainer, IScope and IScopeProvider (and
their respective implementation classes) is up-to-date.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #897288 is a reply to message #897262] Mon, 23 July 2012 09:56 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Mon, 23 July 2012 14:48

You may want to
override
org.eclipse.xtext.ui.resource.DefaultResourceUIServiceProvider.isJavaTargetFolder(IStorage)
and make it aware of your Maven config.


Thanks, I'll have a look.

Regards,

A. Digulla
Re: Xtext and scopes [message #897308 is a reply to message #897264] Mon, 23 July 2012 10:32 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Mon, 23 July 2012 14:55

> I'll talk to my boss how to handle this. But it proves my point: When
> there is a problem in this area, Xtext doesn't provide us with enough
> information to see what is going on without looking at the source code.

Yes, that's the spirit that we follow. Unfortunately we don't have the
resources to document everything up to a satisfying level. Therefore the
newsgroup support and for more confidential things the prof support is
available. I find that reasonable.


I understand. The knowledge is free, the time to explain costs money Smile

How about adding some toString() methods or a "scope dumper" to quickly see what a scope contains?

(I mean more than the parent-child relations that some implementations of IScope print today).

Sebastian Zarnekow wrote on Mon, 23 July 2012 14:55

> Taking a step back, some more general questions:
>
> If an DSL editor tries to look for a reference (the thing between "[]"
> in the grammar), where does it look if I don't have any special scoping
> rules defined?

The current resource, all resources in the project, all resources in
dependent projects.


Thanks. So it should find what I need but for some reason, it doesn't. Does it matter if the project is open?

Maven allows me to close projects; in that case, the dependency will be resolved with JAR that contains the models. So the model is there but you will have to iterate over the entries in a JAR instead of over files (IResource) in an Eclipse project.

Sebastian Zarnekow wrote on Mon, 23 July 2012 14:55

> How can I enumerate all models that my DSL editor can "see" when I'm in
> a special scoping rule? I tried:

You should avoid that. Really. Even for debugging purpose that's not a
good idea. Try to use the various queries on the IScope and inspect the
result. That will lead to more trustworthy results and is easier to handle.

You may want to enumerate the content of the IContainers that returned
by IContainer.Manager#getVisibleContainers to find all resources that
are queried.


Ok. I found an example how to use getVisibleContainers() in org.eclipse.xtext.scoping.impl.DefaultGlobalScopeProvider.getVisibleContainers(Resource)
but the code looks odd:

OnChangeEvictingCache.CacheAdapter cache = new OnChangeEvictingCache().getOrCreate(resource);


What keeps the local variable cache alive?

Anyway, I tried to build something that can find all libraries:

    @Inject
    private IContainer.Manager containerManager;

    @Inject
    private IResourceDescription.Manager descriptionManager;
    
    @Inject
    private IGlobalScopeProvider globalScopeProvider;

    public Iterable<Model> allModels( Resource resource ) {
        IResourceDescription description = descriptionManager.getResourceDescription(resource);
        IResourceDescriptions resourceDescriptions = ((AbstractGlobalScopeProvider)globalScopeProvider).getResourceDescriptions(resource);
        List<IContainer> containers = containerManager.getVisibleContainers( description, resourceDescriptions );

        EClass type = MSetDslPackage.eINSTANCE.getAvPMLib();
        
        List<Model> result = Lists.newArrayList();
        for( IContainer container : containers ) {
            Iterable<IEObjectDescription> exports = container.getExportedObjectsByType( type );
            for( IEObjectDescription export : exports ) {
                System.out.println( export.getQualifiedName() + " " + export.getEObjectURI() );
                EObject obj = export.getEObjectOrProxy();
                result.add( (Model) obj );
            }
        }
        
        return result;
    }


But I just get 1 container from the code above and that's the one which is open in the current editor.

Regards,

A. Digulla
Re: Xtext and scopes [message #897358 is a reply to message #897308] Mon, 23 July 2012 14:27 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

see inline.

Am 23.07.12 16:32, schrieb Aaron Digulla:
> Sebastian Zarnekow wrote on Mon, 23 July 2012 14:55
>> > I'll talk to my boss how to handle this. But it proves my point: When
>> > there is a problem in this area, Xtext doesn't provide us with enough
>> > information to see what is going on without looking at the source code.
>>
>> Yes, that's the spirit that we follow. Unfortunately we don't have the
>> resources to document everything up to a satisfying level. Therefore
>> the newsgroup support and for more confidential things the prof
>> support is available. I find that reasonable.
>
>
> I understand. The knowledge is free, the time to explain costs money :)

Time is money ;-)

>
> How about adding some toString() methods or a "scope dumper" to quickly
> see what a scope contains?

Scopes are computed lazily for good reasons. You won't like it if your
scopes cause an OOM in the debugger because all their content is fetched
eagily for the purpose of a #toString representation.

>
> (I mean more than the parent-child relations that some implementations
> of IScope print today).
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 14:55
>> > Taking a step back, some more general questions:
>> >
>> > If an DSL editor tries to look for a reference (the thing between "[]"
>> > in the grammar), where does it look if I don't have any special scoping
>> > rules defined?
>>
>> The current resource, all resources in the project, all resources in
>> dependent projects.
>
>
> Thanks. So it should find what I need but for some reason, it doesn't.
> Does it matter if the project is open?
>
> Maven allows me to close projects; in that case, the dependency will be
> resolved with JAR that contains the models. So the model is there but
> you will have to iterate over the entries in a JAR instead of over files
> (IResource) in an Eclipse project.

Everything that's on the classpath of an IJAvaProject is visible. Each
Jar should get an own container. Semantics are the very same as for Java
classes (read: first come first serve in cause of ambiguities)

>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 14:55
>> > How can I enumerate all models that my DSL editor can "see" when I'm in
>> > a special scoping rule? I tried:
>>
>> You should avoid that. Really. Even for debugging purpose that's not a
>> good idea. Try to use the various queries on the IScope and inspect
>> the result. That will lead to more trustworthy results and is easier
>> to handle.
>>
>> You may want to enumerate the content of the IContainers that returned
>> by IContainer.Manager#getVisibleContainers to find all resources that
>> are queried.
>
>
> Ok. I found an example how to use getVisibleContainers() in
> org.eclipse.xtext.scoping.impl.DefaultGlobalScopeProvider.getVisibleContainers(Resource)
>
> but the code looks odd:
>
>
> OnChangeEvictingCache.CacheAdapter cache = new
> OnChangeEvictingCache().getOrCreate(resource);
>
>
> What keeps the local variable cache alive?

See the JavaDoc of OnChangeEvictingCache:

/**
* A cache implementation that stores its values in the scope of a
resource.
* The values will be discarded as soon as the contents of the resource
changes semantically.
* Clients may override this behavior for certain transactions by means
of {@link #execWithoutCacheClear(Resource, IUnitOfWork)}
* or {@link #execWithTemporaryCaching(Resource, IUnitOfWork)}.
*
* @author Sven Efftinge - Initial contribution and API
* @author Sebastian Zarnekow
*/


>
> Anyway, I tried to build something that can find all libraries:
>
>
> @Inject
> private IContainer.Manager containerManager;
>
> @Inject
> private IResourceDescription.Manager descriptionManager;
> @Inject
> private IGlobalScopeProvider globalScopeProvider;
>
> public Iterable<Model> allModels( Resource resource ) {
> IResourceDescription description =
> descriptionManager.getResourceDescription(resource);
> IResourceDescriptions resourceDescriptions =
> ((AbstractGlobalScopeProvider)globalScopeProvider).getResourceDescriptions(resource);
>
> List<IContainer> containers =
> containerManager.getVisibleContainers( description, resourceDescriptions );
>
> EClass type = MSetDslPackage.eINSTANCE.getAvPMLib();
> List<Model> result = Lists.newArrayList();
> for( IContainer container : containers ) {
> Iterable<IEObjectDescription> exports =
> container.getExportedObjectsByType( type );
> for( IEObjectDescription export : exports ) {
> System.out.println( export.getQualifiedName() + " " +
> export.getEObjectURI() );
> EObject obj = export.getEObjectOrProxy();
> result.add( (Model) obj );
> }
> }
> return result;
> }
>
>
> But I just get 1 container from the code above and that's the one which
> is open in the current editor.

Please use the
org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider to obtain a
valid instance of the context specific ResourceDescriptions.

I assume you still did not add any custom bindings to the runtime module
or ui module? How do you run that code? In a unit test or while
debugging a runtime app?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #897459 is a reply to message #897358] Tue, 24 July 2012 04:19 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian, thanks for spending so much time with me.

Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27

> How about adding some toString() methods or a "scope dumper" to quickly
> see what a scope contains?

Scopes are computed lazily for good reasons. You won't like it if your
scopes cause an OOM in the debugger because all their content is fetched
eagily for the purpose of a #toString representation.


Well, I have 16GB of RAM and I don't care how much memory Xtext needs to give me the information that I need to fix a bug Smile Memory is cheap. One hour bug searching costs about $150. I could buy 24GB of RAM for that.

Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27

Everything that's on the classpath of an IJAvaProject is visible. Each
Jar should get an own container. Semantics are the very same as for Java
classes (read: first come first serve in cause of ambiguities)


Okay. I translate that as: It should behave as I expect but doesn't.

Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27

> OnChangeEvictingCache.CacheAdapter cache = new
> OnChangeEvictingCache().getOrCreate(resource);
>
> What keeps the local variable cache alive?
See the JavaDoc of OnChangeEvictingCache:


Ah, it's in getOrCreate():

resource.eAdapters().add(adapter);


Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27

Please use the
org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider to obtain a
valid instance of the context specific ResourceDescriptions.


Here is the new code:

    @Inject
    private IContainer.Manager containerManager;

    @Inject
    private IResourceDescription.Manager descriptionManager;
    
    @Inject
    private ResourceDescriptionsProvider resourceDescriptionsProvider;

    public Iterable<Model> allModels( Resource resource ) {
        IResourceDescription description = descriptionManager.getResourceDescription(resource);
        IResourceDescriptions resourceDescriptions = resourceDescriptionsProvider.getResourceDescriptions(resource);
        List<IContainer> containers = containerManager.getVisibleContainers( description, resourceDescriptions );
        System.out.println( "Found " + containers.size() + " containers for " + resource );

        EClass type = MSetDslPackage.eINSTANCE.getAvPMLib();
        
        List<Model> result = Lists.newArrayList();
        for( IContainer container : containers ) {
            Iterable<IEObjectDescription> exports = container.getExportedObjectsByType( type );
            for( IEObjectDescription export : exports ) {
                System.out.println( export.getQualifiedName() + " " + export.getEObjectURI() );
                EObject obj = export.getEObjectOrProxy();
                result.add( (Model) obj );
            }
        }
        
        return result;
    }


Models:

------------ file causeType.mset -----------------
ModelSet CauseTypeMSet {
    lib admPMLib;
    ...
}

---------- file admPMLib.mset ---------------------
lib admPMLib extends baseBluPMLib { ... }

---------- file baseBluPMLib.mset ---------------------
lib baseBluPMLib { ... }


Output when I save causeType.mset:

Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@461c5b7d uri='platform:/resource/.../causeType.mset'
baseBluPMLib platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset#//@libs.0
Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@499e1073 uri='platform:/resource/.../libs/admPMLib.mset'
baseBluPMLib platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset#//@libs.0
Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@735dc05f uri='platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset'
baseBluPMLib platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset#//@libs.0
Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@7962c4d7 uri='platform:/resource/ors-pm-config/src/main/resources/.../causeType.mset'
admPMLib platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset#//@libs.0
Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@8261845 uri='platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset'
admPMLib platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset#//@libs.0
Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@3916ed5c uri='platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset'
admPMLib platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset#//@libs.0


When I do code completion, I see 11 other libraries but they don't appear in the output of the code above which means so other code must be executed to determine which symbols are visible.

Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27

I assume you still did not add any custom bindings to the runtime module
or ui module?


Here is the runtime module (with https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555 applied):

public class MSetDslRuntimeModule extends com.avanon.pmodel.dsl.AbstractMSetDslRuntimeModule {
	
	public Class<? extends ITypesystem> bindITypesystem() {
        return MSetTypesystem.class;
    }


    // Bugfix for resolution of resources in same resource set
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
	@Override
    public Class<? extends IAllContainersState.Provider> bindIAllContainersState$Provider() {
      return FixedResourceSetBasedAllContainersStateProvider.class;
    }

    public static class FixedResourceSetBasedAllContainersStateProvider extends
        ResourceSetBasedAllContainersStateProvider {

      @Override
      protected IAllContainersState handleAdapterNotFound(
          ResourceSet resourceSet) {
        return new FixedFlatResourceSetBasedAllContainersState(resourceSet);
      }
    }

    public static class FixedFlatResourceSetBasedAllContainersState extends
        FlatResourceSetBasedAllContainersState {

      public FixedFlatResourceSetBasedAllContainersState(ResourceSet rs) {
        super(rs);
      }

      public Collection<URI> getContainedURIs(String containerHandle) {
        if (!getHandle().equals(containerHandle))
          return Collections.emptySet();
        ResourceSet resourceSet = getResourceSet();
        List<URI> uris = Lists.newArrayListWithCapacity(resourceSet
            .getResources().size());
        URIConverter uriConverter = resourceSet.getURIConverter();
        for (Resource r : resourceSet.getResources())
          uris.add(uriConverter.normalize(r.getURI()));
        return uris;
      }
    }
}


And this is the UI module:

public class MSetDslUiModule extends com.avanon.pmodel.dsl.ui.AbstractMSetDslUiModule {
	public MSetDslUiModule(AbstractUIPlugin plugin) {
		super(plugin);
	}

    // With this binding, Xtext editors open much faster 
    // See http://alexruiz.developerblogs.com/?p=2359
    @Override
    public Class<? extends IResourceSetProvider> bindIResourceSetProvider() {
        return SimpleResourceSetProvider.class;
    }
}


Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27

How do you run that code? In a unit test or while
debugging a runtime app?


There are three ways:

1. As Junit test (not plugin test!) in Eclipse -> fails
2. As Junit test with Tycho (command line) -> success!!
3. Debugging as "Eclipse Application" launch type -> fails

In the Eclipse Console (1+3), I see this output:

Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@4c5cc942 uri='test.mset'
    1: 2 org.eclipse.xtext.resource.containers.StateBasedContainer@5fa13338
scope_AvPMmodelSet_libs libs=[]


-> no symbols on the global level found

On the command line, I get:

Found 1 containers for org.eclipse.xtext.linking.lazy.LazyLinkingResource@353980e1 uri='test.mset'
    1: 2 org.eclipse.xtext.resource.containers.StateBasedContainer@523c4f13
base base.mset#//@libs.0


i.e. here, "base" is found.

What could be different?

Regards,

A. Digulla
Re: Xtext and scopes [message #897482 is a reply to message #897459] Tue, 24 July 2012 05:13 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Do your files reside in a Java project in a source folder (in the
Eclipse-sense, e.g. is src/main/resources a source folder)?
Is the class-path different when you run those tests with Maven or as
junit test from within Eclipse? I'm not too familiar with Tycho/Maven...

Where did you add the allModels(Resource) code? How do you invoke it?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 24.07.12 10:19, schrieb Aaron Digulla:
> Sebastian, thanks for spending so much time with me.
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27
>> > How about adding some toString() methods or a "scope dumper" to quickly
>> > see what a scope contains?
>>
>> Scopes are computed lazily for good reasons. You won't like it if your
>> scopes cause an OOM in the debugger because all their content is
>> fetched eagily for the purpose of a #toString representation.
>
>
> Well, I have 16GB of RAM and I don't care how much memory Xtext needs to
> give me the information that I need to fix a bug :) Memory is cheap. One
> hour bug searching costs about $150. I could buy 24GB of RAM for that.
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27
>> Everything that's on the classpath of an IJAvaProject is visible. Each
>> Jar should get an own container. Semantics are the very same as for
>> Java classes (read: first come first serve in cause of ambiguities)
>
>
> Okay. I translate that as: It should behave as I expect but doesn't.
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27
>> > OnChangeEvictingCache.CacheAdapter cache = new
>> > OnChangeEvictingCache().getOrCreate(resource);
>> >
>> > What keeps the local variable cache alive?
>> See the JavaDoc of OnChangeEvictingCache:
>
>
> Ah, it's in getOrCreate():
>
>
> resource.eAdapters().add(adapter);
>
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27
>> Please use the
>> org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider to obtain
>> a valid instance of the context specific ResourceDescriptions.
>
>
> Here is the new code:
>
>
> @Inject
> private IContainer.Manager containerManager;
>
> @Inject
> private IResourceDescription.Manager descriptionManager;
> @Inject
> private ResourceDescriptionsProvider resourceDescriptionsProvider;
>
> public Iterable<Model> allModels( Resource resource ) {
> IResourceDescription description =
> descriptionManager.getResourceDescription(resource);
> IResourceDescriptions resourceDescriptions =
> resourceDescriptionsProvider.getResourceDescriptions(resource);
> List<IContainer> containers =
> containerManager.getVisibleContainers( description, resourceDescriptions );
> System.out.println( "Found " + containers.size() + " containers
> for " + resource );
>
> EClass type = MSetDslPackage.eINSTANCE.getAvPMLib();
> List<Model> result = Lists.newArrayList();
> for( IContainer container : containers ) {
> Iterable<IEObjectDescription> exports =
> container.getExportedObjectsByType( type );
> for( IEObjectDescription export : exports ) {
> System.out.println( export.getQualifiedName() + " " +
> export.getEObjectURI() );
> EObject obj = export.getEObjectOrProxy();
> result.add( (Model) obj );
> }
> }
> return result;
> }
>
>
> Models:
>
>
> ------------ file causeType.mset -----------------
> ModelSet CauseTypeMSet {
> lib admPMLib;
> ...
> }
>
> ---------- file admPMLib.mset ---------------------
> lib admPMLib extends baseBluPMLib { ... }
>
> ---------- file baseBluPMLib.mset ---------------------
> lib baseBluPMLib { ... }
>
>
> Output when I save causeType.mset:
>
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@461c5b7d
> uri='platform:/resource/.../causeType.mset'
> baseBluPMLib
> platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset#//@libs.0
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@499e1073
> uri='platform:/resource/.../libs/admPMLib.mset'
> baseBluPMLib
> platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset#//@libs.0
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@735dc05f
> uri='platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset'
>
> baseBluPMLib
> platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset#//@libs.0
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@7962c4d7
> uri='platform:/resource/ors-pm-config/src/main/resources/.../causeType.mset'
>
> admPMLib
> platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset#//@libs.0
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@8261845
> uri='platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset'
>
> admPMLib
> platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset#//@libs.0
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@3916ed5c
> uri='platform:/resource/ors-pm-config/src/main/resources/.../libs/baseBluPMLib.mset'
>
> admPMLib
> platform:/resource/ors-pm-config/src/main/resources/.../libs/admPMLib.mset#//@libs.0
>
>
>
> When I do code completion, I see 11 other libraries but they don't
> appear in the output of the code above which means so other code must be
> executed to determine which symbols are visible.
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27
>> I assume you still did not add any custom bindings to the runtime
>> module or ui module?
>
>
> Here is the runtime module (with
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555 applied):
>
>
> public class MSetDslRuntimeModule extends
> com.avanon.pmodel.dsl.AbstractMSetDslRuntimeModule {
>
> public Class<? extends ITypesystem> bindITypesystem() {
> return MSetTypesystem.class;
> }
>
>
> // Bugfix for resolution of resources in same resource set
> // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=382555
> @Override
> public Class<? extends IAllContainersState.Provider>
> bindIAllContainersState$Provider() {
> return FixedResourceSetBasedAllContainersStateProvider.class;
> }
>
> public static class FixedResourceSetBasedAllContainersStateProvider
> extends
> ResourceSetBasedAllContainersStateProvider {
>
> @Override
> protected IAllContainersState handleAdapterNotFound(
> ResourceSet resourceSet) {
> return new
> FixedFlatResourceSetBasedAllContainersState(resourceSet);
> }
> }
>
> public static class FixedFlatResourceSetBasedAllContainersState extends
> FlatResourceSetBasedAllContainersState {
>
> public FixedFlatResourceSetBasedAllContainersState(ResourceSet rs) {
> super(rs);
> }
>
> public Collection<URI> getContainedURIs(String containerHandle) {
> if (!getHandle().equals(containerHandle))
> return Collections.emptySet();
> ResourceSet resourceSet = getResourceSet();
> List<URI> uris = Lists.newArrayListWithCapacity(resourceSet
> .getResources().size());
> URIConverter uriConverter = resourceSet.getURIConverter();
> for (Resource r : resourceSet.getResources())
> uris.add(uriConverter.normalize(r.getURI()));
> return uris;
> }
> }
> }
>
>
> And this is the UI module:
>
>
> public class MSetDslUiModule extends
> com.avanon.pmodel.dsl.ui.AbstractMSetDslUiModule {
> public MSetDslUiModule(AbstractUIPlugin plugin) {
> super(plugin);
> }
>
> // With this binding, Xtext editors open much faster // See
> http://alexruiz.developerblogs.com/?p=2359
> @Override
> public Class<? extends IResourceSetProvider>
> bindIResourceSetProvider() {
> return SimpleResourceSetProvider.class;
> }
> }
>
>
> Sebastian Zarnekow wrote on Mon, 23 July 2012 20:27
>> How do you run that code? In a unit test or while debugging a runtime
>> app?
>
>
> There are three ways:
>
> 1. As Junit test (not plugin test!) in Eclipse -> fails
> 2. As Junit test with Tycho (command line) -> success!!
> 3. Debugging as "Eclipse Application" launch type -> fails
>
> In the Eclipse Console (1+3), I see this output:
>
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@4c5cc942 uri='test.mset'
> 1: 2 org.eclipse.xtext.resource.containers.StateBasedContainer@5fa13338
> scope_AvPMmodelSet_libs libs=[]
>
>
> -> no symbols on the global level found
>
> On the command line, I get:
>
>
> Found 1 containers for
> org.eclipse.xtext.linking.lazy.LazyLinkingResource@353980e1 uri='test.mset'
> 1: 2 org.eclipse.xtext.resource.containers.StateBasedContainer@523c4f13
> base base.mset#//@libs.0
>
>
> i.e. here, "base" is found.
>
> What could be different?
>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #897536 is a reply to message #897482] Tue, 24 July 2012 08:44 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Tue, 24 July 2012 11:13
Do your files reside in a Java project in a source folder (in the
Eclipse-sense, e.g. is src/main/resources a source folder)?


In my unit test, the two source files are added to one resource set using two different URLs. One contains the library definition, the second resource contains a model which references the library. Here is the code:

val rset = new SynchronizedXtextResourceSet()
		
parser.resourceSet( rset ).uri( "base.mset" ).input("lib base {}").parse()
parser.resourceSet( rset ).uri( "test.mset" ).input('''
    ModelSet mset {
        lib base base;
    }''')
    .expectError( "ERROR:duplicate lib entry 'base' (test.mset line : 2)" )


Instead of the validation error, I get "Couldn't resolve reference to AvPMLib 'base'" and I simply fail to understand how something so simple could possibly fail! I have no OSGi, the setup is very simple, there is no customization of any kind. It's very frustrating, especially since everything else in Xtext works just as expected.

When I run the Eclipse application, all model sets are in the same (the current) Java project. I checked the .project file and it has the Java nature.

Might be related: Sometimes, I see errors in the editor but the problems view is empty. Sometimes, those errors go away when I close+open the editor again. Or I have to modify + save the file.

Sebastian Zarnekow wrote on Tue, 24 July 2012 11:13
Is the class-path different when you run those tests with Maven or as
junit test from within Eclipse? I'm not too familiar with Tycho/Maven...


The tests in Eclipse are missing two plugins which might be relevant:

org.eclipse.xtext.ecore-2.3.0.v201206120633.jar
org.eclipse.xtext.smap-2.3.0.v201206120633.jar

but adding those two to the classpath has no effect :-/ But apparently, Tycho runs the tests as headless JUnit plugin tests - which I can't get to work inside of Eclipse Sad

So I'm stuck with three different environments and three different behaviors and no way to use the differences to figure out what's wrong Sad

Sebastian Zarnekow wrote on Tue, 24 July 2012 11:13
Is the class-path Where did you add the allModels(Resource) code? How do you invoke it?


It's part of a custom scope provider:

public class MSetDslScopeProvider extends AbstractDeclarativeScopeProvider {
       public IScope scope_AvPMmodelSet_libs( AvPMmodelSet modelSet, EReference ref ) {
        
        Resource resource = modelSet.eResource();
        List<AvPMLib> libs = allLibs( resource );

        System.out.println( "scope_AvPMmodelSet_libs libs=" + libs );
        return Scopes.scopeFor( libs );
}


which translates to "if you need a value for the "libs" property of a AvPMmodelSet, find all available libraries.

Regards,

A. Digulla

[Updated on: Tue, 24 July 2012 08:47]

Report message to a moderator

Re: Xtext and scopes [message #897540 is a reply to message #897536] Tue, 24 July 2012 08:51 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Aaron,

Am 24.07.12 14:44, schrieb Aaron Digulla:
> Sebastian Zarnekow wrote on Tue, 24 July 2012 11:13
>> Do your files reside in a Java project in a source folder (in the
>> Eclipse-sense, e.g. is src/main/resources a source folder)?
>
>
> In my unit test, the two source files are added to one resource set
> using two different URLs. On contains the library definition, the second
> resource contains a model which references the library. Here is the code:
>
>
> val rset = new SynchronizedXtextResourceSet()
>
> parser.resourceSet( rset ).uri( "base.mset" ).input("lib base {}").parse()
> parser.resourceSet( rset ).uri( "test.mset" ).input('''
> ModelSet mset {
> lib base base;
> }''')
> .expectError( "ERROR:duplicate lib entry 'base' (test.mset line : 2)" )
>

Did you try to use a configured resource set e.g. by using
Provider<XtextResourceSet> ?

>
> When I run the Eclipse application, all model sets are in the same (the
> current) Java project. I check the .project file and it has the Java
> nature.

Are these files in a source folder (in the Eclipse sense)?

>
> Might be related: Sometimes, I see errors in the editor but the problems
> view is empty. Sometimes, those errors go away when I close+open the
> editor again. Or I have to modify + save the file.

This indicates that the files are not visible to Eclipse, e.g. just
contained in a folder but not in a source folder. This explains why you
see only one container in your logs.

>
> Sebastian Zarnekow wrote on Tue, 24 July 2012 11:13
>> Is the class-path different when you run those tests with Maven or as
>> junit test from within Eclipse? I'm not too familiar with Tycho/Maven...
>
>
> The tests in Eclipse are missing two plugins which might be relevant:
>
> org.eclipse.xtext.ecore-2.3.0.v201206120633.jar
> org.eclipse.xtext.smap-2.3.0.v201206120633.jar

Those don't matter for your scenario.

>
> but adding those two to the classpath has no effect :-/ But apparently,
> Tycho runs the tests as headless JUnit plugin tests - which I can't get
> to work inside of Eclipse :(
>
> So I'm stuck with three different environments and three different
> behaviors and no way to use the differences to figure out what's wrong :(
>
> Sebastian Zarnekow wrote on Tue, 24 July 2012 11:13
>> Is the class-path Where did you add the allModels(Resource) code? How
>> do you invoke it?
>
>
> It's part of a custom scope provider:
>
>
> public class MSetDslScopeProvider extends
> AbstractDeclarativeScopeProvider {
> public IScope scope_AvPMmodelSet_libs( AvPMmodelSet modelSet,
> EReference ref ) {
> Resource resource = modelSet.eResource();
> List<AvPMLib> libs = allLibs( resource );
>
> System.out.println( "scope_AvPMmodelSet_libs libs=" + libs );
> return Scopes.scopeFor( libs );
> }
>

It's likely that this code breaks the semantics since the libs are most
likely proxies thus they don't have any values set. It's not possible to
compute a meaningful name from them. This problem will manifest itself
as soon as you put the files into a Java source folder. The method
pretty much does what the defaults will do for you anyway so it's save
to return delegateGetScope() instead.

Regards,
Sebastian

>
> which translates to "if you need a value for the "libs" property of a
> AvPMmodelSet, find all available libraries.
>
> Regards,
>
> A. Digulla
Re: Xtext and scopes [message #897705 is a reply to message #897540] Wed, 25 July 2012 03:03 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Tue, 24 July 2012 14:51

>> Do your files reside in a Java project in a source folder (in the
>> Eclipse-sense, e.g. is src/main/resources a source folder)?
>
>
> In my unit test, the two source files are added to one resource set
> using two different URLs. On contains the library definition, the second
> resource contains a model which references the library. Here is the code:
>
>
> val rset = new SynchronizedXtextResourceSet()
>
> parser.resourceSet( rset ).uri( "base.mset" ).input("lib base {}").parse()
> parser.resourceSet( rset ).uri( "test.mset" ).input('''
> ModelSet mset {
> lib base base;
> }''')
> .expectError( "ERROR:duplicate lib entry 'base' (test.mset line : 2)" )
>

Did you try to use a configured resource set e.g. by using
Provider<XtextResourceSet> ?


No. Do you have a code sample how to do that in a unit test?

Sebastian Zarnekow wrote on Tue, 24 July 2012 14:51

> When I run the Eclipse application, all model sets are in the same (the
> current) Java project. I check the .project file and it has the Java
> nature.

Are these files in a source folder (in the Eclipse sense)?


Yes. I checked and Eclipse copies them to the classes/output folder which it wouldn't if they were not considered "sources".

Sebastian Zarnekow wrote on Tue, 24 July 2012 14:51

> Might be related: Sometimes, I see errors in the editor but the problems
> view is empty. Sometimes, those errors go away when I close+open the
> editor again. Or I have to modify + save the file.

This indicates that the files are not visible to Eclipse, e.g. just
contained in a folder but not in a source folder. This explains why you
see only one container in your logs.


Or it's a problem in the global scope container which gets out of sync with the files in the workspace.

Sebastian Zarnekow wrote on Tue, 24 July 2012 14:51

>> Is the class-path different when you run those tests with Maven or as
>> junit test from within Eclipse? I'm not too familiar with Tycho/Maven...
>
>
> The tests in Eclipse are missing two plugins which might be relevant:
>
> org.eclipse.xtext.ecore-2.3.0.v201206120633.jar
> org.eclipse.xtext.smap-2.3.0.v201206120633.jar

Those don't matter for your scenario.


Damn Sad

Sebastian Zarnekow wrote on Tue, 24 July 2012 14:51

>> Is the class-path Where did you add the allModels(Resource) code? How
>> do you invoke it?
> It's part of a custom scope provider:
It's likely that this code breaks the semantics since the libs are most
likely proxies thus they don't have any values set. It's not possible to
compute a meaningful name from them. This problem will manifest itself
as soon as you put the files into a Java source folder. The method
pretty much does what the defaults will do for you anyway so it's save
to return delegateGetScope() instead.


Well, I added the method to know when Xtext wants the names and to see how Xtext would compute the values.

Removing it has no effect except but that I don't understand anymore what happens and I lose my only place to influence it.

Stepping through my code, I noticed that it throws ClassCastException which is swallowed in PolymorphicDispatcher.NullErrorHandler. Just like this guy, I'm unable to change the default binding Sad Maybe the guys at stackoverflow.com can help.

After fixing the error, the code still fails which worries me a bit. I mean I modeled it after your input and code I found in Xtext and, as you said, it should do what delegateGetScope() does - but that's not the case.

Oh well. delegateGetScope() sometimes works, sometime, it doesn't. Right now, I see this odd behavior:

When I call IContainer.getResourceDescriptionCount() in my unit test, I get 2. But when I call .getResourceDescriptions(), I get an empty list. Stepping through the code, I end up in ResourceSetBasedResourceDescriptions:

	public IResourceDescription getResourceDescription(URI uri) {
		Resource resource = resourceSet.getResource(uri, false);
		if (resource == null)
			return null;
		IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
		if (resourceServiceProvider == null)
			return null;
		Manager manager = resourceServiceProvider.getResourceDescriptionManager();
		if (manager==null)
			return null;
		return manager.getResourceDescription(resource);
	}


The URI is correct but registry.getResourceServiceProvider(uri) returns null.

Stepping further through the code, I find that Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put() was never called :-/ Looking further, I see that InjectorProviderCustom in the domainmodel example got a bit more complicated.

I copied the code and that showed me that the call to createInjectorAndDoEMFRegistration() was lost when I updated the unit tests for Xtext 2.3.0. This inspired me to write the following test (in Xtend):

	@Test
	def void testExtensionIsRegistered() {
		assertNotNull( "Did you call *Setup.createInjectorAndDoEMFRegistration()?"
			, Resource$Factory$Registry::INSTANCE.getExtensionToFactoryMap().get("mset")
		);
	}


It would be nice if I could reuse the string constants in *StandaloneSetupGenerated (see bug 385870)

Now the unit tests work in Eclipse and from the command line. One down, two to go.

Trying to run the tests as JUnit Plugin Tests still fails with "java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "com/google/inject/Injector"" :-/

On the positive side, running the domaindmodel tests also fails, so it's a bug in the current implementation of org.eclipse.xtext.example.domainmodel.tests.InjectorProviderCustom. See bug 383889

Which leaves the plug-in when running it inside of Eclipse. At the moment, it works. I'll just leave the debug output in there to have more information when it fails again.

Regards,

A. Digulla
Re: Xtext and scopes [message #897726 is a reply to message #897705] Wed, 25 July 2012 03:30 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Am 25.07.12 09:03, schrieb Aaron Digulla:
> On the positive side, running the domaindmodel tests also fails, so it's
> a bug in the current implementation of
> org.eclipse.xtext.example.domainmodel.tests.InjectorProviderCustom. See
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=383889

The strange thing is that I cannot reproduce this on my machine.
The tests fail due to outdated assertions but I don't see the
LinkageError. Are you hundert percent sure that PDE does not put guice
on the classpath of your project, twice, in two different versions? Did
you expand the PDE classpath container and checked for guice? I assume
that you have a maven classpath container, too. Does it add another
Guice jar with an Injector in it?

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Xtext and scopes [message #897727 is a reply to message #897705] Wed, 25 July 2012 03:33 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Am 25.07.12 09:03, schrieb Aaron Digulla:
>> Did you try to use a configured resource set e.g. by using
>> Provider<XtextResourceSet> ?
>
>
> No. Do you have a code sample how to do that in a unit test?

@Inject Provider<XtextResourceSet> resourceSetProvider

But I doubt that it would make any difference in the runtime scenario.
Looks like I was on the wrong track.
Re: Xtext and scopes [message #897739 is a reply to message #897705] Wed, 25 July 2012 03:52 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Am 25.07.12 09:03, schrieb Aaron Digulla:
>> Are these files in a source folder (in the Eclipse sense)?
>
>
> Yes. I checked and Eclipse copies them to the classes/output folder
> which it wouldn't if they were not considered "sources".

Just to be 100% sure: It's not maven that copies them to class/output?
Do you see the entry Build Path->Remove from Build Path if you right
click the resources folder?

>> This indicates that the files are not visible to Eclipse, e.g. just
> contained in a folder but not in a source folder. This explains why
> you see only one container in your logs.
>
> Or it's a problem in the global scope container which gets out of
sync with the files in the workspace.

Well that mechanism is used everywhere in Xtext so I doubt that it is
seriously broken.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Xtext and scopes [message #897788 is a reply to message #897726] Wed, 25 July 2012 05:04 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Wed, 25 July 2012 09:30

> On the positive side, running the domaindmodel tests also fails, so it's
> a bug in the current implementation of
> org.eclipse.xtext.example.domainmodel.tests.InjectorProviderCustom. See
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=383889

The strange thing is that I cannot reproduce this on my machine.
The tests fail due to outdated assertions but I don't see the
LinkageError.


Let's make sure we use the same project. I get one failed test (compareGeneratedJava) because StringBuilder has been replaced with ToStringHelper. Does the same happen on your side?

Sebastian Zarnekow wrote on Wed, 25 July 2012 09:30

Are you hundert percent sure that PDE does not put guice
on the classpath of your project, twice, in two different versions?


Yes. There is only one version on the classpath: com.google.inject_3.0.0.v201203062045.jar

But as I said in the bug, maybe XtextRunner gets the type from two different classloaders. OTOH, that should probably cause ClassCastException and not LinkageError :-/

One odd fact: The JAR com.google.inject_3.0.0.v201203062045.jar from emft-mwe-Update-2.3.0.zip and from tmf-xtext-Update-2.3.0.zip (archived update sites downloaded from eclipse.org) differs. From my past experience, this is because the JAR was signed by different builds. I checked the contents (file names+sizes) and they are the same.

Sebastian Zarnekow wrote on Wed, 25 July 2012 09:30

Did you expand the PDE classpath container and checked for guice?


Yep. I'd send you the content of the "Plug-in Dependencies" view (which you get by clicking on "Show the plug-in dependency hierarchy") but there is no way to copy the list Sad

Sebastian Zarnekow wrote on Wed, 25 July 2012 09:30

I assume
that you have a maven classpath container, too. Does it add another
Guice jar with an Injector in it?


No, I didn't modify the sample project after creating it with the "New..." wizard.

Regards,

A. Digulla
Re: Xtext and scopes [message #897798 is a reply to message #897739] Wed, 25 July 2012 05:17 Go to previous message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Sebastian Zarnekow wrote on Wed, 25 July 2012 09:52

>> Are these files in a source folder (in the Eclipse sense)?
> Yes. I checked and Eclipse copies them to the classes/output folder
> which it wouldn't if they were not considered "sources".

Just to be 100% sure: It's not maven that copies them to class/output?
Do you see the entry Build Path->Remove from Build Path if you right
click the resources folder?


Yes. I left the debug code in my plug-in. Right now, it works (no errors) but since I don't know for sure what triggers it, I don't have a test case.

Sebastian Zarnekow wrote on Wed, 25 July 2012 09:52

>> This indicates that the files are not visible to Eclipse, e.g. just
> contained in a folder but not in a source folder. This explains why
> you see only one container in your logs.
>
> Or it's a problem in the global scope container which gets out of
> sync with the files in the workspace.

Well that mechanism is used everywhere in Xtext so I doubt that it is
seriously broken.


I don't think it's a bug as such. Xtext's code is written resilient. If something unexpected happens (like when there is no resource factory), Xtext just returns null instead of throwing an exception.

One good example is the error handler in PolymorphicDispatcher. The default is to ignore all errors. This means that exceptions in my scope methods get swallowed. When I enabled logging for these errors, I got many NoSuchMethodExceptions which probably explains why it was disabled.

But this causes problems when I make a mistake. Ignoring NoSuchMethodExceptions in my custom error handler is also dangerous because my code could throw this exception as well (and I can't check specifically for your exception because it's private).

So the design of Xtext makes the code very resilient against crashing but it also interferes with finding bugs because it never crashes even when something is severely broken.

Regards,

A. Digulla
Previous Topic:Json empty object serialization problem
Next Topic:semantic highlighting stopped working for comments ?
Goto Forum:
  


Current Time: Thu Aug 21 18:10:25 EDT 2014

Powered by FUDForum. Page generated in 0.04184 seconds