Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Final variable not getting injected
Final variable not getting injected [message #879424] Thu, 31 May 2012 07:47 Go to next message
Vishal seth is currently offline Vishal sethFriend
Messages: 32
Registered: April 2010
Member
Hi,

Can final variables be injected? Facing an issue in DynamicResourceClusteringPolicy for MINIMUM_PERCENT_FREE_MEMORY variable. Injecting this by using org.eclipse.xtext.ui.shared.overridingGuiceModule extension class.

Regards
Vishal
Re: Final variable not getting injected [message #879429 is a reply to message #879424] Thu, 31 May 2012 07:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

i cannot reproduce your problem

	public void configureDynamicResourceClusteringPolicy(Binder binder) {
		binder.bind(Long.class)
				.annotatedWith(
						Names.named(DynamicResourceClusteringPolicy.MINIMUM_PERCENT_FREE_MEMORY))
				.toInstance(50L);
	}


works perfect for me.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Final variable not getting injected [message #879907 is a reply to message #879429] Fri, 01 June 2012 05:17 Go to previous messageGo to next message
Vishal seth is currently offline Vishal sethFriend
Messages: 32
Registered: April 2010
Member
Hi Christian,

When inspected in debug mode it gives the correct value bounded. But while logging it gives the default value. How did you ascertain it was correctly picked up while processing?

Regards
Vishal
Re: Final variable not getting injected [message #879936 is a reply to message #879907] Fri, 01 June 2012 06:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

what do you mean by logging?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Final variable not getting injected [message #879963 is a reply to message #879936] Fri, 01 June 2012 07:56 Go to previous messageGo to next message
Vishal seth is currently offline Vishal sethFriend
Messages: 32
Registered: April 2010
Member
Hi,

System.out.println/Log. I override the DynamicResourceClusteringPolicy class to check the behavior.

Regards
Vishal
Re: Final variable not getting injected [message #879972 is a reply to message #879963] Fri, 01 June 2012 08:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
can you share your code?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Final variable not getting injected [message #879980 is a reply to message #879972] Fri, 01 June 2012 08:25 Go to previous messageGo to next message
Vishal seth is currently offline Vishal sethFriend
Messages: 32
Registered: April 2010
Member
Hi,

@SuppressWarnings("restriction")
public class TestDynamicResourceClusteringPolicy extends DynamicResourceClusteringPolicy
{
	public static final String TEST_MINIMUM_PERCENT_FREE_MEMORY = "test.TestDynamicResourceClusteringPolicy.minimumPercentFreeMemory";

	@Inject(optional = true)
	@Named(TEST_MINIMUM_PERCENT_FREE_MEMORY)
	private final long minimumPercentFreeMemory = 15l;

	public boolean continueProcessing(ResourceSet resourceSet, URI next, int alreadyProcessed)
	{
		System.out.println("TestDynamicResourceClusteringPolicy.continueProcessing()" + minimumPercentFreeMemory);
		return super.continueProcessing(resourceSet, next, alreadyProcessed);
	}

}

@SuppressWarnings("restriction")
public class TestGuiceOverridingSharedModule implements Module
{
	@Override
	public void configure(Binder binder)
	{
		Long minimumPercentFreeMemory = 25l;
		binder.bind(IResourceClusteringPolicy.class).to(TestDynamicResourceClusteringPolicy.class);
		binder.bind(Long.class).annotatedWith(Names.named(TestDynamicResourceClusteringPolicy.TEST_MINIMUM_PERCENT_FREE_MEMORY))
		.toInstance(minimumPercentFreeMemory);
	}
}


Re: Final variable not getting injected [message #879993 is a reply to message #879980] Fri, 01 June 2012 08:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
hmm strange. maybe sebastian or sven can give us some explaination

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Final variable not getting injected [message #880011 is a reply to message #879993] Fri, 01 June 2012 09:23 Go to previous messageGo to next message
Vishal seth is currently offline Vishal sethFriend
Messages: 32
Registered: April 2010
Member
hi,

Can this be possible due to this particular child grammar extending from other grammar? Another issue which popped while putting the overriding guice entry in the base grammar was bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=279913. Hence the plugin entry & the class was entered in the child grammar & not the base one.

Regards
Vishal
Re: Final variable not getting injected [message #880163 is a reply to message #879993] Fri, 01 June 2012 14:43 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Am 01.06.12 10:56, schrieb Christian Dietrich:
> hmm strange. maybe sebastian or sven can give us some explaination

I'd assume that Long.class != Long.TYPE.
You try to bind a primitive long annotated with .. but what you register
in your module is an instanceof of the wrapper type Long.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Final variable not getting injected [message #880164 is a reply to message #879980] Fri, 01 June 2012 14:44 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
For the sake of completeness, you may want to use
bindConstant().annotatedWith(..).to(25l)

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


Am 01.06.12 10:25, schrieb Vishal seth:
> Hi,
>
>
> @SuppressWarnings("restriction")
> public class TestDynamicResourceClusteringPolicy extends
> DynamicResourceClusteringPolicy
> {
> public static final String TEST_MINIMUM_PERCENT_FREE_MEMORY =
> "test.TestDynamicResourceClusteringPolicy.minimumPercentFreeMemory";
>
> @Inject(optional = true)
> @Named(TEST_MINIMUM_PERCENT_FREE_MEMORY)
> private final long minimumPercentFreeMemory = 15l;
>
> public boolean continueProcessing(ResourceSet resourceSet, URI next, int
> alreadyProcessed)
> {
> System.out.println("TestDynamicResourceClusteringPolicy.continueProcessing()"
> + minimumPercentFreeMemory);
> return super.continueProcessing(resourceSet, next, alreadyProcessed);
> }
>
> }
>
> @SuppressWarnings("restriction")
> public class TestGuiceOverridingSharedModule implements Module
> {
> @Override
> public void configure(Binder binder)
> {
> Long minimumPercentFreeMemory = 25l;
> binder.bind(IResourceClusteringPolicy.class).to(TestDynamicResourceClusteringPolicy.class);
>
> binder.bind(Long.class).annotatedWith(Names.named(TestDynamicResourceClusteringPolicy.TEST_MINIMUM_PERCENT_FREE_MEMORY))
>
> .toInstance(minimumPercentFreeMemory);
> }
> }
>
>
>
Re: Final variable not getting injected [message #881190 is a reply to message #880164] Mon, 04 June 2012 04:51 Go to previous message
Vishal seth is currently offline Vishal sethFriend
Messages: 32
Registered: April 2010
Member
Hi,

Even this way of binding does not work for final variable.

Regards
Vishal
Previous Topic:Xtext vs ANTLR syntactic predicates
Next Topic:[FIXED] [NOT AN ISSUE] Problem with validator
Goto Forum:
  


Current Time: Wed Oct 21 14:55:01 GMT 2020

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

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

Back to the top