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 <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 ); } } }
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 <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"); } }
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; } }
void processAnnotatedType(@Observes ProcessAnnotatedType<FruitObserver> pat) { peachObserver = pat.getAnnotatedType().getMethods().stream() .filter(annotatedMethod -> annotatedMethod.getJavaMember().getName().equals("observesPeach")).findAny().get(); }
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; }
/** * Finds any method matching the method name and parameter types. */ public static <X> AnnotatedMethod<? super X> findMethod(AnnotatedType<X> type, String methodName, Class<?> []param) { for (AnnotatedMethod<? super X> annMethod : type.getMethods()) { Method method = annMethod.getJavaMember(); if (! method.getName().equals(methodName)) continue; if (isMatch(param, method.getParameterTypes())) return annMethod; } return null; }
@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"); }
@Test @SpecAssertion(section = PROCESS_ANNOTATED_TYPE, id = "ba") public void testGetAnnotatedType() { AnnotatedType<Dog> annotatedType = ProcessAnnotatedTypeObserver.getDogAnnotatedType(); assertEquals(annotatedType.getBaseType(), Dog.class); Set<AnnotatedMethod<? super Dog>> annotatedMethods = annotatedType.getMethods(); assertEquals(annotatedMethods.size(), 3); for (AnnotatedMethod<? super Dog> annotatedMethod : annotatedMethods) { Set<String> validMethodNames = new HashSet<String>(Arrays.asList("bite", "live", "drinkMilk")); if (!validMethodNames.contains(annotatedMethod.getJavaMember().getName())) { fail("Invalid method name found" + annotatedMethod.getJavaMember().getName()); } } }
public <T> void analyze(AnnotatedType<T> annotatedType, Bean<T> bean) { LOGGER.info("Scanning Type: " + annotatedType.getJavaClass()); Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods(); methods.stream() .filter(method -> method.isAnnotationPresent(Incoming.class) || method.isAnnotationPresent(Outgoing.class)) .forEach(method -> collected.add(method.getJavaMember(), bean)); }
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"))); }
public static List<AnnotatedMethod<?>> getInterceptableMethods(AnnotatedType<?> type) { List<AnnotatedMethod<?>> annotatedMethods = new ArrayList<AnnotatedMethod<?>>(); for (AnnotatedMethod<?> annotatedMethod : type.getMethods()) { boolean businessMethod = !annotatedMethod.isStatic() && !annotatedMethod.isAnnotationPresent(Inject.class) && !annotatedMethod.getJavaMember().isBridge(); if (businessMethod && !isInterceptorMethod(annotatedMethod)) { annotatedMethods.add(annotatedMethod); } } return annotatedMethods; }
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"))); }
@Test @SpecAssertion(section = ALTERNATIVE_METADATA_SOURCES, id = "aab") public void testMethods() { AnnotatedType<WildCat> annotatedType = getCurrentManager().createAnnotatedType(WildCat.class); Set<AnnotatedMethod<? super WildCat>> methods = annotatedType.getMethods(); String[] names = new String[] { "yowl", "jump", "bite", "getName" }; assertEquals(methods.size(), 4); for (AnnotatedMethod<? super WildCat> method : methods) { // Just simple test for method name assertTrue(arrayContains(names, method.getJavaMember().getName())); } }
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); }
protected ArrayList<Method> getLifecycleMethods(Class<? extends Annotation> annType) { ArrayList<Method> methods = new ArrayList<Method>(); for (AnnotatedMethod<? super X> method : getBeanType().getMethods()) { if (! method.isAnnotationPresent(annType)) continue; if (method.getParameters().size() != 0) continue; methods.add(method.getJavaMember()); } Collections.sort(methods, new PostConstructComparator()); return methods; }
@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); }
/** * Introspects the lifecycle methods */ public void introspectTimer(AnnotatedType<X> apiClass) { Class<X> cl = apiClass.getJavaClass(); if (cl == null || cl.equals(Object.class)) return; if (TimedObject.class.isAssignableFrom(cl)) { _timeoutMethod = "ejbTimeout"; return; } for (AnnotatedMethod<? super X> apiMethod : apiClass.getMethods()) { Method method = apiMethod.getJavaMember(); if (method.isAnnotationPresent(Timeout.class)) { if ((method.getParameterTypes().length != 0) && (method.getParameterTypes().length != 1 || ! Timer.class.equals(method.getParameterTypes()[0]))) { throw new ConfigException(L.l( "{0}: timeout method '{1}' does not have a (Timer) parameter", cl .getName(), method.getName())); } _timeoutMethod = method.getName(); addBusinessMethod(apiMethod); } } }
private void camelFactoryProducers(@Observes ProcessAnnotatedType<CdiCamelFactory> pat, BeanManager manager) { pat.setAnnotatedType( new AnnotatedTypeDelegate<>( pat.getAnnotatedType(), pat.getAnnotatedType().getMethods().stream() .filter(am -> am.isAnnotationPresent(Produces.class)) .filter(am -> am.getTypeClosure().stream().noneMatch(isEqual(TypeConverter.class))) .peek(am -> producerQualifiers.put(am.getJavaMember(), getQualifiers(am, manager))) .map(am -> new AnnotatedMethodDelegate<>(am, am.getAnnotations().stream() .filter(annotation -> !manager.isQualifier(annotation.annotationType())) .collect(collectingAndThen(toSet(), annotations -> { annotations.add(EXCLUDED); return annotations; })))) .collect(toSet()))); }