Re: [weld-dev] Proper way to get to EnhancedAnnotatedConstructor (CDI autofactories implementation)

2016-08-15 Thread Jan-Willem Gmelig Meyling
Hi Martin,


Thanks for your response. These are obviously my first steps with CDI and Weld, 
so I wasn’t familiar with the extension SPI.  I will first try to improve the 
logic getting to the construction point and then see how much of the code I can 
make CDI vendor unspecific.

Jan-Willem

> On 09 Aug 2016, at 14:05, Martin Kouba  wrote:
> 
> Hi Jan-Willem,
> 
> first of all it's not a good idea to depend on Weld internals - the 
> implementation can change any time without any warning. On the other 
> hand, I understand that you're just "patching" an existing extension.
> 
> WRT the way to get to the EnhancedAnnotatedConstructor - there is 
> org.jboss.weld.injection.InjectionPointFactory.createConstructorInjectionPoint(Bean,
>  
> EnhancedAnnotatedType, BeanManagerImpl) which itself performs the 
> lookup (and attempts to find a bean constructor as defined in 3.9. Bean 
> constructors).
> 
> Moreover, you should probably use a "silent" instance of 
> InjectionPointFactory, otherwise ProcessInjectionPoint event will be 
> fired for each injection point created.
> 
> Also I would recommend to analyze the extension code so that it's clear 
> what exactly is missing in the CDI 1.2 extension SPI (a lot of stuff was 
> added since CDI 1.0/Weld 1). This will help improve the CDI 2.0 SPI 
> (under development).
> 
> Martin
> 
> Dne 8.8.2016 v 17:36 Jan-Willem Gmelig Meyling napsal(a):
>> Hello everyone,
>> 
>> 
>> I am in the process of patching the softwaremill-common CDI extensions
>> [1] from Weld 1.1 to Weld 2.x. I am currently working on their extension
>> for autofactories. I stumbled upon the following piece of code I would
>> like to migrate:
>> 
>>CurrentInjectionPoint currentInjectionPoint =
>> Container.instance().services().get(CurrentInjectionPoint.class);
>> 
>> currentInjectionPoint.push(ConstructorInjectionPoint.of(bean,
>> (WeldConstructor) createdTypeData.getCreatedTypeConstructor()));
>>instance = newInstance(parameters);
>>currentInjectionPoint.pop();
>> 
>> Source: [2]
>> 
>> I see how the pop should now be invoked on the
>> `ThreadLocalStackReference` returned by the push method. I have also
>> found the InjectionPointFactory#createConstructorInjectionPoint(Bean,
>> Class, EnhancedAnnotatedConstructor, BeanManagerImpl) method [3]. Now I
>> am wondering how I can get to the `EnhancedAnnotatedConstructor`, as the
>> approach I am currently using feels plain wrong.
>> 
>> My code:
>> 
>>CurrentInjectionPoint currentInjectionPoint =
>> Container.instance().services().get(CurrentInjectionPoint.class);
>>Class declaringComponentClass = (Class)
>> createdTypeData.getCreatedTypeConstructor().getBaseType();
>> 
>> 
>>BeanManagerImpl manager = ((BeanManagerProxy)
>> beanManager).delegate();
>>EnhancedAnnotatedConstructor constructor =
>> (EnhancedAnnotatedConstructor) manager
>>.createEnhancedAnnotatedType(declaringComponentClass)
>>.getEnhancedConstructors()
>>.stream().findAny().get();
>> 
>>ConstructorInjectionPoint actualInjectionPoint =
>> InjectionPointFactory.instance()
>>.createConstructorInjectionPoint(bean,
>> declaringComponentClass, constructor, manager);
>>ThreadLocalStackReference ref =
>> currentInjectionPoint.push(actualInjectionPoint);
>>instance = newInstance(parameters);
>> 
>> 
>> My code is also available on Github at [4]. My question is also posted
>> on Stackoverflow [5], so points will be awarded for the answer.
>> 
>> Thanks in advance!
>> 
>> Jan-Willem Gmelig Meyling
>> 
>> 
>> 
>> 
>> [1]
>> https://github.com/softwaremill/softwaremill-common/tree/master/softwaremill-cdi
>> [2] 
>> https://github.com/softwaremill/softwaremill-common/blob/master/softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/FactoryInvocationHandler.java#L35-L48
>> [3]
>> http://javadox.com/org.jboss.weld.servlet/weld-servlet/2.3.1.Final/org/jboss/weld/injection/InjectionPointFactory.html#createConstructorInjectionPoint-javax.enterprise.inject.spi.Bean-java.lang.Class-org.jboss.weld.annotated.enhanced.EnhancedAnnotatedConstructor-org.jboss.weld.manager.BeanManagerImpl-
>> [4] 
>> https://github.com/JWGmeligMeyling/cdi-autofactories/blob/8346cf269d73a8bd455c12c4d467df7bcb8f3920/src/main/java/com/softwaremill/common/cdi/autofactory/extension/FactoryInvocationHandler.java#L50-L60
>> [5] 
>> http://stackoverflow.com/questions/38436110/proper-way-to-get-enhancedannotatedconstructor
>> 
>> 
>> 
>> 
>> ___
>> weld-dev mailing list
>> weld-dev@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/weld-dev
>> 
> 
> -- 
> Martin Kouba
> Software Engineer
> Red Hat, Czech Republic
> ___
> weld-dev mailing list
> weld-dev@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev


Re: [weld-dev] How to avoid this warning message?

2016-08-15 Thread Martin Kouba
Hi John,

looks like a bug. Weld does not consider extended interfaces. I've 
created WELD-2221 [1] to track this issue.

Martin

[1]
https://issues.jboss.org/browse/WELD-2221


Dne 15.8.2016 v 01:24 John D. Ament napsal(a):
> Yep, it was the inheritance.  Any idea why though?
>
> https://git1-us-west.apache.org/repos/asf?p=deltaspike.git;a=blobdiff;f=deltaspike/modules/data/api/src/main/java/org/apache/deltaspike/data/api/AbstractEntityRepository.java;h=529c474d8a84837ccfb2fb6693ec651f65ff8b3e;hp=933c136abf58efde4bba7dc5cf8944d711d92d40;hb=bb9abfcc;hpb=6d4fbd8e6a50555ed70c06b4a10669e7e6f403d1
>
> John
>
> On Sun, Aug 14, 2016 at 7:03 PM John D. Ament  > wrote:
>
> 
> https://lists.apache.org/thread.html/8edcc676c2dbede50f7e75cc56c4d78d260357df527347a1ff155402@%3Cusers.deltaspike.apache.org%3E
>  for
> some reference
>
> Somewhere between 1.6 and 1.7 this started popping up on DS.  Even
> though these methods are defined in the class hierarchy, they are
> transitively inherited.  Is DS not picking them up because
> AbstractEntityRepository doesn't directly implement the other
> interfaces?
>
> John
>
>
>
> ___
> weld-dev mailing list
> weld-dev@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev
>

-- 
Martin Kouba
Software Engineer
Red Hat, Czech Republic
___
weld-dev mailing list
weld-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev