diff --git a/aot-api/src/main/java/io/micronaut/aot/MicronautAotOptimizer.java b/aot-api/src/main/java/io/micronaut/aot/MicronautAotOptimizer.java
index d75feeed..0281eecb 100644
--- a/aot-api/src/main/java/io/micronaut/aot/MicronautAotOptimizer.java
+++ b/aot-api/src/main/java/io/micronaut/aot/MicronautAotOptimizer.java
@@ -58,7 +58,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Deque;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
@@ -73,13 +72,13 @@
* generation at build time. Its role is to generate a bunch of
* source code for various optimizations which can be computed
* at build time.
- *
+ *
* Typically, generated code will involve the generation of an
* "optimized" entry point for the application, which delegates
* to the main entry point, but also performs some static
* initialization by making calls to the
* {@link io.micronaut.core.optim.StaticOptimizations} class.
- *
+ *
* The Micronaut AOT optimizer is experimental and won't do
* anything by its own: it must be integrated in some form, for
* example via a build plugin, which in turn will make the generated
@@ -87,7 +86,7 @@
* call this class to generate the optimization code, and in addition
* create an optimized jar, an optimized native binary or even a
* full distribution.
- *
+ *
* The optimizer works by passing in the whole application runtime
* classpath and a set of configuration options. It then analyzes
* the classpath, for example to identify the services to be loaded,
@@ -119,9 +118,9 @@ private MicronautAotOptimizer(List classpath,
private void compileGeneratedSources(List extraClasspath, List javaFiles) {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- DiagnosticCollector ds = new DiagnosticCollector<>();
+ var ds = new DiagnosticCollector();
try (StandardJavaFileManager mgr = compiler.getStandardFileManager(ds, null, null)) {
- List fullClasspath = new ArrayList<>(classpath);
+ var fullClasspath = new ArrayList<>(classpath);
fullClasspath.addAll(extraClasspath);
List options = compilerOptions(outputClassesDirectory, fullClasspath);
List filesToCompile = outputSourceFilesToSourceDir(outputSourcesDirectory, javaFiles);
@@ -134,8 +133,8 @@ private void compileGeneratedSources(List extraClasspath, List j
throw new RuntimeException("Unable to compile generated classes", e);
}
List> diagnostics = ds.getDiagnostics().stream()
- .filter(d -> d.getKind() == Diagnostic.Kind.ERROR)
- .collect(Collectors.toList());
+ .filter(d -> d.getKind() == Diagnostic.Kind.ERROR)
+ .toList();
if (!diagnostics.isEmpty()) {
throwCompilationError(diagnostics);
}
@@ -150,21 +149,21 @@ private void compileGeneratedSources(List extraClasspath, List j
*/
public static void exportConfiguration(String runtime, File propertiesFile) {
List list = SourceGeneratorLoader.list(Runtime.valueOf(runtime.toUpperCase(Locale.ENGLISH)));
- try (PrintWriter wrt = new PrintWriter(new FileOutputStream(propertiesFile))) {
- Deque queue = new ArrayDeque<>(list);
+ try (var wrt = new PrintWriter(new FileOutputStream(propertiesFile))) {
+ var queue = new ArrayDeque<>(list);
while (!queue.isEmpty()) {
AOTModule generator = queue.pop();
if (!generator.description().isEmpty()) {
Arrays.stream(generator.description().split("\r?\n")).forEach(line ->
- wrt.println("# " + line));
+ wrt.println("# " + line));
}
wrt.println(generator.id() + ".enabled = true");
Arrays.stream(generator.subgenerators())
- .map(MetadataUtils::findMetadata)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .sorted(Collections.reverseOrder())
- .forEachOrdered(queue::addFirst);
+ .map(MetadataUtils::findMetadata)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .sorted(Collections.reverseOrder())
+ .forEachOrdered(queue::addFirst);
for (Option option : generator.options()) {
wrt.println(toPropertiesSample(option));
}
@@ -190,16 +189,16 @@ public static void exportConfiguration(String runtime, File propertiesFile) {
* @param props the configuration properties
*/
public static void execute(Properties props) {
- Configuration config = new DefaultConfiguration(props);
+ var config = new DefaultConfiguration(props);
String pkg = config.mandatoryValue(GENERATED_PACKAGE);
- File outputDir = new File(config.mandatoryValue(OUTPUT_DIRECTORY));
- File sourcesDir = new File(outputDir, "sources");
- File classesDir = new File(outputDir, "classes");
- File logsDir = new File(outputDir, "logs");
+ var outputDir = new File(config.mandatoryValue(OUTPUT_DIRECTORY));
+ var sourcesDir = new File(outputDir, "sources");
+ var classesDir = new File(outputDir, "classes");
+ var logsDir = new File(outputDir, "logs");
runner(pkg, sourcesDir, classesDir, logsDir, config)
- .addClasspath(config.stringList(CLASSPATH).stream().map(File::new).collect(Collectors.toList()))
- .execute();
+ .addClasspath(config.stringList(CLASSPATH).stream().map(File::new).collect(Collectors.toList()))
+ .execute();
}
public static Runner runner(String generatedPackage,
@@ -211,7 +210,7 @@ public static Runner runner(String generatedPackage,
}
private static List outputSourceFilesToSourceDir(File srcDir, List javaFiles) {
- List srcFiles = new ArrayList<>(javaFiles.size());
+ var srcFiles = new ArrayList(javaFiles.size());
if (srcDir.isDirectory() || srcDir.mkdirs()) {
StreamHelper.trying(() -> {
for (JavaFile javaFile : javaFiles) {
@@ -230,7 +229,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
}
private static void throwCompilationError(List> diagnostics) {
- StringBuilder sb = new StringBuilder("Compilation errors:\n");
+ var sb = new StringBuilder("Compilation errors:\n");
for (Diagnostic extends JavaFileObject> d : diagnostics) {
JavaFileObject source = d.getSource();
String srcFile = source == null ? "unknown" : new File(source.toUri()).getName();
@@ -242,11 +241,11 @@ private static void throwCompilationError(List compilerOptions(File dstDir,
List classPath) {
- List options = new ArrayList<>();
+ var options = new ArrayList();
options.add("-source");
- options.add("1.8");
+ options.add("17");
options.add("-target");
- options.add("1.8");
+ options.add("17");
options.add("-classpath");
String cp = classPath.stream().map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator));
options.add(cp);
@@ -259,15 +258,15 @@ private void writeLogs(DefaultSourceGenerationContext context) {
if (logsDirectory.isDirectory() || logsDirectory.mkdirs()) {
writeLines(new File(logsDirectory, OUTPUT_RESOURCES_FILE_NAME), context.getExcludedResources());
context.getDiagnostics().forEach((key, messages) -> {
- File logFile = new File(logsDirectory, key.toLowerCase(Locale.US) + ".log");
+ var logFile = new File(logsDirectory, key.toLowerCase(Locale.US) + ".log");
writeLines(logFile, messages);
});
}
}
private static void writeLines(File outputFile, Collection lines) {
- try (PrintWriter writer = new PrintWriter(
- new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)
+ try (var writer = new PrintWriter(
+ new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)
)) {
lines.forEach(writer::println);
} catch (FileNotFoundException e) {
@@ -318,13 +317,12 @@ public Runner addClasspath(Collection elements) {
return this;
}
- @SuppressWarnings("unchecked")
public Runner execute() {
- MicronautAotOptimizer optimizer = new MicronautAotOptimizer(
- classpath,
- outputSourcesDirectory,
- outputClassesDirectory,
- logsDirectory);
+ var optimizer = new MicronautAotOptimizer(
+ classpath,
+ outputSourcesDirectory,
+ outputClassesDirectory,
+ logsDirectory);
ApplicationContextAnalyzer analyzer = ApplicationContextAnalyzer.create(spec -> {
if (config.containsKey(Environments.TARGET_ENVIRONMENTS_NAMES)) {
List targetEnvs = config.stringList(Environments.TARGET_ENVIRONMENTS_NAMES);
@@ -335,10 +333,10 @@ public Runner execute() {
});
Set environmentNames = analyzer.getEnvironmentNames();
LOGGER.info("Analysis will be performed with active environments: {}", environmentNames);
- DefaultSourceGenerationContext context = new DefaultSourceGenerationContext(generatedPackage, analyzer, config, outputClassesDirectory.toPath());
+ var context = new DefaultSourceGenerationContext(generatedPackage, analyzer, config, outputClassesDirectory.toPath());
List sourceGenerators = SourceGeneratorLoader.load(config.getRuntime(), context);
ApplicationContextConfigurerGenerator generator = new ApplicationContextConfigurerGenerator(
- sourceGenerators
+ sourceGenerators
);
generator.generate(context);
optimizer.compileGeneratedSources(context.getExtraClasspath(), context.getGeneratedJavaFiles());
diff --git a/aot-cli/src/main/java/io/micronaut/aot/cli/Main.java b/aot-cli/src/main/java/io/micronaut/aot/cli/Main.java
index 539593cc..d24cc2bc 100644
--- a/aot-cli/src/main/java/io/micronaut/aot/cli/Main.java
+++ b/aot-cli/src/main/java/io/micronaut/aot/cli/Main.java
@@ -63,9 +63,9 @@ public class Main implements Runnable, ConfigKeys {
@Override
public void run() {
List classpath = toURLs(classpathString);
- Properties props = new Properties();
+ var props = new Properties();
if (config.exists()) {
- try (InputStreamReader reader = new InputStreamReader(new FileInputStream(config))) {
+ try (var reader = new InputStreamReader(new FileInputStream(config))) {
props.load(reader);
} catch (IOException e) {
throw new RuntimeException(e);
@@ -97,7 +97,7 @@ public void run() {
* @param ctxClassLoader the current context classloader
*/
private void executeInIsolatedLoader(Properties props, URL[] urls, ClassLoader ctxClassLoader) {
- URLClassLoader cl = new URLClassLoader(urls, new FilteringClassLoader(ctxClassLoader));
+ var cl = new URLClassLoader(urls, new FilteringClassLoader(ctxClassLoader));
try {
Thread.currentThread().setContextClassLoader(cl);
Class> runnerClass = cl.loadClass("io.micronaut.aot.MicronautAotOptimizer");
@@ -127,7 +127,7 @@ private static List toURLs(String classpathString) {
}
})
.filter(Objects::nonNull)
- .collect(Collectors.toList());
+ .toList();
}
public static int execute(String[] args) {
diff --git a/aot-cli/src/main/java/io/micronaut/aot/cli/VersionProvider.java b/aot-cli/src/main/java/io/micronaut/aot/cli/VersionProvider.java
index 28061392..a6b58b80 100644
--- a/aot-cli/src/main/java/io/micronaut/aot/cli/VersionProvider.java
+++ b/aot-cli/src/main/java/io/micronaut/aot/cli/VersionProvider.java
@@ -32,15 +32,15 @@ public class VersionProvider implements CommandLine.IVersionProvider {
static {
String text = "unknown";
- try (InputStream stream = VersionProvider.class.getResourceAsStream("/version.txt")) {
- text = new BufferedReader(
- new InputStreamReader(stream, StandardCharsets.UTF_8))
- .lines()
- .collect(Collectors.joining("\n"));
- } catch (Exception ex) {
- // noop
- }
- VERSION = text;
+ try (InputStream stream = VersionProvider.class.getResourceAsStream("/version.txt")) {
+ text = new BufferedReader(
+ new InputStreamReader(stream, StandardCharsets.UTF_8))
+ .lines()
+ .collect(Collectors.joining("\n"));
+ } catch (Exception ex) {
+ // noop
+ }
+ VERSION = text;
}
@Override
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/AOTCodeGenerator.java b/aot-core/src/main/java/io/micronaut/aot/core/AOTCodeGenerator.java
index 39deb28f..6ffb1c98 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/AOTCodeGenerator.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/AOTCodeGenerator.java
@@ -31,7 +31,7 @@
*
one or more source files
*
one or more resource files
*
- *
+ *
* Code generators must be annotated with {@link AOTModule}.
*/
public interface AOTCodeGenerator {
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/AOTContext.java b/aot-core/src/main/java/io/micronaut/aot/core/AOTContext.java
index cc287f29..c59357e8 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/AOTContext.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/AOTContext.java
@@ -45,6 +45,7 @@ public interface AOTContext {
/**
* Returns the source generators configuration.
+ *
* @return the configuration
*/
@NonNull
@@ -52,6 +53,7 @@ public interface AOTContext {
/**
* Returns the application context analyzer.
+ *
* @return the application context analyzer
*/
@NonNull
@@ -59,6 +61,7 @@ public interface AOTContext {
/**
* Registers a generated source file.
+ *
* @param javaFile the file to be added.
*/
void registerGeneratedSourceFile(@NonNull JavaFile javaFile);
@@ -66,6 +69,7 @@ public interface AOTContext {
/**
* Registers a code block to be executed statically when
* the optimized binary is loaded.
+ *
* @param staticInitializer the static initializer method
*/
void registerStaticInitializer(MethodSpec staticInitializer);
@@ -75,6 +79,7 @@ public interface AOTContext {
* create a class which implements the {@link io.micronaut.core.optim.StaticOptimizations}
* service type. The consumer should create a body which returns
* an instance of the optimization type.
+ *
* @param className the name of the class to generate
* @param optimizationKind the type of the optimization
* @param bodyBuilder the builder of the body of the load() method
@@ -84,6 +89,7 @@ public interface AOTContext {
/**
* Registers a generated service type.
+ *
* @param serviceType the type of the service
* @param simpleServiceName the simple name of the generated type
*/
@@ -91,6 +97,7 @@ public interface AOTContext {
/**
* Registers a new generated resource.
+ *
* @param path the relative path to the resource (including file name)
* @param consumer the consumer to be called when the resource is generated.
*/
@@ -118,12 +125,14 @@ public interface AOTContext {
/**
* Registers a type as a requiring initialization at build time.
+ *
* @param className the type
*/
void registerBuildTimeInit(@NonNull String className);
/**
* Generates a java file spec.
+ *
* @param typeSpec the type spec of the main class
* @return a java file
*/
@@ -144,6 +153,7 @@ public interface AOTContext {
/**
* Stores an entry in the context. The entry may be read by other
* processors, as long as they are executed in the proper order.
+ *
* @param type the class of the value to store
* @param value the value to store
* @param the type of the value
@@ -152,6 +162,7 @@ public interface AOTContext {
/**
* Reads an entry from the context.
+ *
* @param type the class of the entry
* @param the type of the entry
* @return an empty value if absent
@@ -161,6 +172,7 @@ public interface AOTContext {
/**
* Returns the diagnostics map.
+ *
* @return the diagnostics
*/
@NonNull
@@ -168,13 +180,15 @@ public interface AOTContext {
/**
* Returns the target runtime environment.
+ *
* @return target runtime
*/
@NonNull
Runtime getRuntime();
/**
- * Returns the set of classes which require build time initialization
+ * Returns the set of classes which require build time initialization.
+ *
* @return the set of classes needing build time init
*/
Set getBuildTimeInitClasses();
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/AOTModule.java b/aot-core/src/main/java/io/micronaut/aot/core/AOTModule.java
index 6dc85969..200f1210 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/AOTModule.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/AOTModule.java
@@ -28,6 +28,7 @@
public @interface AOTModule {
/**
* A unique identifier for this source generator.
+ *
* @return the id
*/
String id();
@@ -36,6 +37,7 @@
* Returns a description for this source generator.
* Description is optional because some code generators
* are purely internal and not exposed to users.
+ *
* @return a description or an empty options
*/
String description() default "";
@@ -43,6 +45,7 @@
/**
* Returns the identifiers of source generators which must
* be executed before this generator is called.
+ *
* @return the list of ids
*/
String[] dependencies() default {};
@@ -60,14 +63,16 @@
/**
* Returns the set of configuration keys which affect
* the configuration of this source generator.
+ *
* @return a set of configuration keys
*/
Option[] options() default {};
/**
* Returns the runtimes this module is valid for.
+ *
* @return the list of runtimes this module applies to.
*/
- Runtime[] enabledOn() default { Runtime.JIT, Runtime.NATIVE };
+ Runtime[] enabledOn() default {Runtime.JIT, Runtime.NATIVE};
}
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/Configuration.java b/aot-core/src/main/java/io/micronaut/aot/core/Configuration.java
index 251b0fb8..a9daac0b 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/Configuration.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/Configuration.java
@@ -33,6 +33,7 @@ public interface Configuration {
/**
* Returns true if the configuration contains an entry
* for the specified key.
+ *
* @param key the key to look for
* @return true if the configuration contains an entry for the key
*/
@@ -98,10 +99,10 @@ default List stringList(@NonNull String key) {
@NonNull
default List stringList(@NonNull String key, @NonNull String separator) {
return optionalValue(key, opt -> opt.map(string ->
- Arrays.stream(string.split(separator))
- .filter(Objects::nonNull)
- .filter(s -> !s.trim().isEmpty())
- .collect(Collectors.toList())
+ Arrays.stream(string.split(separator))
+ .filter(Objects::nonNull)
+ .filter(s -> !s.trim().isEmpty())
+ .collect(Collectors.toList())
).orElse(Collections.emptyList()));
}
@@ -131,6 +132,7 @@ default boolean isFeatureEnabled(@NonNull String featureId) {
/**
* Returns the target runtime for optimizations.
+ *
* @return the target runtime
*/
@NonNull
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/Option.java b/aot-core/src/main/java/io/micronaut/aot/core/Option.java
index 89bd0ea9..59eacc39 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/Option.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/Option.java
@@ -21,18 +21,21 @@
public @interface Option {
/**
* Returns the key used to configure this option.
+ *
* @return the key, as found in properties
*/
String key();
/**
* Returns a description of this configuration option.
+ *
* @return the description
*/
String description() default "";
/**
* Returns a sample value for this option, if any.
+ *
* @return a sample value
*/
String sampleValue() default "";
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/Runtime.java b/aot-core/src/main/java/io/micronaut/aot/core/Runtime.java
index c89a613a..4b6ef87c 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/Runtime.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/Runtime.java
@@ -16,7 +16,7 @@
package io.micronaut.aot.core;
/**
- * The targetted type of runtime.
+ * The targeted type of runtime.
*/
public enum Runtime {
JIT("JIT"),
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/codegen/AbstractCodeGenerator.java b/aot-core/src/main/java/io/micronaut/aot/core/codegen/AbstractCodeGenerator.java
index 0bef6d6a..4eb57410 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/codegen/AbstractCodeGenerator.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/codegen/AbstractCodeGenerator.java
@@ -34,7 +34,7 @@ public static String simpleNameOf(String fqcn) {
protected static MethodSpec staticMethodBuilder(String name, Consumer super MethodSpec.Builder> consumer) {
MethodSpec.Builder builder = MethodSpec.methodBuilder(name)
- .addModifiers(Modifier.PRIVATE, Modifier.STATIC);
+ .addModifiers(Modifier.PRIVATE, Modifier.STATIC);
consumer.accept(builder);
return builder.build();
}
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/codegen/ApplicationContextConfigurerGenerator.java b/aot-core/src/main/java/io/micronaut/aot/core/codegen/ApplicationContextConfigurerGenerator.java
index ccc3acb9..0b07d4e2 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/codegen/ApplicationContextConfigurerGenerator.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/codegen/ApplicationContextConfigurerGenerator.java
@@ -26,8 +26,8 @@
import io.micronaut.context.ApplicationContextBuilder;
import io.micronaut.context.ApplicationContextConfigurer;
import io.micronaut.core.annotation.NonNull;
+import io.micronaut.core.util.CollectionUtils;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -40,7 +40,7 @@
* it is responsible for generating a new entry point, which delegates
* to the original entry point of the application, and injects a number
* of optimizations before starting the application.
- *
+ *
* The list of optimizations to inject is determined by the list of
* delegate optimizers which are passed to this generator.
*/
@@ -58,10 +58,10 @@ public ApplicationContextConfigurerGenerator(List sourceGenera
@Override
public void generate(@NonNull AOTContext context) {
TypeSpec.Builder optimizedEntryPoint = TypeSpec.classBuilder(CUSTOMIZER_CLASS_NAME)
- .addSuperinterface(ApplicationContextConfigurer.class)
- .addModifiers(PUBLIC);
+ .addSuperinterface(ApplicationContextConfigurer.class)
+ .addModifiers(PUBLIC);
CodeBlock.Builder staticInitializer = CodeBlock.builder();
- StaticInitializerCapturingContext capturer = new StaticInitializerCapturingContext(context, optimizedEntryPoint, staticInitializer);
+ var capturer = new StaticInitializerCapturingContext(context, optimizedEntryPoint, staticInitializer);
for (AOTCodeGenerator sourceGenerator : sourceGenerators) {
sourceGenerator.generate(capturer);
}
@@ -74,17 +74,17 @@ public void generate(@NonNull AOTContext context) {
private void addDiagnostics(AOTContext context, TypeSpec.Builder optimizedEntryPoint) {
MethodSpec.Builder configure = MethodSpec.methodBuilder("configure")
- .addModifiers(PUBLIC)
- .addAnnotation(Override.class)
- .addParameter(ApplicationContextBuilder.class, "builder");
- MapGenerator mapGenerator = new MapGenerator();
+ .addModifiers(PUBLIC)
+ .addAnnotation(Override.class)
+ .addParameter(ApplicationContextBuilder.class, "builder");
+ var mapGenerator = new MapGenerator();
CodeBlock mapBlock = mapGenerator.generateMap(optimizedEntryPoint, createDiagnosticsMap(context));
configure.addStatement("builder.properties($L)", mapBlock);
optimizedEntryPoint.addMethod(configure.build());
}
private Map createDiagnosticsMap(AOTContext context) {
- Map values = new LinkedHashMap<>();
+ var values = CollectionUtils.newLinkedHashMap(3);
values.put("micronaut.aot.enabled", true);
values.put("micronaut.aot.runtime", context.getRuntime().toString());
values.put("micronaut.aot.optimizations", buildOptimizationList());
@@ -93,12 +93,12 @@ private Map createDiagnosticsMap(AOTContext context) {
private List buildOptimizationList() {
return sourceGenerators.stream()
- .map(Object::getClass)
- .map(MetadataUtils::findMetadata)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .map(AOTModule::id)
- .collect(Collectors.toList());
+ .map(Object::getClass)
+ .map(MetadataUtils::findMetadata)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .map(AOTModule::id)
+ .collect(Collectors.toList());
}
private static final class StaticInitializerCapturingContext extends DelegatingSourceGenerationContext {
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/codegen/DelegatingSourceGenerationContext.java b/aot-core/src/main/java/io/micronaut/aot/core/codegen/DelegatingSourceGenerationContext.java
index c2c213c6..6d54c371 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/codegen/DelegatingSourceGenerationContext.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/codegen/DelegatingSourceGenerationContext.java
@@ -19,9 +19,9 @@
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
+import io.micronaut.aot.core.AOTContext;
import io.micronaut.aot.core.Configuration;
import io.micronaut.aot.core.Runtime;
-import io.micronaut.aot.core.AOTContext;
import io.micronaut.aot.core.context.ApplicationContextAnalyzer;
import io.micronaut.core.annotation.NonNull;
@@ -88,7 +88,8 @@ public void registerStaticOptimization(String className, Class optimizati
/**
* Registers a generated service type.
- * @param serviceType the type of the service
+ *
+ * @param serviceType the type of the service
* @param simpleServiceName the simple name of the generated type
*/
@Override
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/codegen/MapGenerator.java b/aot-core/src/main/java/io/micronaut/aot/core/codegen/MapGenerator.java
index 91391664..ef27a2dd 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/codegen/MapGenerator.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/codegen/MapGenerator.java
@@ -51,19 +51,18 @@ public final CodeBlock generateMap(TypeSpec.Builder builder, Map
private String convertValueToSource(Object value, TypeSpec.Builder builder) {
if (value == null) {
return "null";
+ }
+ Class> valueClass = value.getClass();
+ if (CharSequence.class.isAssignableFrom(valueClass)) {
+ return CodeBlock.of("$S", value).toString();
+ } else if (Number.class.isAssignableFrom(valueClass) || Boolean.class.isAssignableFrom(valueClass)) {
+ return convertNumberOrBoolean(valueClass, value);
+ } else if (List.class.isAssignableFrom(valueClass)) {
+ return generateListMethod((List>) value, builder);
+ } else if (Map.class.isAssignableFrom(valueClass)) {
+ return generateMapMethod((Map, ?>) value, builder);
} else {
- Class> valueClass = value.getClass();
- if (CharSequence.class.isAssignableFrom(valueClass)) {
- return CodeBlock.of("$S", value).toString();
- } else if (Number.class.isAssignableFrom(valueClass) || Boolean.class.isAssignableFrom(valueClass)) {
- return convertNumberOrBoolean(valueClass, value);
- } else if (List.class.isAssignableFrom(valueClass)) {
- return generateListMethod((List>) value, builder);
- } else if (Map.class.isAssignableFrom(valueClass)) {
- return generateMapMethod((Map, ?>) value, builder);
- } else {
- throw new UnsupportedOperationException("Configuration map contains an entry of type " + valueClass + " which is not supported yet. Please file a bug report.");
- }
+ throw new UnsupportedOperationException("Configuration map contains an entry of type " + valueClass + " which is not supported yet. Please file a bug report.");
}
}
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/config/MetadataUtils.java b/aot-core/src/main/java/io/micronaut/aot/core/config/MetadataUtils.java
index bde53866..633d89a3 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/config/MetadataUtils.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/config/MetadataUtils.java
@@ -15,8 +15,8 @@
*/
package io.micronaut.aot.core.config;
-import io.micronaut.aot.core.AOTModule;
import io.micronaut.aot.core.AOTCodeGenerator;
+import io.micronaut.aot.core.AOTModule;
import io.micronaut.aot.core.Option;
import io.micronaut.aot.core.Runtime;
@@ -29,6 +29,7 @@
public class MetadataUtils {
/**
* Returns the AOT module annotation for a class, if present.
+ *
* @param clazz the class to look for
* @return the module annotation.
*/
@@ -40,6 +41,7 @@ public static Optional findMetadata(Class> clazz) {
* Returns the option with the corresponding name. If
* the supplied class is not annotated with {@link AOTModule}
* invocation will fail.
+ *
* @param clazz the AOT module class
* @param name the name of the option
* @return the corresponding option
@@ -51,11 +53,12 @@ public static Option findOption(Class> clazz, String name) {
/**
* Returns a string representation of the option, for
* use in properties files.
+ *
* @param option the option to convert to sample text.
* @return a sample
*/
public static String toPropertiesSample(Option option) {
- StringBuilder sb = new StringBuilder();
+ var sb = new StringBuilder();
String description = option.description();
if (!description.isEmpty()) {
sb.append("# ").append(description).append("\n");
@@ -69,8 +72,8 @@ public static String toPropertiesSample(Option option) {
public static boolean isEnabledOn(Runtime runtime, AOTCodeGenerator module) {
return findMetadata(module.getClass())
- .map(aotModule -> isEnabledOn(runtime, aotModule))
- .orElse(false);
+ .map(aotModule -> isEnabledOn(runtime, aotModule))
+ .orElse(false);
}
public static boolean isEnabledOn(Runtime runtime, AOTModule module) {
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/config/SourceGeneratorLoader.java b/aot-core/src/main/java/io/micronaut/aot/core/config/SourceGeneratorLoader.java
index 4687c88b..c2b2228b 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/config/SourceGeneratorLoader.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/config/SourceGeneratorLoader.java
@@ -56,42 +56,42 @@ public class SourceGeneratorLoader {
public static List load(Runtime runtime, AOTContext context) {
Configuration configuration = context.getConfiguration();
return sourceGeneratorStream()
- .map(sg -> new Object() {
- final AOTCodeGenerator generator = sg;
- final AOTModule module = MetadataUtils.findMetadata(sg.getClass()).orElse(null);
- })
- .filter(sg -> {
- if (sg.module != null) {
- boolean isEnabledOnRuntime = MetadataUtils.isEnabledOn(runtime, sg.module);
- if (!isEnabledOnRuntime) {
- LOGGER.debug("Skipping source generator {} as it is not enabled on runtime {}", sg.generator.getClass().getName(), runtime);
- return false;
- }
- boolean isEnabledByConfiguration = configuration.isFeatureEnabled(sg.module.id());
- if (!isEnabledByConfiguration) {
- LOGGER.debug("Skipping source generator {} as it is not enabled by configuration", sg.generator.getClass().getName());
- return false;
- }
- LOGGER.debug("Loading source generator {}", sg.generator.getClass().getName());
- return true;
+ .map(sg -> new Object() {
+ final AOTCodeGenerator generator = sg;
+ final AOTModule module = MetadataUtils.findMetadata(sg.getClass()).orElse(null);
+ })
+ .filter(sg -> {
+ if (sg.module != null) {
+ boolean isEnabledOnRuntime = MetadataUtils.isEnabledOn(runtime, sg.module);
+ if (!isEnabledOnRuntime) {
+ LOGGER.debug("Skipping source generator {} as it is not enabled on runtime {}", sg.generator.getClass().getName(), runtime);
+ return false;
}
- return false;
- })
- .sorted(Comparator.comparing(f -> f.module, EXECUTION_ORDER))
- .map(sg -> sg.generator)
- .collect(Collectors.toList());
+ boolean isEnabledByConfiguration = configuration.isFeatureEnabled(sg.module.id());
+ if (!isEnabledByConfiguration) {
+ LOGGER.debug("Skipping source generator {} as it is not enabled by configuration", sg.generator.getClass().getName());
+ return false;
+ }
+ LOGGER.debug("Loading source generator {}", sg.generator.getClass().getName());
+ return true;
+ }
+ return false;
+ })
+ .sorted(Comparator.comparing(f -> f.module, EXECUTION_ORDER))
+ .map(sg -> sg.generator)
+ .collect(Collectors.toList());
}
@NonNull
public static List list(Runtime runtime) {
return sourceGeneratorStream()
- .map(Object::getClass)
- .map(MetadataUtils::findMetadata)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .filter(aotModule -> MetadataUtils.isEnabledOn(runtime, aotModule))
- .sorted(EXECUTION_ORDER)
- .collect(Collectors.toList());
+ .map(Object::getClass)
+ .map(MetadataUtils::findMetadata)
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .filter(aotModule -> MetadataUtils.isEnabledOn(runtime, aotModule))
+ .sorted(EXECUTION_ORDER)
+ .collect(Collectors.toList());
}
private static Stream sourceGeneratorStream() {
diff --git a/aot-core/src/main/java/io/micronaut/aot/core/context/ApplicationContextAnalyzer.java b/aot-core/src/main/java/io/micronaut/aot/core/context/ApplicationContextAnalyzer.java
index 06884b96..fdbd630a 100644
--- a/aot-core/src/main/java/io/micronaut/aot/core/context/ApplicationContextAnalyzer.java
+++ b/aot-core/src/main/java/io/micronaut/aot/core/context/ApplicationContextAnalyzer.java
@@ -47,12 +47,11 @@
* An application context analyzer is responsible for instantiating
* an application context and inferring whether a bean should be
* included in the application binaries.
- *
+ *