public boolean isElementType(final WiringElementType type, final Class<? extends Annotation> annotation) { return getAnnotationsForElementType(type).contains(annotation); }
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)); }
private boolean scopeDoesNotRequireProxy(final MetaClass type) { final Class<? extends Annotation> scope = getScope(type); return scope.equals(EntryPoint.class) || injectionContext.getAnnotationsForElementType(WiringElementType.DependentBean).contains(scope); }
/** * Overloaded version to check GWT's JClassType classes. * * @param type * @param hasAnnotations * * @return */ public boolean isElementType(final WiringElementType type, final com.google.gwt.core.ext.typeinfo.HasAnnotations hasAnnotations) { final Collection<Class<? extends Annotation>> annotationsForElementType = getAnnotationsForElementType(type); for (final Annotation a : hasAnnotations.getAnnotations()) { if (annotationsForElementType.contains(a.annotationType())) { return true; } } return false; }
private List<MetaConstructor> getInjectableConstructors(final MetaClass type) { final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); final List<MetaConstructor> cons = new ArrayList<>(); for (final MetaConstructor con : type.getConstructors()) { for (final Class<? extends Annotation> anno : injectAnnotations) { if (con.isAnnotationPresent(anno)) { cons.add(con); } } } return cons; }
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 MetaConstructor getInjectableConstructor(final MetaClass type) { final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); for (final MetaConstructor con : type.getConstructors()) { for (final Class<? extends Annotation> anno : injectAnnotations) { if (con.isAnnotationPresent(anno)) { return con; } } } return null; }
private Class<? extends Annotation> getDirectScope(final HasAnnotations annotated) { scopeAnnoTypes.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.DependentBean)); scopeAnnoTypes.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.NormalScopedBean)); scopeAnnoTypes.addAll(injectionContext.getAnnotationsForElementType(WiringElementType.PseudoScopedBean));
private Map<Class<? extends Annotation>, MetaClass> findScopeContexts(final IOCProcessingContext processingContext) { final Collection<MetaClass> scopeContexts = ClassScanner.getTypesAnnotatedWith(ScopeContext.class); final Map<Class<? extends Annotation>, MetaClass> annoToContextImpl = new HashMap<>(); for (final MetaClass scopeContext : scopeContexts) { if (!scopeContext.isAssignableTo(Context.class)) { throw new RuntimeException("They type " + scopeContext.getFullyQualifiedName() + " was annotated with @ScopeContext but does not implement " + Context.class.getName()); } final ScopeContext anno = scopeContext.getAnnotation(ScopeContext.class); for (final Class<? extends Annotation> scope : anno.value()) { annoToContextImpl.put(scope, scopeContext); } } final MetaClass depContextImpl = MetaClassFactory.get(DependentScopeContext.class); for (final Class<? extends Annotation> customAnno : injectionContext.getAnnotationsForElementType(WiringElementType.DependentBean)) { annoToContextImpl.put(customAnno, depContextImpl); } return annoToContextImpl; }
/** * @param producerTypeInjectable If this parameter is null, only static methods will be processed. */ private void processProducerMethods(final Injectable producerTypeInjectable, final MetaClass producerType, final DependencyGraphBuilder builder, final Collection<MetaMethod> disposesMethods, final boolean enabled, final List<String> problems) { final boolean staticOnly = (producerTypeInjectable == null); final Collection<Class<? extends Annotation>> producerAnnos = injectionContext.getAnnotationsForElementType(WiringElementType.ProducerElement); for (final Class<? extends Annotation> anno : producerAnnos) { final List<MetaMethod> methods = producerType.getDeclaredMethodsAnnotatedWith(anno); for (final MetaMethod method : methods) { if (!staticOnly || method.isStatic()) { processProducerMethod(producerTypeInjectable, producerType, builder, disposesMethods, method, enabled, problems); } } } }
/** * @param producerInjectable If null then only static fields will be processed. */ private void processProducerFields(final Injectable producerInjectable, final MetaClass producerType, final DependencyGraphBuilder builder, final Collection<MetaMethod> disposesMethods, final boolean enabled, final List<String> problems) { final boolean staticOnly = (producerInjectable == null); final Collection<Class<? extends Annotation>> producerAnnos = injectionContext.getAnnotationsForElementType(WiringElementType.ProducerElement); for (final Class<? extends Annotation> producerAnno : producerAnnos) { final List<MetaField> fields = producerType.getFieldsAnnotatedWith(producerAnno); for (final MetaField field : fields) { if (!staticOnly || field.isStatic()) { processProducerField(producerInjectable, producerType, builder, disposesMethods, field, enabled, problems); } } } }
final Collection<Class<? extends Annotation>> producerAnnos = injectionContext.getAnnotationsForElementType(WiringElementType.ProducerElement); for (final Class<? extends Annotation> producerAnnoType : producerAnnos) { final List<MetaMethod> producerMethods = type.getMethodsAnnotatedWith(producerAnnoType); final Collection<Class<? extends Annotation>> injectAnnos = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); for (final Class<? extends Annotation> anno : injectAnnos) { if (!type.getFieldsAnnotatedWith(anno).isEmpty()) {
private void addFieldInjectionPoints(final Injectable typeInjectable, final DependencyGraphBuilder builder, final List<String> problems) { final boolean noPublicFieldsAllowed = typeInjectable.getWiringElementTypes().contains(WiringElementType.NormalScopedBean); final MetaClass type = typeInjectable.getInjectedType(); final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); for (final Class<? extends Annotation> inject : injectAnnotations) { for (final MetaField field : type.getFieldsAnnotatedWith(inject)) { if (noPublicFieldsAllowed && field.isPublic()) { problems.add("The normal scoped bean " + type.getFullyQualifiedName() + " has a public field " + field.getName()); } builder.addFieldDependency(typeInjectable, field.getType(), qualFactory.forSink(field), field); } } }
@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 maybeProcessAsProvider(final Injectable typeInjectable, final DependencyGraphBuilder builder, final boolean enabled) { final MetaClass type = typeInjectable.getInjectedType(); final Collection<Class<? extends Annotation>> providerAnnotations = injectionContext .getAnnotationsForElementType(WiringElementType.Provider); for (final Class<? extends Annotation> anno : providerAnnotations) { if (type.isAnnotationPresent(anno)) { if (type.isAssignableTo(Provider.class)) { addProviderInjectable(typeInjectable, builder, enabled); } else if (type.isAssignableTo(ContextualTypeProvider.class)) { addContextualProviderInjectable(typeInjectable, builder, enabled); } break; } } }
private void addMethodInjectionPoints(final Injectable typeInjectable, final DependencyGraphBuilder builder, final List<String> problems) { final MetaClass type = typeInjectable.getInjectedType(); final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); for (final Class<? extends Annotation> inject : injectAnnotations) { for (final MetaMethod setter : type.getMethodsAnnotatedWith(inject)) { if (setter.getParameters().length != 1) { problems.add("The method injection point " + setter.getName() + " in " + setter.getDeclaringClass().getFullyQualifiedName() + " should have exactly one parameter, not " + setter.getParameters().length + "."); } else { final MetaParameter metaParam = setter.getParameters()[0]; builder.addSetterMethodDependency(typeInjectable, metaParam.getType(), qualFactory.forSink(setter.getParameters()[0]), setter); } } } }