public IOCProcessor(final InjectionContext injectionContext) { this.injectionContext = injectionContext; this.qualFactory = injectionContext.getQualifierFactory(); nonSimpletonTypeAnnotations.add(IOCProvider.class); nonSimpletonTypeAnnotations.add(Specializes.class); nonSimpletonTypeAnnotations.add(LoadAsync.class); nonSimpletonTypeAnnotations.add(EnabledByProperty.class); nonSimpletonTypeAnnotations.add(Typed.class); nonSimpletonTypeAnnotations.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.DependentBean)); nonSimpletonTypeAnnotations.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.PseudoScopedBean)); nonSimpletonTypeAnnotations.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.NormalScopedBean)); nonSimpletonTypeAnnotations.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.AlternativeBean)); }
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { final InjectableHandle handle = new InjectableHandle(MetaClassFactory.get(Logger.class), injectionContext.getQualifierFactory().forUniversallyQualified()); final Map<String, CustomFactoryInjectable> injectablesByLoggerName = new HashMap<String, CustomFactoryInjectable>();
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { if (DYNAMIC_VALIDATION_ENABLED) { injectionContext.registerExtensionTypeCallback(type -> { if (type.isConcrete() && type.isAssignableTo(ConstraintValidator.class) && !type.getFullyQualifiedName().equals(NullType.class.getName())) { logger.debug("Found ConstraintValidator, {}", type.getFullyQualifiedName()); validators.add(type); } }); final InjectableHandle handle = new InjectableHandle(MetaClassFactory.get(DynamicValidator.class), injectionContext.getQualifierFactory().forDefault()); injectionContext.registerInjectableProvider(handle, (injectionSite, nameGenerator) -> new DefaultCustomFactoryInjectable(handle.getType(), handle.getQualifier(), "DynamicValidatorFactory", Singleton.class, Arrays.asList(WiringElementType.NormalScopedBean), new DynamicValidatorBodyGenerator(validators))); } }
@Override public CustomFactoryInjectable getInjectable(final InjectionSite injectionSite, final FactoryNameGenerator nameGenerator) { final String loggerName; if (injectionSite.isAnnotationPresent(NamedLogger.class)) { loggerName = injectionSite.getAnnotation(NamedLogger.class).value(); } else { loggerName = injectionSite.getEnclosingType().getFullyQualifiedName(); } if (!injectablesByLoggerName.containsKey(loggerName)) { final Statement loggerValue = invokeStatic(LoggerFactory.class, "getLogger", loggerName); final FactoryBodyGenerator generator = new AbstractBodyGenerator() { @Override protected List<Statement> generateCreateInstanceStatements(final ClassStructureBuilder<?> bodyBlockBuilder, final Injectable injectable, final DependencyGraph graph, final InjectionContext injectionContext) { return Collections.singletonList(Stmt.nestedCall(loggerValue).returnValue()); } }; final MetaClass type = MetaClassFactory.get(Logger.class); final Qualifier qualifier = injectionContext.getQualifierFactory().forUniversallyQualified(); injectablesByLoggerName.put(loggerName, new DefaultCustomFactoryInjectable(type, qualifier, nameGenerator.generateFor(type, qualifier, InjectableType.ExtensionProvided), Dependent.class, Collections.singletonList(WiringElementType.DependentBean), generator)); } return injectablesByLoggerName.get(loggerName); } });
private void addProviderForWidgetType(final InjectionContext injectionContext, final MetaClass widgetType) { if (widgetType.isPublic() && widgetType.isDefaultInstantiable()) { final InjectableHandle handle = new InjectableHandle(widgetType, injectionContext.getQualifierFactory().forDefault()); injectionContext.registerExactTypeInjectableProvider(handle, new InjectableProvider() {
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); } }
@Before @SuppressWarnings({ "unchecked", "rawtypes" }) public void setup() { MetaClassFactory.getMetaClassCache().clear(); FactoryGenerator.setDependencyGraph(null); final QualifierFactory qualFactory = new DefaultQualifierFactory(); when(injContext.getQualifierFactory()).thenReturn(qualFactory); when(injContext.getInjectableProviders()).thenReturn(HashMultimap.create()); when(injContext.getExactTypeInjectableProviders()).thenReturn(HashMultimap.create()); when(injContext.getAnnotationsForElementType(DependentBean)).thenReturn(Arrays.asList(Dependent.class)); when(injContext.getAnnotationsForElementType(NormalScopedBean)).thenReturn(Arrays.asList(ApplicationScoped.class)); when(injContext.getAnnotationsForElementType(PseudoScopedBean)).thenReturn(Arrays.asList(Singleton.class, Dependent.class)); when(injContext.getAnnotationsForElementType(AlternativeBean)).thenReturn(Arrays.asList(Alternative.class)); when(injContext.getAnnotationsForElementType(InjectionPoint)).thenReturn(Arrays.asList(Inject.class)); when(injContext.getAnnotationsForElementType(ProducerElement)).thenReturn(Arrays.asList(IOCProducer.class)); when(injContext.getAnnotationsForElementType(Provider)).thenReturn(Arrays.asList(IOCProvider.class)); when(injContext.isWhitelisted(any())).thenReturn(true); when(injContext.isBlacklisted(any())).thenReturn(false); final ClassStructureBuilder<?> classBuilder = ClassBuilder .define("org.jboss.errai.ioc.FakeBootstrapperImpl") .publicScope() .implementsInterface(Bootstrapper.class) .body(); final BlockBuilder blockBuilder = classBuilder.publicMethod(ContextManager.class, "bootstrap").body(); when(procContext.getBlockBuilder()).thenReturn(blockBuilder); when(procContext.getBootstrapBuilder()).thenReturn(classBuilder); when(procContext.getBootstrapClass()).thenReturn(classBuilder.getClassDefinition()); processor = new IOCProcessor(injContext); }
@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); }
injectionContext.getQualifierFactory().forSource(new HasAnnotations() {
injectionContext.getQualifierFactory().forSource(new HasAnnotations() {
@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))); }