private Collection<MetaMethod> getMatchingMethods(final MetaClassMember member, final Collection<MetaMethod> disposesMethods) { final Collection<MetaMethod> matching = new ArrayList<>(); final Qualifier memberQual = qualFactory.forSource(member); final MetaClass producedType = getProducedType(member); for (final MetaMethod candidate : disposesMethods) { final MetaParameter disposesParam = candidate.getParametersAnnotatedWith(Disposes.class).iterator().next(); if (producedType.isAssignableTo(disposesParam.getType())) { final Qualifier paramQual = qualFactory.forSink(disposesParam); if (paramQual.isSatisfiedBy(memberQual)) { matching.add(candidate); } } } return matching; }
private void removeLinksToProducedTypes(final InjectableImpl specialized, final Set<InjectableImpl> toBeRemoved) { final Collection<InjectableReference> producedReferences = new ArrayList<>(); for (final MetaMethod method : specialized.type.getDeclaredMethodsAnnotatedWith(Produces.class)) { producedReferences.add(lookupInjectableReference(method.getReturnType(), qualFactory.forSource(method))); } for (final MetaField field : specialized.type.getDeclaredFields()) { if (field.isAnnotationPresent(Produces.class)) { producedReferences.add(lookupInjectableReference(field.getType(), qualFactory.forSource(field))); } } for (final InjectableReference reference : producedReferences) { final Iterator<InjectableBase> linkIter = reference.linked.iterator(); while (linkIter.hasNext()) { final InjectableBase link = linkIter.next(); if (link instanceof InjectableImpl && ((InjectableImpl) link).injectableType.equals(InjectableType.Producer)) { final InjectableImpl concreteLink = (InjectableImpl) link; final ProducerInstanceDependencyImpl producerMemberDep = GraphUtil.findProducerInstanceDep(concreteLink); if (producerMemberDep.producingMember.getDeclaringClass().equals(specialized.type)) { linkIter.remove(); toBeRemoved.add(concreteLink); } } } } }
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { final QualifierFactory qualifierFactory = injectionContext.getQualifierFactory(); final InjectableHandle transitionToHandle = new InjectableHandle(MetaClassFactory.get(Anchor.class), qualifierFactory.forSource(() -> new Annotation[] { TRANSITION_TO })); final InjectableHandle transitionToRoleHandle = new InjectableHandle(MetaClassFactory.get(Anchor.class), qualifierFactory.forSource(() -> new Annotation[] { TRANSITION_TO_ROLE })); scanForUniquePageRoles(context.getGeneratorContext()); registerProvider(injectionContext, transitionToHandle); registerProvider(injectionContext, transitionToRoleHandle); }
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { final QualifierFactory qualifierFactory = injectionContext.getQualifierFactory(); final InjectableHandle transitionToHandle = new InjectableHandle(MetaClassFactory.get(Anchor.class), qualifierFactory.forSource(() -> new Annotation[] { TRANSITION_TO })); final InjectableHandle transitionToRoleHandle = new InjectableHandle(MetaClassFactory.get(Anchor.class), qualifierFactory.forSource(() -> new Annotation[] { TRANSITION_TO_ROLE })); scanForUniquePageRoles(context.getGeneratorContext()); registerProvider(injectionContext, transitionToHandle); registerProvider(injectionContext, transitionToRoleHandle); }
@Test public void typeWithCustomQualifier() throws Exception { final Qualifier customQualifier = qualFactory.forSource(() -> new Annotation[] { new CustomQualifier() { @Override public Class<? extends Annotation> annotationType() { return CustomQualifier.class; } }}); final String generated = generator.generateFor(object, customQualifier, Type); assertEquals("Type_factory__j_l_Object__quals__j_e_i_Any_o_j_e_i_u_r_CustomQualifier", generated); }
private void addProviderInjectable(final Injectable providerImplInjectable, final DependencyGraphBuilder builder, final boolean enabled) { final MetaClass providerImpl = providerImplInjectable.getInjectedType(); final MetaMethod providerMethod = providerImpl.getMethod("get", new Class[0]); final MetaClass providedType = getMethodReturnType(providerMethod); final InjectableType injectableType = (enabled ? InjectableType.Provider : InjectableType.Disabled); final Injectable providedInjectable = builder.addInjectable(providedType, qualFactory.forSource(providerMethod), EXACT_TYPE, Dependent.class, injectableType, WiringElementType.Provider, WiringElementType.DependentBean); builder.addProducerMemberDependency(providedInjectable, providerImplInjectable.getInjectedType(), providerImplInjectable.getQualifier(), providerMethod); }
@Test public void typeWithNamedQualifier() throws Exception { final Qualifier namedQualifier = qualFactory.forSource(() -> new Annotation[] { new Named() { @Override public Class<? extends Annotation> annotationType() { return Named.class; } @Override public String value() { return "foo"; } }}); final String generated = generator.generateFor(object, namedQualifier, Type); assertEquals("Type_factory__j_l_Object__quals__j_e_i_Any_j_e_i_Default_j_i_Named", generated); }
private void register(final Collection<String> tags, final InjectionContext injectionContext, final MetaClass type) { for (final String tag : tags) { final Qualifier qualifier = injectionContext.getQualifierFactory().forSource(new HasNamedAnnotation(tag)); final InjectableHandle handle = new InjectableHandle(type, qualifier); final ElementInjectionBodyGenerator injectionBodyGenerator = new ElementInjectionBodyGenerator(type, tag, getProperties(type), getClassNames(type)); final ElementProvider elementProvider = new ElementProvider(handle, injectionBodyGenerator); injectionContext.registerExactTypeInjectableProvider(handle, elementProvider); } }
private void register(final Collection<String> tags, final InjectionContext injectionContext, final MetaClass type) { for (final String tag : tags) { final Qualifier qualifier = injectionContext.getQualifierFactory().forSource(new HasNamedAnnotation(tag)); final InjectableHandle handle = new InjectableHandle(type, qualifier); final ElementInjectionBodyGenerator injectionBodyGenerator = new ElementInjectionBodyGenerator(type, tag, getProperties(type), getClassNames(type)); final ElementProvider elementProvider = new ElementProvider(handle, injectionBodyGenerator); injectionContext.registerExactTypeInjectableProvider(handle, elementProvider); } }
injectionContext.getQualifierFactory().forSource(new HasAnnotations() {
injectionContext.getQualifierFactory().forSource(new HasAnnotations() {
private void processProducerMethod(final Injectable producerTypeInjectable, final MetaClass producerType, final DependencyGraphBuilder builder, final Collection<MetaMethod> disposesMethods, final MetaMethod method, final boolean enabled, final List<String> problems) { final Class<? extends Annotation> directScope = getScope(method); final WiringElementType[] wiringTypes = getWiringTypeForProducer(producerType, method, directScope); final InjectableType injectableType = (enabled ? InjectableType.Producer : InjectableType.Disabled); final Injectable producedInjectable = builder.addInjectable(getMethodReturnType(method), qualFactory.forSource(method), getPathPredicate(method, problems), directScope, injectableType, wiringTypes); if (method.isStatic()) { builder.addProducerMemberDependency(producedInjectable, producerType, method); } else { builder.addProducerMemberDependency(producedInjectable, producerType, producerTypeInjectable.getQualifier(), method); } if (enabled) { processProducerAndDisposerMethodsDependencies(builder, disposesMethods, method, producedInjectable); } }
final boolean enabled; if (isSimpleton(type)) { builder.addInjectable(type, qualFactory.forSource(type), ANY, Dependent.class, InjectableType.Type, WiringElementType.DependentBean, WiringElementType.Simpleton); maybeProcessAsStaticOnlyProducer(builder, type, problems); final Injectable typeInjectable = builder.addInjectable(type, qualFactory.forSource(type), getPathPredicate(type, problems), directScope, InjectableType.Type, getWiringTypes(type, directScope)); processInjectionPoints(typeInjectable, builder, problems); final Injectable typeInjectable = builder.addInjectable(type, qualFactory.forSource(type), getPathPredicate(type, problems), directScope, InjectableType.Disabled, getWiringTypes(type, directScope)); maybeProcessAsProducer(builder, type, typeInjectable, false, problems);
private void processProducerField(final Injectable producerInjectable, final MetaClass producerType, final DependencyGraphBuilder builder, final Collection<MetaMethod> disposesMethods, final MetaField field, final boolean enabled, final List<String> problems) { final Class<? extends Annotation> scopeAnno = getScope(field); final InjectableType injectableType = (enabled ? InjectableType.Producer : InjectableType.Disabled); final Injectable producedInjectable = builder.addInjectable(field.getType(), qualFactory.forSource(field), getPathPredicate(field, problems), scopeAnno, injectableType, getWiringTypeForProducer(producerType, field, scopeAnno)); if (field.isStatic()) { builder.addProducerMemberDependency(producedInjectable, producerType, field); } else { builder.addProducerMemberDependency(producedInjectable, producerInjectable.getInjectedType(), producerInjectable.getQualifier(), field); } if (enabled) { processDisposerDependencies(builder, disposesMethods, field, producedInjectable); } }
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { final AnnoWithNonBindingAttribute representative = new AnnoWithNonBindingAttribute() { @Override public Class<? extends Annotation> annotationType() { return AnnoWithNonBindingAttribute.class; } @Override public String value() { return ""; } }; final QualifierFactory qualFactory = injectionContext.getQualifierFactory(); final InjectableHandle handle = new InjectableHandle(MetaClassFactory.get(String.class), qualFactory.forSource(() -> new Annotation[] { representative })); injectionContext.registerInjectableProvider(handle, (injectionSite, nameGenerator) -> new DefaultCustomFactoryInjectable(handle, nameGenerator.generateFor(handle, ExtensionProvided), Dependent.class, Arrays.asList(DependentBean), getGenerator(injectionSite))); }