private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
@Override public Object resolve(Injectee injectee, ServiceHandle root) { InjecteeImpl injecteeWrapper = new InjecteeImpl(); injecteeWrapper.setRequiredType(injectee.getRequiredType()); injecteeWrapper.setParent(injectee.getParent()); injecteeWrapper.setRequiredQualifiers(injectee.getRequiredQualifiers()); injecteeWrapper.setOptional(injectee.isOptional()); injecteeWrapper.setPosition(injectee.getPosition()); injecteeWrapper.setFactory(ReflectionHelper.isSubClassOf(injectee.getRequiredType(), Factory.class)); injecteeWrapper.setInjecteeDescriptor(new ForeignDescriptorImpl(injectee.getInjecteeDescriptor())); Object instance = jerseyResolver.resolve(injecteeWrapper); if (injecteeWrapper.isFactory()) { return asFactory(instance); } else { return instance; } }
@Override public Object resolve(Injectee injectee, ServiceHandle root) { InjecteeImpl injecteeWrapper = new InjecteeImpl(); injecteeWrapper.setRequiredType(injectee.getRequiredType()); injecteeWrapper.setParent(injectee.getParent()); injecteeWrapper.setRequiredQualifiers(injectee.getRequiredQualifiers()); injecteeWrapper.setOptional(injectee.isOptional()); injecteeWrapper.setPosition(injectee.getPosition()); injecteeWrapper.setFactory(ReflectionHelper.isSubClassOf(injectee.getRequiredType(), Factory.class)); injecteeWrapper.setInjecteeDescriptor(new ForeignDescriptorImpl(injectee.getInjecteeDescriptor())); Object instance = jerseyResolver.resolve(injecteeWrapper); if (injecteeWrapper.isFactory()) { return asFactory(instance); } else { return instance; } }
private void methodMe(Map<SystemInjecteeImpl, Object> resolved, T t) throws Throwable { for (ResolutionInfo ri : myInitializers) { Method m = (Method) ri.baseElement; List<SystemInjecteeImpl> injectees = ri.injectees; Object args[] = new Object[injectees.size()]; for (Injectee injectee : injectees) { args[injectee.getPosition()] = resolved.get(injectee); } ReflectionHelper.invoke(t, m, args, locator.getNeutralContextClassLoader()); } }
private void methodMe(Map<SystemInjecteeImpl, Object> resolved, T t) throws Throwable { for (ResolutionInfo ri : myInitializers) { Method m = (Method) ri.baseElement; List<SystemInjecteeImpl> injectees = ri.injectees; Object args[] = new Object[injectees.size()]; for (Injectee injectee : injectees) { args[injectee.getPosition()] = resolved.get(injectee); } ReflectionHelper.invoke(t, m, args, locator.getNeutralContextClassLoader()); } }
private void methodMe(Map<SystemInjecteeImpl, Object> resolved, T t) throws Throwable { for (ResolutionInfo ri : myInitializers) { Method m = (Method) ri.baseElement; List<SystemInjecteeImpl> injectees = ri.injectees; Object args[] = new Object[injectees.size()]; for (Injectee injectee : injectees) { args[injectee.getPosition()] = resolved.get(injectee); } ReflectionHelper.invoke(t, m, args, locator.getNeutralContextClassLoader()); } }
private void methodMe(Map<SystemInjecteeImpl, Object> resolved, T t) throws Throwable { for (ResolutionInfo ri : myInitializers) { Method m = (Method) ri.baseElement; List<SystemInjecteeImpl> injectees = ri.injectees; Object args[] = new Object[injectees.size()]; for (Injectee injectee : injectees) { args[injectee.getPosition()] = resolved.get(injectee); } ReflectionHelper.invoke(t, m, args, locator.getNeutralContextClassLoader()); } }
private boolean hasEncodedAnnotation(Injectee injectee) { AnnotatedElement element = injectee.getParent(); final boolean isConstructor = element instanceof Constructor; final boolean isMethod = element instanceof Method; // if injectee is method or constructor, check its parameters if (isConstructor || isMethod) { Annotation[] annotations; if (isMethod) { annotations = ((Method) element).getParameterAnnotations()[injectee.getPosition()]; } else { annotations = ((Constructor) element).getParameterAnnotations()[injectee.getPosition()]; } for (Annotation annotation : annotations) { if (annotation.annotationType().equals(Encoded.class)) { return true; } } } // check injectee itself (method, constructor or field) if (element.isAnnotationPresent(Encoded.class)) { return true; } // check class which contains injectee Class<?> clazz = injectee.getInjecteeClass(); return clazz.isAnnotationPresent(Encoded.class); }
public <T extends Annotation> Optional<T> findParameter(Injectee injectee, Class<T> type) { AnnotatedElement parent = injectee.getParent(); Optional<T> annotation; if (parent instanceof Field) { Field field = (Field) parent; annotation = Optional.ofNullable(field.getAnnotation(type)); } else { Executable executable = (Executable) parent; Annotation[][] annotations = executable.getParameterAnnotations(); Annotation[] params = annotations[injectee.getPosition()]; annotation = Stream.of(params) .parallel() .filter(p -> type.equals(p.annotationType())) .map(p -> (T) p) .findFirst(); } return annotation; }
/** * Returns an injection resolver for the injectee * * @param locator The locator to use when finding the resolver * @param injectee Injectee from which the annotation should be extracted * @return Injection resolver used to resolve the injection for the injectee * @throws IllegalStateException If we could not find a valid resolver */ public InjectionResolver<?> getInjectionResolver( ServiceLocatorImpl locator, Injectee injectee) throws IllegalStateException { return getInjectionResolver(locator, injectee.getParent(), injectee.getPosition()); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
/** * NOTE: There can be only one {@link Annotation} that is a {@link Qualifier} or {@link BindingAnnotation}. * They're the same but HK2 does not know about {@link BindingAnnotation}. * * @see Qualifier * @see BindingAnnotation * @see javax.inject.Named * @see com.google.inject.name.Named */ private static Set<Annotation> getQualifiers(Injectee injectee) { // JSR 330's @Qualifier Set<Annotation> qualifiers = injectee.getRequiredQualifiers(); if (!qualifiers.isEmpty()) { return qualifiers; } AnnotatedElement element = injectee.getParent(); int position = injectee.getPosition(); // Guice's @BindingAnnotation is the same as @Qualifier Annotation annotation = getBindingAnnotation(element, position); if (annotation != null) { return Collections.singleton(annotation); } return Collections.emptySet(); }
private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
private CacheKey(Injectee injectee) { this.injectee = injectee; this.hash = Objects.hash(injectee.getInjecteeClass(), injectee.getInjecteeDescriptor(), injectee.getParent(), injectee.getRequiredQualifiers(), injectee.getRequiredType(), injectee.getPosition()); }
/** * This is the copy constructor, which will copy all the values from the incoming Injectee * @param copyMe The non-null Injectee to copy the values from */ public InjecteeImpl(Injectee copyMe) { requiredType = copyMe.getRequiredType(); position = copyMe.getPosition(); parent = copyMe.getParent(); qualifiers = Collections.unmodifiableSet(copyMe.getRequiredQualifiers()); isOptional = copyMe.isOptional(); isSelf = copyMe.isSelf(); injecteeDescriptor = copyMe.getInjecteeDescriptor(); // unqualified = copyMe.getUnqualified(); if (parent == null) { pClass = null; } else if (parent instanceof Field) { pClass = ((Field) parent).getDeclaringClass(); } else if (parent instanceof Constructor) { pClass = ((Constructor<?>) parent).getDeclaringClass(); } else if (parent instanceof Method) { pClass = ((Method) parent).getDeclaringClass(); } }
@Override public Object resolve(Injectee injectee, ServiceHandle root) { InjecteeImpl injecteeWrapper = new InjecteeImpl(); injecteeWrapper.setRequiredType(injectee.getRequiredType()); injecteeWrapper.setParent(injectee.getParent()); injecteeWrapper.setRequiredQualifiers(injectee.getRequiredQualifiers()); injecteeWrapper.setOptional(injectee.isOptional()); injecteeWrapper.setPosition(injectee.getPosition()); injecteeWrapper.setFactory(ReflectionHelper.isSubClassOf(injectee.getRequiredType(), Factory.class)); injecteeWrapper.setInjecteeDescriptor(new ForeignDescriptorImpl(injectee.getInjecteeDescriptor())); Object instance = jerseyResolver.resolve(injecteeWrapper); if (injecteeWrapper.isFactory()) { return asFactory(instance); } else { return instance; } }
@Override public Object resolve(Injectee injectee, ServiceHandle root) { InjecteeImpl injecteeWrapper = new InjecteeImpl(); injecteeWrapper.setRequiredType(injectee.getRequiredType()); injecteeWrapper.setParent(injectee.getParent()); injecteeWrapper.setRequiredQualifiers(injectee.getRequiredQualifiers()); injecteeWrapper.setOptional(injectee.isOptional()); injecteeWrapper.setPosition(injectee.getPosition()); injecteeWrapper.setFactory(ReflectionHelper.isSubClassOf(injectee.getRequiredType(), Factory.class)); injecteeWrapper.setInjecteeDescriptor(new ForeignDescriptorImpl(injectee.getInjecteeDescriptor())); Object instance = jerseyResolver.resolve(injecteeWrapper); if (injecteeWrapper.isFactory()) { return asFactory(instance); } else { return instance; } }