Injected Index Class is always Null in my DerivedStateComputer [message #1810041] |
Mon, 29 July 2019 15:13  |
Eclipse User |
|
|
|
This is both a general and an Xtext specific question.
I'm working on defining a DSL for an already pre-defined file format. The pre-defined file format was not built by a modeling person and thus has many ambiguities and sometime a lack of defined containment hierarchy. The overall containment hierarchy for this tool appears to be their Python script itself.
For several reasons, I'm having to use a DerivedStateComputer to declare real objects on the fly in the AST based on some ambiguous information. As I'm in a particular resource, I want to declare a derived object, but I need to check "somewhere" that this object has not already been derived. The trouble is, if it's been derived and declared, it was done in another resource.
To combat the "declared in another resource problem", I'm trying to use the index. So far, using this index, I've been successful in seeing objects of interest declared in other resources (during linking and scoping mainly) . Specifically I've coded an index much like Lorenzo's:
https://github.com/LorenzoBettini/packtpub-xtext-book-2nd-examples/blob/master/org.example.smalljava.parent/org.example.smalljava/src/org/example/smalljava/scoping/SmallJavaIndex.xtend
My problem current (and I'm probably not aware of all of them), is I'm trying to @Inject this index into my DerivedStateComputer so I can see all the other visible objects that may have already been derived.
But the injected index is always null. I can't get to it.
private static class DerivedStateComputer implements IDerivedStateComputer {
@Inject
@Extension
private PBXIndex pbxIndex;
<some time later>
// Get all existing connections from the index
if (this.pbxIndex != null) {
Map<QualifiedName, IEObjectDescription> existingConnections = this.pbxIndex.getVisibleExternalConnectionsDescriptions(pbxDoc);
this.pbxIndex is always null and I can't access the index. My ScopeProvider can access the index (ScopeProvider is xtend) but my DerivedStateComputer (Java) can't see to get a non-null injection.
Does this index not existing during if (!preLinkingPhase)
|
|
|
|
|
|
Re: Injected Index Class is always Null in my DerivedStateComputer [message #1810047 is a reply to message #1810046] |
Mon, 29 July 2019 22:52  |
Eclipse User |
|
|
|
I think I got it now.
I have to bind my DerivedStateComputer into my RuntimeMoudule like this:
override bindXtextResource () {
PBXResource
}
def Class<? extends IDerivedStateComputer> bindIDerivedStateComputer() {
DerivedStateComputer
}
Which meant I had to refactor my DerivedStateComputer class into its own file etc...
But once I got that binding in, I think it took care of whatever constructor stuff needed to happen in order to get the injection to work. My injected field is no longer null.
|
|
|
Powered by
FUDForum. Page generated in 0.03403 seconds