Refine search
/** * Collects all FT methods in a set for later processing. * * @param event Event information. */ void registerFaultToleranceMethods(@Observes ProcessManagedBean<?> event) { AnnotatedType<?> type = event.getAnnotatedBeanClass(); for (AnnotatedMethod<?> method : type.getMethods()) { if (isFaultToleranceMethod(type.getJavaClass(), method.getJavaMember())) { getRegisteredMethods().add(new BeanMethod(type.getJavaClass(), method.getJavaMember())); } } }
private void validateTagLibraryListenerAnnotatedType(AnnotatedType<TagLibraryListener> type) { assertEquals(type.getBaseType(), TagLibraryListener.class); assertTrue(typeSetMatches(type.getTypeClosure(), TagLibraryListener.class, ServletContextListener.class, EventListener.class, Object.class)); assertEquals(type.getFields().size(), 2); assertEquals(type.getConstructors().size(), 1); assertTrue(type.getMethods().stream().anyMatch(m -> m.getJavaMember().getName().equals("contextInitialized"))); }
private void validateManagedBean(AnnotatedType<Farm> type) { assert type.getBaseType().equals(Farm.class); assert typeSetMatches(type.getTypeClosure(), Farm.class, Object.class); assert type.getFields().size() == 1; assert type.getFields().iterator().next().isAnnotationPresent(Produces.class); assert type.getMethods().size() == 1; assert type.getMethods().iterator().next().isAnnotationPresent(Produces.class); }
private void validateManagedBean(AnnotatedType<Farm> type) { assert type.getBaseType().equals(Farm.class); assert rawTypeSetMatches(type.getTypeClosure(), Farm.class, Object.class); assert type.getFields().size() == 1; assert type.getFields().iterator().next().isAnnotationPresent(Produces.class); assert type.getMethods().size() == 1; assert type.getMethods().iterator().next().isAnnotationPresent(Produces.class); }
private <T> void determineConstrainedMethods(AnnotatedType<T> type, BeanDescriptor beanDescriptor, Set<AnnotatedCallable<? super T>> callables) { List<Method> overriddenAndImplementedMethods = InheritedMethodsHelper.getAllMethods( type.getJavaClass() ); for ( AnnotatedMethod<? super T> annotatedMethod : type.getMethods() ) { Method method = annotatedMethod.getJavaMember(); Optional<String> correspondingProperty = getterPropertySelectionStrategyHelper.getProperty( method ); // obtain @ValidateOnExecution from the top-most method in the hierarchy Method methodForExecutableTypeRetrieval = replaceWithOverriddenOrInterfaceMethod( method, overriddenAndImplementedMethods ); EnumSet<ExecutableType> classLevelExecutableTypes = executableTypesDefinedOnType( methodForExecutableTypeRetrieval.getDeclaringClass() ); EnumSet<ExecutableType> memberLevelExecutableType = executableTypesDefinedOnMethod( methodForExecutableTypeRetrieval, correspondingProperty.isPresent() ); ExecutableType currentExecutableType = correspondingProperty.isPresent() ? ExecutableType.GETTER_METHODS : ExecutableType.NON_GETTER_METHODS; // validation is enabled per default, so explicit configuration can just veto whether // validation occurs if ( veto( classLevelExecutableTypes, memberLevelExecutableType, currentExecutableType ) ) { continue; } boolean needsValidation; if ( correspondingProperty.isPresent() ) { needsValidation = isGetterConstrained( beanDescriptor, method, correspondingProperty.get() ); } else { needsValidation = isNonGetterConstrained( beanDescriptor, method ); } if ( needsValidation ) { callables.add( annotatedMethod ); } } }
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"))); }
private void validateTagLibraryListenerAnnotatedType(AnnotatedType<TagLibraryListener> type) { assert type.getBaseType().equals(TagLibraryListener.class); assert rawTypeSetMatches(type.getTypeClosure(), TagLibraryListener.class, ServletContextListener.class, EventListener.class, Object.class); assert type.getFields().size() == 2; assert type.getConstructors().size() == 1; assert type.getMethods().size() == 3; }
protected <T> AnnotatedMethod<? super T> findFirstCreateMethod(AnnotatedType<T> cl) { for (AnnotatedMethod<? super T> method : cl.getMethods()) { if (method.getJavaMember().getName().startsWith("create")) return method; } return null; }
private void validateServletListenerAnnotatedType(AnnotatedType<TestListener> type) { assertEquals(type.getBaseType(), TestListener.class); assertTrue(type.getAnnotations().isEmpty()); assertEquals(type.getFields().size(), 2); assertTrue(type.getMethods().stream().anyMatch(m -> m.getJavaMember().getName().equals("contextInitialized"))); int initializers = 0; for (AnnotatedMethod<?> method : type.getMethods()) { assertEquals(method.getParameters().size(), 1); assertEquals(method.getBaseType(), void.class); if (method.isAnnotationPresent(Inject.class)) { initializers++; } } assertEquals(initializers, 1); }
private void validateSessionBeanInterceptor(AnnotatedType<SheepInterceptor> type) { assert type.getBaseType().equals(SheepInterceptor.class); assert rawTypeSetMatches(type.getTypeClosure(), SheepInterceptor.class, Object.class); assert type.getAnnotations().size() == 0; assert type.getFields().size() == 0; assert type.getMethods().size() == 1; }
public static AnnotatedMethod<?> findMethod(final AnnotatedType<?> type, final Method method) { AnnotatedMethod<?> annotatedMethod = null; for (final AnnotatedMethod<?> am : type.getMethods()) { if (am.getJavaMember().equals(method)) { annotatedMethod = am; break; } } if (annotatedMethod == null) { throw new IllegalStateException("No annotated method for " + method); } return annotatedMethod; } }
@SuppressWarnings("unchecked") private <X, A extends AnnotatedMember<? super X>> A getAnnotatedMember(Class<X> javaClass, String memberName) { AnnotatedType<X> type = getCurrentManager().createAnnotatedType(javaClass); for (AnnotatedField<? super X> field : type.getFields()) { if (field.getJavaMember().getName().equals(memberName)) { return (A) field; } } for (AnnotatedMethod<? super X> method : type.getMethods()) { if (method.getJavaMember().getName().equals(memberName)) { return (A) method; } } throw new IllegalArgumentException("Member " + memberName + " not found on " + javaClass); }
private void validateSessionBeanInterceptor(AnnotatedType<SheepInterceptor> type) { assert type.getBaseType().equals(SheepInterceptor.class); assert typeSetMatches(type.getTypeClosure(), SheepInterceptor.class, Object.class); assert type.getAnnotations().size() == 0; assert type.getFields().size() == 0; assert type.getMethods().size() == 1; }
private <X> AnnotatedMethod<? super X> getMethod(final ProcessAnnotatedType<X> annotatedType, final String name) { for (final AnnotatedMethod<? super X> annotatedMethod : annotatedType.getAnnotatedType().getMethods()) { if (name.equals(annotatedMethod.getJavaMember().getName())) { return annotatedMethod; } } throw new IllegalArgumentException("cannot find method on implementation class that is on the interface"); } }
/** * Generates a unique signature for an annotated type. Members without * annotations are omitted to reduce the length of the signature * * @param <X> * @param annotatedType * @return */ public static <X> String createTypeId(AnnotatedType<X> annotatedType) { return createTypeId(annotatedType.getJavaClass(), annotatedType.getAnnotations(), annotatedType.getMethods(), annotatedType.getFields(), annotatedType.getConstructors()); }
void processAnnotatedType(@Observes ProcessAnnotatedType<FruitObserver> pat) { peachObserver = pat.getAnnotatedType().getMethods().stream() .filter(annotatedMethod -> annotatedMethod.getJavaMember().getName().equals("observesPeach")).findAny().get(); }
public AnnotatedTypeConfiguratorImpl(AnnotatedType<T> annotatedType) { super(annotatedType); this.constructors = annotatedType.getConstructors().stream().map(c -> AnnotatedConstructorConfiguratorImpl.from(c)).collect(ImmutableSet.collector()); this.methods = annotatedType.getMethods().stream().map(m -> AnnotatedMethodConfiguratorImpl.from(m)).collect(ImmutableSet.collector()); this.fields = annotatedType.getFields().stream().map(f -> AnnotatedFieldConfiguratorImpl.from(f)).collect(ImmutableSet.collector()); }
private static List<Method> getBindingCdiAnnotationMethods(AnnotatedType<?> at) { List<Method> bindingMethods = new ArrayList<>(); for (AnnotatedMethod<?> method : at.getMethods()) { if (method.isAnnotationPresent(Nonbinding.class)) { continue; } bindingMethods.add(method.getJavaMember()); } return bindingMethods; }
private void validateServletListenerAnnotatedType(AnnotatedType<TestListener> type) { assert type.getBaseType().equals(TestListener.class); assert type.getAnnotations().isEmpty(); assert type.getFields().size() == 2; assert type.getMethods().size() == 3; int initializers = 0; for (AnnotatedMethod<?> method : type.getMethods()) { assert method.getParameters().size() == 1; assert method.getBaseType().equals(void.class); if (method.isAnnotationPresent(Inject.class)) { initializers++; } } assert initializers == 1; }
@Test @SpecAssertions({ @SpecAssertion(section = PROCESS_BEAN_ATTRIBUTES_EE, id = "bab") }) public void testSessionBeanAnnotated() { Annotated deltaAnnotated = extension.getAnnotatedMap().get(Delta.class); assertNotNull(deltaAnnotated); assertTrue(deltaAnnotated instanceof AnnotatedType); @SuppressWarnings("unchecked") AnnotatedType<Delta> deltaAnnotatedType = (AnnotatedType<Delta>) deltaAnnotated; assertEquals(deltaAnnotatedType.getJavaClass(), Delta.class); assertEquals(deltaAnnotatedType.getMethods().size(), 1); assertEquals(deltaAnnotatedType.getMethods().iterator().next().getJavaMember().getName(), "foo"); }