Interceptor annot = type.getAnnotation(Interceptor.class); if (annot != null) { return; LOGGER.log(Level.FINE, () -> "### Processing annotations for " + pat.getAnnotatedType().getJavaClass().getName()); Class<?> clazz = configurator.getAnnotated().getJavaClass(); configurator.filterMethods(method -> !Modifier.isPrivate(method.getJavaMember().getModifiers())) .forEach(method -> { METRIC_ANNOTATIONS.forEach(annotation -> { LookupResult<? extends Annotation> lookupResult = lookupAnnotation(method.getAnnotated().getJavaMember(), annotation, clazz); if (lookupResult != null) { registerMetric(method.getAnnotated().getJavaMember(), clazz, lookupResult); configurator.filterConstructors(constructor -> !Modifier.isPrivate(constructor.getJavaMember().getModifiers())) .forEach(constructor -> { METRIC_ANNOTATIONS.forEach(annotation -> { LookupResult<? extends Annotation> lookupResult = lookupAnnotation(constructor.getAnnotated().getJavaMember(), annotation, clazz); if (lookupResult != null) { registerMetric(constructor.getAnnotated().getJavaMember(), clazz, lookupResult);
@Override public List<AnnotatedParameter> getParameters() { final List<AnnotatedParameter> parameters = new ArrayList<>(ctor.getParameters().size()); for (final AnnotatedParameter<?> ap : ctor.getParameters()) { parameters.add(new AnnotatedParameter() {
@Override public Set<Annotation> getAnnotations() { return ctor.getAnnotations(); }
this.javaClass = type.getJavaClass(); for (AnnotatedField<? super X> field : type.getFields()) { if (fields.get(field.getJavaMember()) == null) { fields.put(field.getJavaMember(), new AnnotationBuilder()); mergeAnnotationsOnElement(field, overwrite, fields.get(field.getJavaMember())); if (methodParameters.get(method.getJavaMember()).get(p.getPosition()) == null) { methodParameters.get(method.getJavaMember()).put(p.getPosition(), new AnnotationBuilder()); mergeAnnotationsOnElement(p, overwrite, methodParameters.get(method.getJavaMember()).get(p.getPosition())); for (AnnotatedConstructor<? super X> constructor : type.getConstructors()) { if (constructors.get(constructor.getJavaMember()) == null) { constructors.put(constructor.getJavaMember(), new AnnotationBuilder()); mergeAnnotationsOnElement(constructor, overwrite, constructors.get(constructor.getJavaMember())); for (AnnotatedParameter<? super X> p : constructor.getParameters()) { if (constructorParameters.get(constructor.getJavaMember()) == null) { constructorParameters.put(constructor.getJavaMember(), new HashMap<Integer, AnnotationBuilder>()); if (constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()) == null) { constructorParameters.get(constructor.getJavaMember()).put(p.getPosition(), new AnnotationBuilder()); mergeAnnotationsOnElement(p, overwrite, constructorParameters.get(constructor.getJavaMember()).get(p.getPosition()));
if (!t1.getJavaClass().equals(t2.getJavaClass())) { return false; if (!compareAnnotated(t1, t2)) { return false; if (t1.getFields().size() != t2.getFields().size()) { return false; for (AnnotatedField<?> f : t2.getFields()) { fields.put(f.getJavaMember(), f); for (AnnotatedField<?> f : t1.getFields()) { if (fields.containsKey(f.getJavaMember())) { if (!compareAnnotatedField(f, fields.get(f.getJavaMember()))) { return false; for (AnnotatedMethod<?> f : t2.getMethods()) { methods.put(f.getJavaMember(), f); for (AnnotatedConstructor<?> f : t2.getConstructors()) { constructors.put(f.getJavaMember(), f); for (AnnotatedConstructor<?> f : t1.getConstructors()) { if (constructors.containsKey(f.getJavaMember())) { if (!compareAnnotatedCallable(f, constructors.get(f.getJavaMember()))) { return false;
protected static void validateParameterCount(AnnotatedCallable<?> callable) { if (callable instanceof BackedAnnotatedMember) { return; // do not validate backed implementation } Class<?>[] parameterTypes = null; if (callable instanceof AnnotatedConstructor<?>) { parameterTypes = AnnotatedConstructor.class.cast(callable).getJavaMember().getParameterTypes(); } else { parameterTypes = AnnotatedMethod.class.cast(callable).getJavaMember().getParameterTypes(); } if (callable.getParameters().size() != parameterTypes.length) { // For enums, BackedAnnotatedConstructor sets parameters to an empty list, so we shouldn't throw the DefinitionException Class<?> declaringClass = callable.getDeclaringType().getJavaClass(); if (!declaringClass.isEnum() && !declaringClass.isMemberClass()) { throw ReflectionLogger.LOG.incorrectNumberOfAnnotatedParametersMethod(callable.getParameters().size(), callable, callable.getParameters(), Arrays.asList(parameterTypes)); } } } }
public static String formatAnnotatedConstructor(AnnotatedConstructor<?> constructor) { return Formats.formatSimpleClassName(constructor) + " " + Formats.addSpaceIfNeeded(Formats.formatAnnotations(constructor.getAnnotations())) + Formats.addSpaceIfNeeded(Formats.formatModifiers(constructor.getJavaMember().getModifiers())) + constructor.getDeclaringType().getJavaClass().getName() + Formats.formatAsFormalParameterList(constructor.getParameters()); }
private <T> UnbackedAnnotatedMember<T> findMatchingMember(UnbackedAnnotatedType<T> type, String id) { for (AnnotatedField<? super T> field : type.getFields()) { if (id.equals(AnnotatedTypes.createFieldId(field))) { return cast(field); } } for (AnnotatedMethod<? super T> method : type.getMethods()) { if (id.equals(AnnotatedTypes.createMethodId(method.getJavaMember(), method.getAnnotations(), method.getParameters()))) { return Reflections.cast(method); } } for (AnnotatedConstructor<T> constructor : type.getConstructors()) { if (id.equals(AnnotatedTypes.createConstructorId(constructor.getJavaMember(), constructor.getAnnotations(), constructor.getParameters()))) { return cast(constructor); } } throw BeanLogger.LOG.unableToLoadMember(id); } }
for (AnnotatedConstructor<?> constructor : type.getConstructors()) { if (constructor.isAnnotationPresent(Inject.class)) { if (injectConstructor != null) { throw WeldMessages.MESSAGES.moreThanOneBeanConstructor(componentClass); for (AnnotatedField<?> field : type.getFields()) { if (field.isAnnotationPresent(Inject.class)) { if (InjectionPoint.class.isAssignableFrom(field.getJavaMember().getType())) { throw WeldMessages.MESSAGES.attemptingToInjectInjectionPointIntoField(componentClass, field.getJavaMember()); for (AnnotatedMethod<?> method : type.getMethods()) { if (method.isAnnotationPresent(Inject.class)) { final List<Bean<?>> parameterBeans = new ArrayList<Bean<?>>(); final List<InjectionPoint> ips = new ArrayList<InjectionPoint>(); for (AnnotatedParameter<?> param : method.getParameters()) { final Set<Annotation> qualifiers = new HashSet<Annotation>(); for (Annotation annotation : param.getAnnotations()) { if (beanManager.isQualifier(annotation.annotationType())) { qualifiers.add(annotation); final Class<?> parameterType = method.getJavaMember().getParameterTypes()[param.getPosition()]; if (InjectionPoint.class.isAssignableFrom(parameterType)) { throw WeldMessages.MESSAGES.attemptingToInjectInjectionPointIntoNonBean(componentClass, method.getJavaMember());
for (AnnotatedConstructor<T> c : event.getAnnotatedType().getConstructors()) if (c.isAnnotationPresent(Current.class)) for (AnnotatedParameter<?> p : c.getParameters()) if (p.getTypeClosure().contains(Resource.class)) builderHolder.getBuilder().overrideConstructorParameterType(c.getJavaMember(), p.getPosition(), Resource.class); modifiedType = true; for (AnnotatedField<?> f : event.getAnnotatedType().getFields()) if (f.isAnnotationPresent(Current.class)) builderHolder.getBuilder().overrideFieldType(f.getJavaMember(), Resource.class); modifiedType = true; typeOverrides.put(replacement.getJavaClass(), replacement); event.setAnnotatedType(replacement);
private boolean annotatedTypeHasAnnotations(AnnotatedType annotatedType, Class<? extends Annotation>[] withAnnotations) if (hasAnnotation(annotatedType.getAnnotations(), withAnnotations)) Set<AnnotatedField> fields = annotatedType.getFields(); for (AnnotatedField annotatedField : fields) if (hasAnnotation(annotatedField.getAnnotations(), withAnnotations)) Set<AnnotatedMethod> annotatedMethods = annotatedType.getMethods(); for (AnnotatedMethod annotatedMethod : annotatedMethods) if (hasAnnotation(annotatedMethod.getAnnotations(), withAnnotations)) for (AnnotatedParameter annotatedParameter : (List<AnnotatedParameter>) annotatedMethod.getParameters()) if (hasAnnotation(annotatedParameter.getAnnotations(), withAnnotations)) for (AnnotatedConstructor<?> annotatedConstructor : annotatedConstructors) if (hasAnnotation(annotatedConstructor.getAnnotations(), withAnnotations)) for (AnnotatedParameter annotatedParameter : annotatedConstructor.getParameters()) if (hasAnnotation(annotatedParameter.getAnnotations(), withAnnotations))
for (Annotation annotation : annotatedType.getAnnotations()) { if (isEqualOrAnnotated(requiredAnnotation, annotation)) { return true; for (AnnotatedField<?> field : annotatedType.getFields()) { for (Annotation annotation : field.getAnnotations()) { if (isEqualOrAnnotated(requiredAnnotation, annotation)) { return true; for (AnnotatedConstructor<?> constructor : annotatedType.getConstructors()) { for (Annotation annotation : constructor.getAnnotations()) { if (isEqualOrAnnotated(requiredAnnotation, annotation)) { return true; for (AnnotatedParameter<?> parameter : constructor.getParameters()) { for (Annotation annotation : parameter.getAnnotations()) { if (isEqualOrAnnotated(requiredAnnotation, annotation)) { return true; for (AnnotatedMethod<?> method : annotatedType.getMethods()) { for (Annotation annotation : method.getAnnotations()) { if (isEqualOrAnnotated(requiredAnnotation, annotation)) { return true; for (AnnotatedParameter<?> parameter : method.getParameters()) { for (Annotation annotation : parameter.getAnnotations()) { if (isEqualOrAnnotated(requiredAnnotation, annotation)) { return true;
private void validateFilterAnnotatedType(AnnotatedType<TestFilter> type) { assertEquals(type.getBaseType(), TestFilter.class); assertTrue(typeSetMatches(type.getTypeClosure(), TestFilter.class, Filter.class, Object.class)); assertEquals(type.getFields().size(), 12); assertEquals(type.getConstructors().size(), 1); assertTrue(type.getConstructors().iterator().next().getParameters().isEmpty()); assertTrue(type.getMethods().stream().anyMatch(m -> m.getJavaMember().getName().equals("doFilter"))); }
static boolean hasAnnotation(AnnotatedType<?> type, Class<? extends Annotation> annotation) { if (type.isAnnotationPresent(annotation)) { return true; } for (AnnotatedMethod<?> method : type.getMethods()) { if (method.isAnnotationPresent(annotation)) { return true; } } for (AnnotatedConstructor<?> constructor : type.getConstructors()) { if (constructor.isAnnotationPresent(annotation)) { return true; } } for (AnnotatedField<?> field : type.getFields()) { if (field.isAnnotationPresent(annotation)) { return true; } } return false; }
AnnotatedMethod<? super AnimalShelter> annotatedMethod = methodConfigurator.getAnnotated(); annotatedMethodEqual.set(AnnotatedTypes.compareAnnotatedCallable( event.getAnnotatedType().getMethods().stream().filter(m -> m.getJavaMember().getName().equals("observesRoomInShelter")).findAny().get(), annotatedMethod)); .filterConstructors(ac -> ac.isAnnotationPresent(Inject.class)) .findFirst().get(); AnnotatedConstructor<AnimalShelter> originalAnnotatedConstructor = event.getAnnotatedType().getConstructors().stream() .filter(m -> m.isAnnotationPresent(Inject.class)).findAny().get(); .set(AnnotatedTypes.compareAnnotatedParameters(originalAnnotatedConstructor.getParameters(), configuratorAnnotatedConstructor.getParameters())); return annotatedField.getJavaMember().getName().equals("cat"); }).findFirst().get(); .compareAnnotatedField(event.getAnnotatedType().getFields().stream().filter(af -> af.getJavaMember().getName().equals("cat")).findAny().get(), annotatedField));
for (AnnotatedConstructor<X> constructor: annotatedType.getConstructors()) if (constructor.isAnnotationPresent(Inject.class)) for (AnnotatedField<? super X> field: annotatedType.getFields()) if (owner != null && Modifier.isPublic(field.getJavaMember().getModifiers()) && !field.isStatic()) if (field.isAnnotationPresent(Inject.class)) if (method.isAnnotationPresent(Inject.class) && !Modifier.isStatic(method.getJavaMember().getModifiers()))
void applyQualifier(Annotation qual, AnnotatedTypeBuilder<?> atb) { AnnotatedType<?> at = atb.create(); //do a loop on all field to replace annotation mark by CDI annotations for (AnnotatedField af : at.getFields()) if (af.isAnnotationPresent(InjectWithQualifier.class)) { atb.addToField(af, InjectLiteral.instance); atb.addToField(af, qual); } //loop on constructors to do the same for (AnnotatedConstructor ac : at.getConstructors()) { Annotation[][] pa = ac.getJavaMember().getParameterAnnotations(); //loop on args to detect marked param for (int i = 0; i < pa.length; i++) for (int j = 0; j < pa[i].length; j++) if (pa[i][j].equals(InjectWithQualifierLiteral.instance)) { atb.addToConstructor(ac, InjectLiteral.instance); atb.addToConstructorParameter(ac.getJavaMember(), i, qual); } } //loop on other methods (setters) for (AnnotatedMethod am : at.getMethods()) if (am.isAnnotationPresent(InjectWithQualifierLiteral.class)) { atb.addToMethod(am, InjectLiteral.instance); atb.addToMethod(am, qual); } }
public AnnotatedTypeWrapper(AnnotatedType<X> delegate, boolean keepOriginalAnnotations, Annotation... annotations) { super(delegate, keepOriginalAnnotations, annotations); this.delegate = delegate; this.constructors = new HashSet<AnnotatedConstructor<X>>(); for (AnnotatedConstructor<X> constructor : delegate.getConstructors()) { constructors.add(new AnnotatedConstructorWrapper<X>(constructor, this, true, constructor.getAnnotations().toArray( new Annotation[] { }))); } this.fields = new HashSet<AnnotatedField<? super X>>(); for (AnnotatedField<? super X> field : delegate.getFields()) { fields.add(new AnnotatedFieldWrapper(field, this, true, field.getAnnotations().toArray(new Annotation[] { }))); } this.methods = new HashSet<AnnotatedMethod<? super X>>(); for (AnnotatedMethod<? super X> method : delegate.getMethods()) { methods.add(new AnnotatedMethodWrapper(method, this, true, method.getAnnotations().toArray(new Annotation[] { }))); } }
private <T> void determineConstrainedConstructors(AnnotatedType<T> type, BeanDescriptor beanDescriptor, Set<AnnotatedCallable<? super T>> callables) { Class<?> clazz = type.getJavaClass(); EnumSet<ExecutableType> classLevelExecutableTypes = executableTypesDefinedOnType( clazz ); for ( AnnotatedConstructor<T> annotatedConstructor : type.getConstructors() ) { Constructor<?> constructor = annotatedConstructor.getJavaMember(); EnumSet<ExecutableType> memberLevelExecutableType = executableTypesDefinedOnConstructor( constructor ); if ( veto( classLevelExecutableTypes, memberLevelExecutableType, ExecutableType.CONSTRUCTORS ) ) { continue; } if ( beanDescriptor.getConstraintsForConstructor( constructor.getParameterTypes() ) != null ) { callables.add( annotatedConstructor ); } } }
public static boolean hasSimpleCdiConstructor(AnnotatedType<?> type) { for (AnnotatedConstructor<?> constructor : type.getConstructors()) { if (constructor.getParameters().isEmpty()) { return true; } if (constructor.isAnnotationPresent(Inject.class)) { return true; } } return false; }