private void recordAnnotatedGaugeSite(@Observes @WithAnnotations(Gauge.class) ProcessAnnotatedType<?> pat) { LOGGER.log(Level.FINE, () -> "### recordAnnoatedGaugeSite for class " + pat.getAnnotatedType().getJavaClass()); AnnotatedType<?> type = pat.getAnnotatedType(); LOGGER.log(Level.FINE, () -> "### Processing annotations for " + type.getJavaClass().getName()); // Register metrics based on annotations AnnotatedTypeConfigurator<?> configurator = pat.configureAnnotatedType(); Class<?> clazz = configurator.getAnnotated().getJavaClass(); // If abstract class, then handled by concrete subclasses if (Modifier.isAbstract(clazz.getModifiers())) { return; } // Process @Gauge methods keeping non-private declared on this class configurator.filterMethods(method -> method.getJavaMember().getDeclaringClass().equals(clazz) && !Modifier.isPrivate(method.getJavaMember().getModifiers()) && method.isAnnotationPresent(Gauge.class)) .forEach(method -> { Method javaMethod = method.getAnnotated().getJavaMember(); String explicitGaugeName = method.getAnnotated().getAnnotation(Gauge.class).name(); String gaugeName = String.format("%s.%s", clazz.getName(), explicitGaugeName != null && explicitGaugeName.length() > 0 ? explicitGaugeName : javaMethod.getName()); annotatedGaugeSites.put(gaugeName, method); LOGGER.log(Level.FINE, () -> String.format("### Recorded annotated gauge with name %s", gaugeName)); }); }
Class<?> clazz = configurator.getAnnotated().getJavaClass();
private void recordAnnotatedGaugeSite(@Observes @WithAnnotations(Gauge.class) ProcessAnnotatedType<?> pat) { LOGGER.log(Level.FINE, () -> "### recordAnnoatedGaugeSite for class " + pat.getAnnotatedType().getJavaClass()); AnnotatedType<?> type = pat.getAnnotatedType(); LOGGER.log(Level.FINE, () -> "### Processing annotations for " + type.getJavaClass().getName()); // Register metrics based on annotations AnnotatedTypeConfigurator<?> configurator = pat.configureAnnotatedType(); Class<?> clazz = configurator.getAnnotated().getJavaClass(); // If abstract class, then handled by concrete subclasses if (Modifier.isAbstract(clazz.getModifiers())) { return; } // Process @Gauge methods keeping non-private declared on this class configurator.filterMethods(method -> method.getJavaMember().getDeclaringClass().equals(clazz) && !Modifier.isPrivate(method.getJavaMember().getModifiers()) && method.isAnnotationPresent(Gauge.class)) .forEach(method -> { Method javaMethod = method.getAnnotated().getJavaMember(); String explicitGaugeName = method.getAnnotated().getAnnotation(Gauge.class).name(); String gaugeName = String.format("%s.%s", clazz.getName(), explicitGaugeName != null && explicitGaugeName.length() > 0 ? explicitGaugeName : javaMethod.getName()); annotatedGaugeSites.put(gaugeName, method); LOGGER.log(Level.FINE, () -> String.format("### Recorded annotated gauge with name %s", gaugeName)); }); }
void observesDogPAT(@Observes ProcessAnnotatedType<Dog> event) { annotatedTypesEqual.set(AnnotatedTypes.compareAnnotatedTypes(event.configureAnnotatedType().getAnnotated(), event.getAnnotatedType())); AnnotatedTypeConfigurator<Dog> annotatedTypeConfigurator = event.configureAnnotatedType(); // add @RequestScoped to Dog and @Inject and @Dogs to its Feed field annotatedTypeConfigurator.add(RequestScoped.Literal.INSTANCE) .filterFields(af -> (af.getJavaMember() .getName().equals("feed"))).findFirst().get().add(InjectLiteral.INSTANCE).add(Dogs.DogsLiteral.INSTANCE); // add @Inject to Dog constructor and @Dogs to its param annotatedTypeConfigurator.constructors().iterator().next().add(InjectLiteral.INSTANCE) .filterParams(ap -> ap.getPosition() == 0).findFirst().get().add(Dogs.DogsLiteral.INSTANCE); }
void observesCatPAT(@Observes ProcessAnnotatedType<Cat> event) { AnnotatedTypeConfigurator<Cat> annotatedTypeConfigurator = event.configureAnnotatedType(); originalCatAT = annotatedTypeConfigurator.getAnnotated(); // remove @RequestScoped from Cat annotatedTypeConfigurator.remove(a -> a.annotationType().equals(RequestScoped.class)); // remove @Produces and @Cats Cat.produceCatName() getAMConfiguratorByName(annotatedTypeConfigurator, "produceCatFeed").remove(a -> a.equals(ProducesLiteral.INSTANCE)) .remove(a -> a.equals(Cats.CatsLiteral.INSTANCE)); // remove @Inject from Cat.feed annotatedTypeConfigurator.filterFields(af -> af.getJavaMember().getName().equals("feed")).findFirst().get() .remove(a -> a.equals(InjectLiteral.INSTANCE)); // remove @Inject and @Cats from constructor with parameter annotatedTypeConfigurator.filterConstructors(ac -> ac.getParameters().size() == 1 && ac.getParameters().get(0).getBaseType().equals(Feed.class)) .findFirst().get().remove(a -> a.equals(InjectLiteral.INSTANCE)).params().get(0).remove(a -> a.equals(Cats.CatsLiteral.INSTANCE)); // remove @Observes from Cat.observesCatsFeed method parameter getAMConfiguratorByName(annotatedTypeConfigurator, "observesCatsFeed") .filterParams(ap -> ap.getPosition() == 0).findFirst().get().remove(a -> a.annotationType().equals(Observes.class)); }
Class<?> clazz = configurator.getAnnotated().getJavaClass();