Referencing EObjects which haven't got a name - the right way #3181
-
Hi, In the DSL I'm working on I want to allow entities to override other entities. See the example grammar and entity declarations presented here: eclipse/xtext-website#55 The main point is that I want to be able to cross-reference some entities which have got no name. These entities do however override some other entities (see the grammar: an entity may not have a name only if it overrides another entity), so my first naive idea was to implement a custom IDerivedStateComputer that sets the I have now solved it in a completely different way that does not require resolving any cross-reference and/or tampering with the I then had to customize the scope provider to use the last segment of an EObject’s qualified name as the identifier of that EObject for solving cross-references. This way, nothing changes for all EObjects with a name, while additionally I can finally reference EObjects of type Entity which override another Entity but have got no name. An excerpt of my code follows: return Scopes.scopeFor(iterable,
QualifiedName.wrapper(eObject -> {
final QualifiedName qualifiedName = qualifiedNameProvider.getFullyQualifiedName(eObject);
if (qualifiedName == null) return null;
return qualifiedName.getLastSegment();
}),
IScope.NULLSCOPE); My question is: does this look like a proper way to achieve what I want to achieve? Any feedback on it would be very welcome :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Can you elaborate your scope provider logic. besides that it makes sense But this depends on what you exactly do |
Beta Was this translation helpful? Give feedback.
i guess then the solution is fine