private InjectionSite findInjectionSite(Injectable attribute) { // try constructor for (int i = 0; i < cdiSources.size(); i++) { Injectable injectable = cdiSources.get(i); if (attribute.equals(injectable)) { return new ConstructorInjectionSite(constructor, i); } } // try postConstruction for (Map.Entry<InjectionSite, Injectable> entry : postConstruction.entrySet()) { if (entry.getValue().equals(attribute)) { return entry.getKey(); } } return null; }
public Class<?> getMemberType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type: " + site.getClass()); } }
try { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getSignature().getConstructor(implementationClass); return method.getGenericParameterTypes()[methodSite.getParam()]; } catch (ClassNotFoundException e) { throw new AssertionError(e);
Injectable injectable = entry.getValue(); ConstructorInjectionSite constructorSite = (ConstructorInjectionSite) site; cdiSources[constructorSite.getParam()] = injectable;
public String getMessage() { if (site instanceof FieldInjectionSite) { FieldInjectionSite field = (FieldInjectionSite) site; return "Unknown injection type " + type + " on field " + field.getName() + " in class " + clazz; } else if (site instanceof MethodInjectionSite) { MethodInjectionSite method = (MethodInjectionSite) site; return "Unknown injection type " + type + " on method " + method + " in class " + clazz; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite ctor = (ConstructorInjectionSite) site; return "Unknown injection type " + type + " on constructor " + ctor.getConstructor() + " in class " + clazz; } else { return "Unknown injection type " + type + " found in class " + clazz; } } }
Injectable injectable = entry.getValue(); ConstructorInjectionSite constructorSite = (ConstructorInjectionSite) site; cdiSources[constructorSite.getParam()] = injectable;
public void visitConstructorParameter(Channel annotation, Constructor<?> constructor, int index, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ConstructorInjectionSite site = new ConstructorInjectionSite(constructor, index); String name = helper.getSiteName(constructor, index, null); Class<?> type = constructor.getParameterTypes()[index]; createReference(name, annotation, type, componentType, site, implClass, context); }
public Class<?> getMemberType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type: " + site.getClass()); } }
try { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getSignature().getConstructor(implementationClass); return method.getParameterTypes()[methodSite.getParam()]; } catch (ClassNotFoundException e) { throw new AssertionError(e);
Injectable injectable = entry.getValue(); ConstructorInjectionSite constructorSite = (ConstructorInjectionSite) site; cdiSources[constructorSite.getParam()] = injectable;
private InjectionSite findInjectionSite(Injectable attribute) { // try constructor for (int i = 0; i < cdiSources.size(); i++) { Injectable injectable = cdiSources.get(i); if (attribute.equals(injectable)) { return new ConstructorInjectionSite(constructor, i); } } // try postConstruction for (Map.Entry<InjectionSite, Injectable> entry : postConstruction.entrySet()) { if (entry.getValue().equals(attribute)) { return entry.getKey(); } } return null; }
public Type getGenericType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getGenericType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type " + site.getClass()); } }
private InjectionSite findInjectionSite(Injectable attribute) { // try constructor for (int i = 0; i < cdiSources.size(); i++) { Injectable injectable = cdiSources.get(i); if (attribute.equals(injectable)) { return new ConstructorInjectionSite(constructor, i); } } // try postConstruction for (Map.Entry<InjectionSite, Injectable> entry : postConstruction.entrySet()) { if (entry.getValue().equals(attribute)) { return entry.getKey(); } } return null; }
public Type getGenericType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getGenericType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type " + site.getClass()); } }
public void visitConstructorParameter(Channel annotation, Constructor<?> constructor, int index, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ConstructorInjectionSite site = new ConstructorInjectionSite(constructor, index); String name = helper.getSiteName(constructor, index, null); Class<?> type = constructor.getParameterTypes()[index]; createReference(name, annotation, type, componentType, site, implClass, context); }
} else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite constructorSite = (ConstructorInjectionSite) site; Constructor<?> constructor = constructorSite.getConstructor(); Annotation[] annotations = constructor.getParameterAnnotations()[constructorSite.getParam()]; for (Annotation annotation : annotations) { if (annotationType.equals(annotation.annotationType())) {
public void processInjectionSites(InjectingComponentType componentType, ImplementationManagerDefinition managerDefinition) { Map<InjectionSite, Injectable> mappings = componentType.getInjectionSites(); // add injections for all the active constructor args Map<InjectionSite, Injectable> construction = managerDefinition.getConstruction(); Constructor<?> constructor = componentType.getConstructor(); Set<Injectable> byConstruction = new HashSet<>(); if (constructor != null) { for (int i = 0; i < constructor.getParameterTypes().length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); Injectable attribute = mappings.get(site); construction.put(site, attribute); byConstruction.add(attribute); } } // add field/method injections Map<InjectionSite, Injectable> postConstruction = managerDefinition.getPostConstruction(); Map<InjectionSite, Injectable> reinjection = managerDefinition.getReinjectables(); for (Map.Entry<InjectionSite, Injectable> entry : mappings.entrySet()) { InjectionSite site = entry.getKey(); if (site instanceof ConstructorInjectionSite) { continue; } Injectable attribute = entry.getValue(); if (!byConstruction.contains(attribute)) { postConstruction.put(site, attribute); } reinjection.put(site, attribute); } }
public void processInjectionSites(InjectingComponentType componentType, ImplementationManagerDefinition managerDefinition) { Map<InjectionSite, Injectable> mappings = componentType.getInjectionSites(); // add injections for all the active constructor args Map<InjectionSite, Injectable> construction = managerDefinition.getConstruction(); Constructor<?> constructor = componentType.getConstructor(); Set<Injectable> byConstruction = new HashSet<>(); if (constructor != null) { for (int i = 0; i < constructor.getParameterTypes().length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); Injectable attribute = mappings.get(site); construction.put(site, attribute); byConstruction.add(attribute); } } // add field/method injections Map<InjectionSite, Injectable> postConstruction = managerDefinition.getPostConstruction(); Map<InjectionSite, Injectable> reinjection = managerDefinition.getReinjectables(); for (Map.Entry<InjectionSite, Injectable> entry : mappings.entrySet()) { InjectionSite site = entry.getKey(); if (site instanceof ConstructorInjectionSite) { continue; } Injectable attribute = entry.getValue(); if (!byConstruction.contains(attribute)) { postConstruction.put(site, attribute); } reinjection.put(site, attribute); } }
public void processInjectionSites(InjectingComponentType componentType, ImplementationManagerDefinition managerDefinition) { Map<InjectionSite, Injectable> mappings = componentType.getInjectionSites(); // add injections for all the active constructor args Map<InjectionSite, Injectable> construction = managerDefinition.getConstruction(); Signature constructor = componentType.getConstructor(); Set<Injectable> byConstruction = new HashSet<Injectable>(constructor.getParameterTypes().size()); for (int i = 0; i < constructor.getParameterTypes().size(); i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); Injectable attribute = mappings.get(site); construction.put(site, attribute); byConstruction.add(attribute); } // add field/method injections Map<InjectionSite, Injectable> postConstruction = managerDefinition.getPostConstruction(); Map<InjectionSite, Injectable> reinjection = managerDefinition.getReinjectables(); for (Map.Entry<InjectionSite, Injectable> entry : mappings.entrySet()) { InjectionSite site = entry.getKey(); if (site instanceof ConstructorInjectionSite) { continue; } Injectable attribute = entry.getValue(); if (!byConstruction.contains(attribute)) { postConstruction.put(site, attribute); } reinjection.put(site, attribute); } }
void evaluateConstructor(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { Map<InjectionSite, Injectable> sites = componentType.getInjectionSites(); Constructor<?> constructor = componentType.getConstructor(); TypeMapping typeMapping = context.getTypeMapping(implClass); Type[] parameterTypes = constructor.getGenericParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { InjectionSite site = new ConstructorInjectionSite(constructor, i); // skip sites that have already been mapped if (sites.containsKey(site)) { continue; } Type parameterType = parameterTypes[i]; String name = helper.getSiteName(constructor, i, null); processSite(componentType, typeMapping, name, constructor, parameterType, site, context); } }