@@ -616,16 +616,6 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
616616 });
617617 }
618618
619- @ SuppressWarnings ("unused" )
620- private void processProducerMethod (@ Observes final ProcessProducerMethod processProducerMethod ) {
621- typesSeenBeforeValidation .addAll (processProducerMethod .getAnnotatedProducerMethod ().getTypeClosure ());
622- }
623-
624- @ SuppressWarnings ("unused" )
625- private void processProducerField (@ Observes final ProcessProducerField processProducerField ) {
626- typesSeenBeforeValidation .addAll (processProducerField .getAnnotatedProducerField ().getTypeClosure ());
627- }
628-
629619 @ SuppressWarnings ("unused" )
630620 private void afterTypeDiscovery (@ Observes final AfterTypeDiscovery afterTypeDiscovery ) {
631621 final List <Class <?>> interceptors = afterTypeDiscovery .getInterceptors ();
@@ -673,11 +663,10 @@ public Object intercept(final InvocationContext ic) throws Exception {
673663 private void processInjectionTarget (@ Observes final ProcessInjectionTarget event ) {
674664 final InjectionTarget it = event .getInjectionTarget ();
675665 final Class <?> componentClass = event .getAnnotatedType ().getJavaClass ();
676- typesSeenBeforeValidation .add (event .getAnnotatedType ().getBaseType ());
677666
678- final Set <InjectionPoint > filteredInjectionPoints = filterHk2InjectionPointsOut (it .getInjectionPoints ());
667+ final Set <InjectionPoint > cdiInjectionPoints = filterHk2InjectionPointsOut (it .getInjectionPoints ());
679668
680- for (final InjectionPoint injectionPoint : filteredInjectionPoints ) {
669+ for (final InjectionPoint injectionPoint : cdiInjectionPoints ) {
681670 final Member member = injectionPoint .getMember ();
682671 if (member instanceof Field ) {
683672 addInjecteeToSkip (componentClass , fieldsToSkip , (Field ) member );
@@ -702,45 +691,42 @@ public Set getInjectionPoints() {
702691 @ Override
703692 public Set getInjectionPoints () {
704693 // Inject CDI beans into JAX-RS resources/providers/application.
705- return filteredInjectionPoints ;
694+ return cdiInjectionPoints ;
706695 }
707696 });
708697 }
709698 }
710699
711- // TODO: refactor the following method
712700 private Set <InjectionPoint > filterHk2InjectionPointsOut (final Set <InjectionPoint > originalInjectionPoints ) {
713701 final Set <InjectionPoint > filteredInjectionPoints = new HashSet <InjectionPoint >();
714702 for (InjectionPoint ip : originalInjectionPoints ) {
715703 final Type injectedType = ip .getType ();
716- if (injectedType instanceof Class <?>) {
717- if (!isJerseyOrDependencyType ((Class <?>)injectedType )
718- && !(customHk2TypesProvider != null && customHk2TypesProvider .getHk2Types ().contains (injectedType ))) {
719- filteredInjectionPoints .add (ip );
720- } else {
721- //remember the type, we would need to mock it's CDI binding at runtime
722- hk2ProvidedTypes .add (injectedType );
723- }
704+ if (customHk2TypesProvider != null && customHk2TypesProvider .getHk2Types ().contains (injectedType )) {
705+ //remember the type, we would need to mock it's CDI binding at runtime
706+ hk2ProvidedTypes .add (injectedType );
724707 } else {
725- if (isInjectionProvider (injectedType )) {
726- if (!isProviderOfJerseyType ((ParameterizedType )injectedType )
727- && !(customHk2TypesProvider != null && customHk2TypesProvider .getHk2Types ().contains (injectedType ))) {
708+ if (injectedType instanceof Class <?>) {
709+ if (isJerseyOrDependencyType ((Class <?>)injectedType )) {
710+ //remember the type, we would need to mock it's CDI binding at runtime
711+ hk2ProvidedTypes .add (injectedType );
712+ } else {
728713 filteredInjectionPoints .add (ip );
714+ }
715+ } else { // it is not a class, maybe provider type?:
716+ if (isInjectionProvider (injectedType )
717+ && (isProviderOfJerseyType ((ParameterizedType )injectedType ))) {
718+ //remember the type, we would need to mock it's CDI binding at runtime
719+ hk2ProvidedTypes .add (((ParameterizedType )injectedType ).getActualTypeArguments ()[0 ]);
729720 } else {
730- //remember the type, we would need to mock it's CDI binding at runtime
731- hk2ProvidedTypes .add (((ParameterizedType )injectedType ).getActualTypeArguments ()[0 ]);
721+ filteredInjectionPoints .add (ip );
732722 }
733- } else {
734- filteredInjectionPoints .add (ip );
735723 }
736724 }
737725 }
738726 return filteredInjectionPoints ;
739727 }
740728
741729 private final Set <Type > hk2ProvidedTypes = Collections .synchronizedSet (new HashSet <Type >());
742- private final Set <Type > potentionalHk2CustomBoundTypes = Collections .synchronizedSet (new HashSet <Type >());
743- private final Set <Type > typesSeenBeforeValidation = Collections .synchronizedSet (new HashSet <Type >());
744730 private final Set <Type > jerseyVetoedTypes = Collections .synchronizedSet (new HashSet <Type >());
745731
746732 private boolean isInjectionProvider (final Type injectedType ) {
@@ -750,7 +736,10 @@ private boolean isInjectionProvider(final Type injectedType) {
750736
751737 private boolean isProviderOfJerseyType (final ParameterizedType provider ) {
752738 final Type firstArgumentType = provider .getActualTypeArguments ()[0 ];
753- return firstArgumentType instanceof Class && isJerseyOrDependencyType ((Class <?>)firstArgumentType );
739+ if (firstArgumentType instanceof Class && isJerseyOrDependencyType ((Class <?>)firstArgumentType )) {
740+ return true ;
741+ }
742+ return (customHk2TypesProvider != null && customHk2TypesProvider .getHk2Types ().contains (firstArgumentType ));
754743 }
755744
756745 /**
@@ -763,23 +752,7 @@ public static class CdiDefaultAnnotation extends AnnotationLiteral<Default> impl
763752 @ SuppressWarnings ({ "unused" , "unchecked" , "rawtypes" })
764753 private void afterDiscoveryObserver (@ Observes AfterBeanDiscovery abd ) {
765754
766- if (customHk2TypesProvider == null ) {
767- potentionalHk2CustomBoundTypes .removeAll (typesSeenBeforeValidation );
768- potentionalHk2CustomBoundTypes .removeAll (_getContracts (typesSeenBeforeValidation ));
769- final boolean configLogEnabled = LOGGER .isLoggable (Level .CONFIG );
770- final Set <Type > effectiveHk2CustomBoundTypes = configLogEnabled ? new HashSet <Type >() : null ;
771- for (Type t : potentionalHk2CustomBoundTypes ) {
772- if (!isNothingWeWantToMessUpWith (t )) { // need to avoid built-in beans conflict
773- hk2ProvidedTypes .add (t );
774- if (configLogEnabled ) {
775- effectiveHk2CustomBoundTypes .add (t );
776- }
777- }
778- }
779- if (configLogEnabled ) {
780- LOGGER .config (listTypes (new StringBuilder ().append ("\n " ), effectiveHk2CustomBoundTypes ).toString ());
781- }
782- } else {
755+ if (customHk2TypesProvider != null ) {
783756 hk2ProvidedTypes .addAll (customHk2TypesProvider .getHk2Types ());
784757 }
785758
@@ -901,19 +874,12 @@ private boolean isJerseyOrDependencyType(final Class<?> clazz) {
901874
902875 final String pkgName = pkg .getName ();
903876
904- final boolean result = pkgName .contains ("org.glassfish.hk2" )
877+ return pkgName .contains ("org.glassfish.hk2" )
905878 || pkgName .contains ("jersey.repackaged" )
906879 || pkgName .contains ("org.jvnet.hk2" )
907880 || (pkgName .startsWith ("org.glassfish.jersey" )
908881 && !pkgName .startsWith ("org.glassfish.jersey.examples" )
909882 && !pkgName .startsWith ("org.glassfish.jersey.tests" ));
910-
911- // TODO: refactor this, it needs to get out of this checking method
912- if (!result ) {
913- potentionalHk2CustomBoundTypes .add (clazz );
914- }
915-
916- return result ;
917883 }
918884
919885 private static BeanManager beanManagerFromJndi () {
0 commit comments