Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Final variable not getting injected
Final variable not getting injected [message #879424] Thu, 31 May 2012 03:47 Go to next message
Eclipse UserFriend
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 03:58 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Final variable not getting injected [message #879907 is a reply to message #879429] Fri, 01 June 2012 01:17 Go to previous messageGo to next message
Eclipse UserFriend
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 02:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what do you mean by logging?

~Christian
Re: Final variable not getting injected [message #879963 is a reply to message #879936] Fri, 01 June 2012 03:56 Go to previous messageGo to next message
Eclipse UserFriend
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 04:09 Go to previous messageGo to next message
Eclipse UserFriend
can you share your code?
Re: Final variable not getting injected [message #879980 is a reply to message #879972] Fri, 01 June 2012 04:25 Go to previous messageGo to next message
Eclipse UserFriend
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 04:56 Go to previous messageGo to next message
Eclipse UserFriend
hmm strange. maybe sebastian or sven can give us some explaination
Re: Final variable not getting injected [message #880011 is a reply to message #879993] Fri, 01 June 2012 05:23 Go to previous messageGo to next message
Eclipse UserFriend
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 10:43 Go to previous messageGo to next message
Eclipse UserFriend
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 10:44 Go to previous messageGo to next message
Eclipse UserFriend
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 00:51 Go to previous message
Eclipse UserFriend
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: Fri Jul 04 17:42:43 EDT 2025

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

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

Back to the top