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<T>) 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<T>) createdTypeData.getCreatedTypeConstructor().getBaseType();


            BeanManagerImpl manager = ((BeanManagerProxy) beanManager).delegate();
            EnhancedAnnotatedConstructor<T> constructor = (EnhancedAnnotatedConstructor<T>) manager
                .createEnhancedAnnotatedType(declaringComponentClass)
                .getEnhancedConstructors()
                .stream().findAny().get();

            ConstructorInjectionPoint<T> actualInjectionPoint = InjectionPointFactory.instance()
                .createConstructorInjectionPoint(bean, declaringComponentClass, constructor, manager);
            ThreadLocalStackReference<InjectionPoint> 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