use of io.micronaut.core.annotation.Generated in project micronaut-aot by micronaut-projects.
the class AbstractStaticServiceLoaderSourceGenerator method generate.
@Override
public void generate(@NonNull AOTContext context) {
this.context = context;
if (serviceNames == null) {
serviceNames = context.getConfiguration().stringList(findOption(this.getClass(), SERVICE_TYPES).key());
}
if (substitutions == null) {
Set<String> resourceNames = new LinkedHashSet<>();
resourceNames.add("application");
context.getAnalyzer().getEnvironmentNames().stream().map(env -> "application-" + env).forEach(resourceNames::add);
context.getConfiguration().stringList(Environments.POSSIBLE_ENVIRONMENTS_NAMES).stream().filter(env -> !"default".equals(env)).map(env -> "application-" + env).forEach(resourceNames::add);
substitutions = new HashMap<>();
if (context.getConfiguration().isFeatureEnabled(YamlPropertySourceGenerator.ID)) {
YamlPropertySourceGenerator yaml = new YamlPropertySourceGenerator(resourceNames);
yaml.generate(context);
if (MetadataUtils.isEnabledOn(context.getRuntime(), yaml)) {
LOGGER.debug("Substituting {} with {}", PropertySourceLoader.class.getName(), yaml.getClass().getName());
substitutions.put(YamlPropertySourceLoader.class.getName(), yaml);
}
}
}
if (metadataProviderPredicate == null) {
metadataProviderPredicate = context.getAnalyzer().getAnnotationMetadataPredicate();
}
if (rejectedClasses == null) {
List<String> strings = context.getConfiguration().stringList(findOption(this.getClass(), REJECTED_CLASSES).key());
Set<String> rejected = strings.isEmpty() ? Collections.emptySet() : new HashSet<>(strings);
rejectedClasses = rejected::contains;
}
if (forceInclude == null) {
forceInclude = new HashSet<>(context.getConfiguration().stringList(findOption(this.getClass(), FORCE_INCLUDE).key()));
}
for (String serviceName : serviceNames) {
LOGGER.debug("Processing service type {}", serviceName);
collectServiceImplementations(serviceName);
}
context.put(Substitutes.class, substitutes);
for (BeanConfiguration beanConfiguration : disabledConfigurations) {
for (List<Class<?>> classList : serviceClasses.values()) {
for (Class<?> clazz : classList) {
if (beanConfiguration.isWithin(clazz)) {
context.addDiagnostics(SERVICE_LOADING_CATEGORY, "Disabling " + clazz.getName() + " because it belongs to " + beanConfiguration.getName() + " which is disabled (" + beanConfiguration.getClass() + ")");
disabledServices.add(clazz);
}
}
}
}
generateServiceLoader();
LOGGER.debug("Generated static service loader classes: {}", staticServiceClasses.keySet());
LOGGER.debug("Generated static {} service loader substitutions", substitutes.values().size());
staticServiceClasses.values().stream().map(context::javaFile).forEach(context::registerGeneratedSourceFile);
context.registerStaticOptimization("StaticServicesLoader", SoftServiceLoader.Optimizations.class, this::buildOptimization);
}
use of io.micronaut.core.annotation.Generated in project micronaut-core by micronaut-projects.
the class ServiceDescriptionProcessor method processGeneratedAnnotation.
private boolean processGeneratedAnnotation(List<io.micronaut.inject.ast.Element> originatingElements, Element element, TypeElement typeElement, String name) {
Generated generated = element.getAnnotation(Generated.class);
if (generated != null) {
String serviceName = generated.service();
if (StringUtils.isNotEmpty(serviceName)) {
serviceDescriptors.computeIfAbsent(serviceName, s1 -> new HashSet<>()).add(name);
originatingElements.add(new JavaClassElement(typeElement, AnnotationMetadata.EMPTY_METADATA, null));
}
return true;
}
return false;
}
Aggregations