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 configure(final IOCProcessingContext context, final InjectionContext injectionContext) { injectionContext.mapElementType(WiringElementType.DependentBean, Templated.class); }
private void registerProvider(final InjectionContext injectionContext, final InjectableHandle transitionToHandle) { injectionContext.registerExactTypeInjectableProvider(transitionToHandle, (injectionSite, nameGenerator) -> getOrCreateInjectable(transitionToHandle, injectionSite, nameGenerator, injectionContext) ); }
public Annotation getMatchingAnnotationForElementType(final WiringElementType type, final HasAnnotations hasAnnotations) { final Collection<Class<? extends Annotation>> annotationsForElementType = getAnnotationsForElementType(type); for (final Annotation a : hasAnnotations.getAnnotations()) { if (annotationsForElementType.contains(a.annotationType())) { return a; } } final Set<Annotation> annotationSet = new HashSet<Annotation>(); fillInStereotypes(annotationSet, hasAnnotations.getAnnotations(), false); for (final Annotation a : annotationSet) { if (annotationsForElementType.contains(a.annotationType())) { return a; } } return null; }
private void addAllInjectableProviders(final DependencyGraphBuilder graphBuilder) { for (final Entry<InjectableHandle, InjectableProvider> entry : injectionContext.getInjectableProviders().entries()) { graphBuilder.addExtensionInjectable(entry.getKey().getType(), entry.getKey().getQualifier(), ANY, entry.getValue()); } for (final Entry<InjectableHandle, InjectableProvider> entry : injectionContext.getExactTypeInjectableProviders().entries()) { graphBuilder.addExtensionInjectable(entry.getKey().getType(), entry.getKey().getQualifier(), EXACT_TYPE, entry.getValue()); } }
@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>(); injectionContext.registerInjectableProvider(handle, new InjectableProvider() { @Override public CustomFactoryInjectable getInjectable(final InjectionSite injectionSite, final FactoryNameGenerator nameGenerator) {
@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); }
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() {
@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); } });
public boolean isElementType(final WiringElementType type, final Class<? extends Annotation> annotation) { return getAnnotationsForElementType(type).contains(annotation); }
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { final MetaClass widgetClazz = MetaClassFactory.get(Widget.class); injectionContext.registerExtensionTypeCallback(new ExtensionTypeCallback() { @Override public void callback(final MetaClass type) { if (type.isDefaultInstantiable() && type.isAssignableTo(widgetClazz)) { addProviderForWidgetType(injectionContext, type); } } }); }
private String generateBootstrappingClassSource(final InjectionContext injectionContext) { log.debug("Processing IOC extensions..."); long start = System.currentTimeMillis(); processExtensions(context, injectionContext, beforeTasks, afterTasks); log.debug("Extensions processed in {}ms", (System.currentTimeMillis() - start)); final IOCProcessor processorFactory = new IOCProcessor(injectionContext); final IOCProcessingContext processingContext = injectionContext.getProcessingContext(); final ClassStructureBuilder<?> classBuilder = processingContext.getBootstrapBuilder(); final BlockBuilder<?> blockBuilder = processingContext.getBlockBuilder(); @SuppressWarnings({ "unchecked", "rawtypes" }) final BlockBuilder builder = new BlockBuilderImpl(classBuilder.getClassDefinition().getInstanceInitializer(), null); doBeforeRunnables(builder); log.debug("Process dependency graph..."); start = System.currentTimeMillis(); processorFactory.process(processingContext); log.debug("Processed dependency graph in {}ms", System.currentTimeMillis() - start); doAfterRunnbales(blockBuilder); blockBuilder.append(loadVariable("contextManager").returnValue()); blockBuilder.finish(); start = System.currentTimeMillis(); final String bootstrapperImplString = classBuilder.toJavaString(); log.debug("Generated BootstrapperImpl String in {}ms", System.currentTimeMillis() - start); return bootstrapperImplString; }
configurator.configure(injectionContext.getProcessingContext(), injectionContext); for (@SuppressWarnings("rawtypes") final Entry<Class<? extends IOCDecoratorExtension>, Class<? extends Annotation>> entry : decoratorMap.entrySet()) { injectionContext.registerDecorator( entry.getKey().getConstructor(new Class[] { Class.class }).newInstance(entry.getValue())); extensionConfigurator.afterInitialization(injectionContext.getProcessingContext(), injectionContext);
injectionContext.getQualifierFactory().forSource(new HasAnnotations() { injectionContext.registerInjectableProvider(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); } }
@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); }
private boolean scopeDoesNotRequireProxy(final MetaClass type) { final Class<? extends Annotation> scope = getScope(type); return scope.equals(EntryPoint.class) || injectionContext.getAnnotationsForElementType(WiringElementType.DependentBean).contains(scope); }
@Override public void afterInitialization(final IOCProcessingContext context, final InjectionContext injectionContext) { injectionContext.registerExtensionTypeCallback(type -> { try { register(getElementTags(type), injectionContext, type); } catch (final Throwable t) { final String typeName = type.getFullyQualifiedName(); final String className = ElementProviderExtension.class.getSimpleName(); final String msg = String.format("Error occurred while processing [%s] in %s.", typeName, className); throw new RuntimeException(msg, t); } }); }
assertTypeIsDataBinder(field.getType()); dataModelType = (MetaClass) field.getType().getParameterizedType().getTypeParameters()[0]; dataBinderRef = invokeStatic(decorable.getInjectionContext().getProcessingContext().getBootstrapClass(), PrivateAccessUtil.getPrivateFieldAccessorName(field), Variable.get("instance"));