Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Injected Index Class is always Null in my DerivedStateComputer
Injected Index Class is always Null in my DerivedStateComputer [message #1810041] Mon, 29 July 2019 19:13 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
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 #1810042 is a reply to message #1810041] Mon, 29 July 2019 19:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Are you sure you don't create the computer with new instead of injection?
Can you debug the constructor .
Who calls it


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Injected Index Class is always Null in my DerivedStateComputer [message #1810044 is a reply to message #1810042] Mon, 29 July 2019 19:46 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
Christian Dietrich wrote on Mon, 29 July 2019 15:17
Are you sure you don't create the computer with new instead of injection?
Can you debug the constructor .
Who calls it


I'm not entirely sure how my DerivedStateComputer gets constructed to be honest:

My DerivedStateComputer is bound in my RuntimeModule:

   override bindXtextResource () {
      PBXResource
   }
   
   def Class<? extends IResourceDescription.Manager> bindIResourceDescriptionManager () {
      DerivedStateAwareResourceDescriptionManager
   }



And the PBXResource code looks like this (partial):

public class PBXResource extends DerivedStateAwareResource {
		
	public PBXResource() {
		setDerivedStateComputer(new DerivedStateComputer());
	}
			
	@Override
	public void installDerivedState(boolean preIndexingPhase) {
		super.installDerivedState(preIndexingPhase);
		
	}
			
	
	private static class DerivedStateComputer implements IDerivedStateComputer {
		
		@Inject
		@Extension
		private PBXIndex pbxIndex;

		@Override
		public void installDerivedState(DerivedStateAwareResource resource, boolean preLinkingPhase) {
			
			if (!preLinkingPhase) {
	
Re: Injected Index Class is always Null in my DerivedStateComputer [message #1810046 is a reply to message #1810044] Mon, 29 July 2019 20:32 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
It's not clear to me why mimicking the xtend-gen/ version of my ScopeProvider - in the way that it injects this index and then proceeds to use it is not working. If I don't inject it and just call a new on PBXIndex, then it doens't get any of it's required injections either and it all fails in a different way.
Re: Injected Index Class is always Null in my DerivedStateComputer [message #1810047 is a reply to message #1810046] Tue, 30 July 2019 02:52 Go to previous message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 268
Registered: May 2012
Senior Member
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.
Previous Topic:Background Color of Embedded Xtext editor does not follow dark theme
Next Topic:Validation: Proper way to check for errors in related resources
Goto Forum:
  


Current Time: Fri Apr 19 20:24:39 GMT 2024

Powered by FUDForum. Page generated in 0.03271 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top