From a51de4b4b005974829057c2d5037e20d8a915b70 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 9 Aug 2024 09:47:40 -0400 Subject: [PATCH 01/59] Create codegen module --- hll/codegen/build.gradle.kts | 17 ++ .../kotlin/hll/codegen/core/CodeGenerator.kt | 224 ++++++++++++++++++ .../hll/codegen/core/CodeGeneratorFactory.kt | 47 ++++ .../hll/codegen/core/DataTypeGenerator.kt | 112 +++++++++ .../hll/codegen/core/ImportDirectives.kt | 59 +++++ .../kotlin/hll/codegen/core/TemplateEngine.kt | 118 +++++++++ .../hll/codegen/core/TemplateProcessor.kt | 87 +++++++ .../hll/codegen/model/ItemSourceKind.kt | 54 +++++ .../sdk/kotlin/hll/codegen/model/Member.kt | 24 ++ .../codegen/model/MemberCodegenBehavior.kt | 114 +++++++++ .../hll/codegen/model/ModelAttributes.kt | 22 ++ .../sdk/kotlin/hll/codegen/model/Operation.kt | 62 +++++ .../sdk/kotlin/hll/codegen/model/Structure.kt | 67 ++++++ .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 123 ++++++++++ settings.gradle.kts | 3 +- 15 files changed, 1132 insertions(+), 1 deletion(-) create mode 100644 hll/codegen/build.gradle.kts create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt diff --git a/hll/codegen/build.gradle.kts b/hll/codegen/build.gradle.kts new file mode 100644 index 00000000000..8f3ff496955 --- /dev/null +++ b/hll/codegen/build.gradle.kts @@ -0,0 +1,17 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +plugins { + alias(libs.plugins.kotlin.jvm) +} + +dependencies { + implementation(libs.ksp.api) + + testImplementation(libs.junit.jupiter) + testImplementation(libs.junit.jupiter.params) + testImplementation(libs.kotest.assertions.core.jvm) + testImplementation(libs.kotlin.test.junit5) +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt new file mode 100644 index 00000000000..8e77f92d1ea --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt @@ -0,0 +1,224 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.core + +private const val INDENT = " " + +/** + * An object which generates code into some context (typically an in-memory buffer which will eventually be written to a + * file). It includes basic methods for writing code in Kotlin such as creating blocks and indentation, docs, and + * ordinary lines of code. + * + * # String templates + * + * All methods which accept text to be written (e.g., [write], [openBlock], etc.) allow for the use of a string template + * with zero or more arguments substituted in for placeholders. See [TemplateEngine] for more details on string + * templates and argument substitution. + * + * # Indentation tracking + * + * Code generators track a running indentation level, which is used to form an indentation prefix prepended to lines + * written by this generator. The default indentation string per level is 4 spaces and the indentation level starts at 0 + * for new generators. The indentation level may be increased or decreased manually via the methods [indent] and + * [dedent]. The indentation level is also adjusted by **block** methods (e.g., [openBlock], [withBlock], etc.), which + * automatically indent/dedent around logical blocks of code. + */ +interface CodeGenerator { + /** + * The import directives for the current context + */ + val imports: ImportDirectives + + /** + * Append a blank line if there isn't already one in the buffer (i.e., invoking this method multiple times + * sequentially will append _only one_ blank line). + */ + fun blankLine() + + /** + * Close a manually-opened block of code by dedenting and appending some finalizing text + * @param template The string template or literal to append after dedenting (e.g., `}`) + * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on + * string templates and argument substitution. + */ + fun closeBlock(template: String, vararg args: Any) + + /** + * Close a manually-opened block and open a new one by dedenting, appending some intermediate text, and then + * indenting again + * @param template The string template or literal to append after dedenting and before re-indenting (e.g., + * `} else {`) + * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on + * string templates and argument substitution. + */ + fun closeAndOpenBlock(template: String, vararg args: Any) + + /** + * Decreases the active indentation level + * @param levels The number of levels to decrement. Defaults to `1` if unspecified. + */ + fun dedent(levels: Int = 1) + + /** + * Increases the active indentation level + * @param levels The number of levels to increment. Defaults to `1` if unspecified. + */ + fun indent(levels: Int = 1) + + /** + * Open a block of code manually by appending some starting text and then indenting + * @param template The string template or literal to append before indenting (e.g., `if (foo) {`) + * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on + * string templates and argument substitution. + */ + fun openBlock(template: String, vararg args: Any) + + /** + * Sends the accumulated text of this generator to the backing buffer (e.g., writes it to a file) + */ + fun persist() + + /** + * Writes a logical block of text by appending some starting text, indenting, executing the [block] function which + * may add text inside the block, dedenting, and writing some finalizing text + * @param preTemplate The string template or literal to append before indenting (e.g., `if (foo) {`) + * @param postText The string literal to append after dedenting (e.g., `}`). No templating or argument substitution + * will be performed on this string. + * @param args The arguments to substitute into the [preTemplate] (if any). See [TemplateEngine] for more details on + * string templates and argument substitution. + * @param block A function to execute in between appending the [preTemplate] and before appending the [postText]. + * This function typically writes more code, which will inherit the active indentation level which will have been + * incremented by `1` by this method. + */ + fun withBlock(preTemplate: String, postText: String, vararg args: Any, block: () -> Unit) + + /** + * Writes a block of documentation by automatically prepending KDoc-style comment tokens as prefixes. This method + * will append an opening comment token (i.e., `/**`), add a special indentation prefix (i.e., ` * `) to the + * existing indentation, execute the given [block], dedent back to the non-comment indentation prefix, and append a + * closing comment token (i.e., `*/`). + * @param block The function to execute in between appending the opening comment token and the closing comment + * token. This function typically writes more code, which will inherit the active indentation prefix and be rendered + * as a KDoc-style comment. + */ + fun withDocs(block: () -> Unit) + + /** + * Writes a line of text, including a terminating newline (i.e., `\n`) + * @param template The string template or literal to append + * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on + * string templates and argument substitution. + */ + fun write(template: String, vararg args: Any) + + /** + * Writes a string of text, _not_ including a terminating newline. Invoking this method repeatedly in sequence + * allows gradually forming an entire line incrementally rather than using a single [write] call. An in-progress + * line may be terminated by invoking a method such as [write] (which will continue on the current line) or + * [blankLine] (which will append a blank line). + * @param template The string template or literal to append + * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on + * string templates and argument substitution. + */ + fun writeInline(template: String, vararg args: Any) +} + +/** + * The standard implementation of [CodeGenerator]. This implementation automatically prepends a comment indicating the + * source is codegenned, a `package` directive specified by the constructor parameter [pkg], and a set of `import` + * directives (if any) from [imports]. + * + * Example of automatically prepended content: + * + * ```kotlin + * // Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT! + * + * package foo.bar + * + * import a.A + * import b.B + * import c.C + * ``` + * @param pkg The Kotlin package for the generated code (e.g., `aws.sdk.kotlin.hll.dynamodbmapper.operations`) + * @param engine A configured template engine to use while processing string templates + * @param persistCallback A callback method to invoke when the [persist] method is called on this class + * @param imports The import directives for the generator. These may be appended by more lines being written. + */ +class CodeGeneratorImpl( + private val pkg: String, + private val engine: TemplateEngine, + private val persistCallback: (String) -> Unit, + override val imports: ImportDirectives = ImportDirectives(), +) : CodeGenerator { + private val builder = StringBuilder() + private var indent = "" + + override fun blankLine() { + if (!builder.endsWith("\n\n")) builder.append('\n') + } + + override fun closeBlock(template: String, vararg args: Any) { + dedent() + write(template, *args) + } + + override fun closeAndOpenBlock(template: String, vararg args: Any) { + dedent() + write(template, *args) + indent() + } + + override fun dedent(levels: Int) { + repeat(levels) { + indent = indent.removeSuffix(INDENT) + } + } + + override fun indent(levels: Int) { + indent += INDENT.repeat(levels) + } + + override fun openBlock(template: String, vararg args: Any) { + write(template, *args) + indent() + } + + override fun persist() { + val content = buildString { + appendLine("// Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT!") + appendLine() + appendLine("package $pkg") + appendLine() + imports.formatted.takeIf { it.isNotBlank() }?.let { appendLine(it) } + append(builder) + } + persistCallback(content) + } + + override fun withBlock(preTemplate: String, postText: String, vararg args: Any, block: () -> Unit) { + openBlock(preTemplate, *args) + block() + closeBlock(postText) + } + + override fun withDocs(block: () -> Unit) { + write("/**") + indent += " * " + block() + indent = indent.removeSuffix(" * ") + write(" */") + } + + override fun write(template: String, vararg args: Any) { + writeInline(template, *args) + builder.append('\n') + } + + override fun writeInline(template: String, vararg args: Any) { + val text = engine.process(template, args.toList()) + if (builder.endsWith('\n')) builder.append(indent) + builder.append(text) + } +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt new file mode 100644 index 00000000000..63f6ffa25d8 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt @@ -0,0 +1,47 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.core + +import com.google.devtools.ksp.processing.Dependencies +import com.google.devtools.ksp.processing.KSPLogger +import com.google.devtools.ksp.processing.CodeGenerator as KSCodeGenerator + +/** + * A factory for [CodeGenerator] instances which will be backed by a [KSCodeGenerator] instance + * @param ksCodeGenerator The underlying KSP [KSCodeGenerator] to use for low-level file access and dependency tracking + * @param logger A logger instance to use for message + */ +class CodeGeneratorFactory(private val ksCodeGenerator: KSCodeGenerator, private val logger: KSPLogger) { + private val dependencies = Dependencies.ALL_FILES + + /** + * Creates a new [CodeGenerator] backed by a [KSCodeGenerator]. The returned generator starts with no imports and + * uses a configured [TemplateEngine] with the default set of processors. + * @param name The name of the file which should be created _without_ parent directory or extension (which is always + * **.kt**) + * @param pkg The Kotlin package for the generated code (e.g., `aws.sdk.kotlin.hll.dynamodbmapper.operations`) + */ + fun generator(name: String, pkg: String): CodeGenerator { + val imports = ImportDirectives() + val processors = listOf( + TemplateProcessor.Literal, + TemplateProcessor.QuotedString, + TemplateProcessor.forType(pkg, imports), + ) + val engine = TemplateEngine(processors) + + val persistCallback: (String) -> Unit = { content -> + logger.info("Checking out code generator for class $pkg.$name") + + ksCodeGenerator + .createNewFile(dependencies, pkg, name) // FIXME don't depend on ALL_FILES + .use { outputStream -> + outputStream.writer().use { writer -> writer.append(content) } + } + } + + return CodeGeneratorImpl(pkg, engine, persistCallback, imports) + } +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt new file mode 100644 index 00000000000..9ee06cb1700 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt @@ -0,0 +1,112 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.core + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Member +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Structure +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.RenderContext + +/** + * Generates immutable data types from a [Structure] into an underlying [CodeGenerator]. These data types consist of a + * read-only `interface` (with a `val` field for each [Structure] member), a `private data class` that serves as the + * default implementation, and a `public` factory function which allows constructing new instances by passing values as + * arguments. + * + * **FIXME**: This generator SHOULD generate a mutable builder object instead of a factory function for backwards + * compatibility. + * + * Example of generated data type: + * + * ```kotlin + * public interface User { + * public companion object { } + * + * public val id: Int + * public val name: String + * public val active: Boolean + * } + * + * private data class UserImpl( + * override val id: Int, + * override val name: String, + * override val active: Boolean, + * ) + * + * public fun User( + * id: Int, + * name: String, + * active: Boolean, + * ): User = UserImpl( + * id, + * name, + * active, + * ) + * ``` + * @param ctx The active rendering context + * @param generator The underlying generator for the context into which the data type should be written + * @param structure The [Structure] which describes the data type for which to generate code + */ +class DataTypeGenerator( + private val ctx: RenderContext, + generator: CodeGenerator, + val structure: Structure, +) : CodeGenerator by generator { + fun generate() { + withBlock("public interface #T {", "}", structure.type) { + write("public companion object { }") // leave room for future expansion + blankLine() + members { write("public val #L: #T", name, type) } + } + blankLine() + + val genericParams = structure + .members + .flatMap { it.type.generics() } + .map { it.shortName } + .requireAllDistinct() + .takeUnless { it.isEmpty() } + ?.joinToString(", ", "<", ">") + ?: "" + + val implName = "${structure.type.shortName}Impl" + openBlock("private data class #L#L(", implName, genericParams) + members { write("override val #L: #T,", name, type) } + closeBlock("): #T", structure.type) + blankLine() + + // TODO replace function builder with Builder interface+impl + openBlock("public fun #L #L(", genericParams, structure.type.shortName) + members { write("#L: #T,", name, type) } + closeAndOpenBlock("): #T = #L(", structure.type, implName) + members { write("#L,", name) } + closeBlock(")") + } + + private inline fun members(crossinline block: Member.() -> Unit) { + structure.members.forEach { it.block() } + } +} + +private fun Type.generics(): List = buildList { + when (val type = this@generics) { + is TypeVar -> add(type) + is TypeRef -> type.genericArgs.flatMap { it.generics() } + } +} + +private fun > C.requireAllDistinct(): C { + val collection = this + val itemCounts = buildMap { + collection.forEach { element -> + compute(element) { _, existingCount -> (existingCount ?: 0) + 1 } + } + } + + val duplicates = itemCounts.filter { (_, count) -> count > 1 }.keys + require(duplicates.isEmpty()) { "Found duplicated items: $duplicates" } + + return collection +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt new file mode 100644 index 00000000000..abb44685f5f --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt @@ -0,0 +1,59 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.core + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef + +/** + * A mutable collection of [ImportDirectives] for eventually writing to a code generator + */ +class ImportDirectives : MutableSet by mutableSetOf() { + operator fun get(shortName: String) = firstOrNull { it.shortName == shortName } + + /** + * Returns a formatted code string with each import on a dedicated line. Imports will be sorted with the following + * precedence: + * 1. Unaliased imports before alised imports + * 2. The special package prefixes `java`, `javax`, `kotlin` after all other imports + * 3. Lexicographically sorted + */ + val formatted: String + get() = buildString { + sortedWith(importComparator).forEach { appendLine(it.formatted) } + } +} + +private val specialPrefixes = setOf( + "java.", + "javax.", + "kotlin.", +) + +private val importComparator = compareBy { it.alias != null } // aliased imports at the very end + .thenBy { directive -> specialPrefixes.any { directive.fullName.startsWith(it) } } // special prefixes < aliases + .thenBy { it.fullName } // sort alphabetically + +/** + * Describes a Kotlin `import` directive + * @param fullName The full name of the import (e.g., `java.net.Socket`) + * @param alias An optional alias for the import (e.g., `JavaSocket`). If present, a formatted code string for this + * directive will include an `as` clause (e.g., `import java.net.Socket as JavaSocket`). + */ +data class ImportDirective(val fullName: String, val alias: String? = null) { + /** + * The unaliased "short name" of an import directive—namely, everything after the last `.` separator. For example, + * for the full name `java.net.Socket` the short name is `Socket`. + */ + val shortName = fullName.split(".").last() + + private val aliasFormatted = alias?.let { " as $it" } ?: "" + + /** + * The formatted `import` code string for this directive + */ + val formatted = "import $fullName$aliasFormatted" +} + +fun ImportDirective(type: TypeRef, alias: String? = null) = ImportDirective(type.fullName, alias) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt new file mode 100644 index 00000000000..383f6a8486b --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt @@ -0,0 +1,118 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.core + +/** + * A string processing engine that replaces template parameters with passed arguments to form a final string. String + * templates take the form of string literals containing zero or more **parameters**, which are special sequences + * starting with `#`. When the engine encounters these parameters, it endeavors to replace the entire parameter with an + * argument value by using a matching [TemplateProcessor]. This may fail if no matching processor is found, there is a + * mismatch between the template and passed arguments, if data types of arguments are incorrect, or other reasons, in + * which case an exception will be thrown. + * + * # Parameters + * + * All parameters start with `#` and end with an uppercase letter (`[A-Z]`). They may optionally contain a number as + * well, which makes them **Positional Parameters**. Otherwise, they are **Sequential Parameters**. Templates cannot + * contain _both_ types of parameters, otherwise an exception will be thrown. + * + * ## Sequential Parameters + * + * Parameters in the form of `#[A-Z]` are sequential parameters. The first such sequential parameter will be substituted + * with the first passed argument, the second will be replaced with the second argument, and so forth. If the number of + * sequential parameters does not match the number of arguments, an exception will be thrown. + * + * Note that with this type of parameter, substituting the same argument value multiple times requires passing that + * argument multiple times. + * + * ## Positional Parameters + * + * Parameters in the form of `#n[A-Z]` (where `n > 0`) are positional parameters. The number `n` in the parameter + * indicates the 1-based index of the argument to use for substitution. If the number `n` references an index outside + * the range of arguments (e.g., less than `0` or greater than the number of passed arguments), an exception will be + * thrown. + * + * Note that with this type of parameter, substituting the same argument value multiple times does not require _passing_ + * that argument multiple times, merely using the same `n` value for multiple parameters. + * + * # Processors + * + * Template engines reference zero or more [TemplateProcessor] instances which perform mapping from raw argument values + * to strings to be used in parameter substitution. When the template engine encounters a parameter in a string + * template, it attempts to match the parameter **key** (an uppercase letter `[A-Z]`) to the key of a processor. If no + * referenced processor has a matching key, an exception will be thrown. + */ +class TemplateEngine(processors: List) { + private val processors = processors.associate { it.key to it.handler } + private val parameterRegex = """(?): String { + var allIndexed: Boolean? = null + + return parameterRegex.replaceIndexed(template) { pos, result -> + val explicitIndex = result.groupValues[1].takeUnless { it.isEmpty() }?.toInt()?.minus(1) + val indexed = explicitIndex != null + + fun req(condition: Boolean, message: () -> String) { + require(condition) { + buildString { + append("Error in template '") + append(template) + append("' for parameter '") + append(result.value) + append("' at index ") + append(result.range.first) + append(": ") + + append(message()) + } + } + } + + fun reqNotNull(element: T?, message: () -> String): T { + req(element != null, message) + return element!! + } + + req(allIndexed == null || allIndexed == indexed) { + "Cannot mix indexed and non-indexed parameters in the same template" + } + allIndexed = indexed + + val key = result.groupValues[2].toCharArray().single() + val handler = reqNotNull(processors[key]) { "No processor found for key character '$key'" } + + val index = explicitIndex ?: pos + req(index in args.indices) { + buildString { + if (indexed) { + append("Index ") + append(result.groupValues[1]) + } else { + append("Parameter index ") + append(pos) + } + append(" is outside of args bounds ") + append(args.indices) + } + } + + handler(args[index]) + } + } +} + +private fun Regex.replaceIndexed(input: CharSequence, transform: (index: Int, MatchResult) -> CharSequence): String { + var index = 0 + return replace(input) { + transform(index, it).also { index++ } + } +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt new file mode 100644 index 00000000000..9983b676c1a --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt @@ -0,0 +1,87 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.core + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Type +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.quote + +/** + * Defines a template processor which maps an argument value of any type to a string value + * @param key The identifier for this processor, which will be used by the [TemplateEngine] to match a parameter with + * this processor + * @param handler A function that accepts an input argument (as an [Any]) and returns a formatted string + */ +data class TemplateProcessor(val key: Char, val handler: (Any) -> String) { + companion object { + /** + * Instantiate a new typed template processor which only receives arguments of a specific type [T] + * @param T The type of argument values this processor will accept + * @param key The identifier for this processor, which will be used by the [TemplateEngine] to match a parameter + * with this processor + * @param handler A function that accepts an input argument of type [T] and returns a formatted string + */ + inline fun typed(key: Char, crossinline handler: (T) -> String) = TemplateProcessor(key) { value -> + require(value is T) { "Expected argument of type ${T::class} but found $value" } + handler(value) + } + + /** + * A literal template processor. This processor substitutes parameters in the form of `#L` with the [toString] + * representation of the corresponding argument. + */ + val Literal = TemplateProcessor('L') { it.toString() } + + /** + * A quoted string template processor. This processor substitutes parameters in the form of `#S` with the + * quoted/escaped form of a string argument. See [quote] for more details. + */ + val QuotedString = typed('S') { it.quote() } + + /** + * Creates a template processor for [Type] values. This processor substitutes parameters in the form of `#T` + * with the name or an alias of the type. It also appends `import` directives if necessary. + * @param pkg The Kotlin package into which code is being generated. An `import` directive will not be added if + * a passed argument has the same package as this processor. + * @param imports An [ImportDirectives] collection to which new imports will be appended + */ + fun forType(pkg: String, imports: ImportDirectives): TemplateProcessor { + val processor = ImportingTypeProcessor(pkg, imports) + return typed('T', processor::format) + } + } + + init { + require(key in 'A'..'Z') { "Key character must be a capital letter (A-Z)" } + } +} + +private open class TypeProcessor { + open fun format(type: Type): String = buildString { + append(type.shortName) + if (type is TypeRef && type.genericArgs.isNotEmpty()) { + type.genericArgs.joinToString(", ", "<", ">", transform = ::format).let(::append) + } + + if (type.nullable) append('?') + } +} + +private class ImportingTypeProcessor(private val pkg: String, private val imports: ImportDirectives) : TypeProcessor() { + override fun format(type: Type): String = buildString { + if (type is TypeRef && type.pkg != pkg) { + val existingImport = imports[type.shortName] + + if (existingImport == null) { + imports += ImportDirective(type) + } else if (existingImport.fullName != type.fullName) { + append(type.pkg) + append('.') + } + } + + append(super.format(type)) + } +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt new file mode 100644 index 00000000000..39225e29c86 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt @@ -0,0 +1,54 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg + +/** + * Identifies a type in the `ItemSource` hierarchy + * @param hoistedFields Which fields should be hoisted from the low-level request type for this item source kind (e.g., + * for `TableSpec` the `tableName` field should be hoisted) + * @param parent The parent type of this type (if any) + * @param isAbstract Indicates whether this item source kind is purely abstract and should not have an implementation + * class (e.g., `ItemSource` should be abstract and non-instantiable) + */ +enum class ItemSourceKind( + val hoistedFields: List, + val parent: ItemSourceKind? = null, + val isAbstract: Boolean = false, +) { + /** + * Indicates the `ItemSource` interface + */ + ItemSource(listOf(), isAbstract = true), + + /** + * Indicates the `Index` interface + */ + Index(listOf("indexName", "tableName"), ItemSource), + + /** + * Indicates the `Table` interface + */ + Table(listOf("tableName"), ItemSource), + + ; + + /** + * Get the [TypeRef] for the `*Spec` type for this item source kind + * @param typeVar The type variable name to use for the generic type + */ + fun getSpecType(typeVar: String): TypeRef = TypeRef(Pkg.Hl.Model, "${name}Spec", listOf(TypeVar(typeVar))) +} + +/** + * Identifies the types of `ItemSource` on which an operation can be invoked (e.g., `Scan` can be invoked on a table, + * index, or any generic item source, whereas `GetItem` can only be invoked on a table) + */ +val Operation.itemSourceKinds: Set + get() = when (name) { + "Query", "Scan" -> setOf(ItemSourceKind.ItemSource, ItemSourceKind.Index, ItemSourceKind.Table) + else -> setOf(ItemSourceKind.Table) + } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt new file mode 100644 index 00000000000..ec2b6dfa374 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt @@ -0,0 +1,24 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import com.google.devtools.ksp.symbol.KSPropertyDeclaration + +/** + * Describes a member (i.e., component field, attribute, property, etc.) of a [Structure] + * @param name The name of the member inside its parent [Structure] + * @param type The [Type] of the member + */ +data class Member(val name: String, val type: Type) { + companion object { + /** + * Derive a [Member] from a [KSPropertyDeclaration] + */ + fun from(prop: KSPropertyDeclaration) = Member( + name = prop.simpleName.getShortName(), + type = Type.from(prop.type), + ) + } +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt new file mode 100644 index 00000000000..533755d18fc --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt @@ -0,0 +1,114 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg + +private val attrMapTypes = setOf(Types.AttributeMap, Types.AttributeMap.nullable()) + +/** + * Describes a behavior to apply for a given [Member] in a low-level structure when generating code for an equivalent + * high-level structure. This interface implements no behaviors on its own; it merely gives strongly-typed names to + * behaviors that will be implemented by calling code. + */ +sealed interface MemberCodegenBehavior { + companion object { + /** + * Identifies a [MemberCodegenBehavior] for the given [Member] by way of various heuristics + * @param member The [Member] for which to identify a codegen behavior + */ + fun identifyFor(member: Member) = when { + member in unsupportedMembers -> Drop + member.type in attrMapTypes -> if (member.name == "key") MapKeys else MapAll + member.isTableName -> Hoist + else -> PassThrough + } + } + + /** + * Indicates that a member should be copied as-is from a low-level structure to a high-level equivalent (i.e., no + * changes to name, type, etc. are required) + */ + data object PassThrough : MemberCodegenBehavior + + /** + * Indicates that a member is an attribute map which may contain _all_ attributes for a data type (as opposed to + * only _key_ attributes) and should be replaced with a generic type (i.e., a `Map` member + * in a low-level structure should be replaced with a generic `T` member in a high-level structure) + */ + data object MapAll : MemberCodegenBehavior + + /** + * Indicates that a member is an attribute map which contains _key_ attributes for a data type (as opposed to _all_ + * attributes) and should be replaced with a generic type (i.e., a `Map` member + * in a low-level structure should be replaced with a generic `T` member in a high-level structure) + */ + data object MapKeys : MemberCodegenBehavior + + /** + * Indicates that a member is unsupported and should not be replicated from a low-level structure to the high-level + * equivalent (e.g., a deprecated member that has been replaced with new features need not be carried forward) + */ + data object Drop : MemberCodegenBehavior + + /** + * Indicates that a member from a low-level structure should be "hoisted" outside its high-level equivalent. This is + * similar to [Drop] but indicates that other codegen may use the member in different ways (e.g., a table name + * parameter in a low-level structure may be hoisted to a different API but not added to the equivalent high-level + * structure). + */ + data object Hoist : MemberCodegenBehavior +} + +/** + * Identifies a [MemberCodegenBehavior] for this [Member] by way of various heuristics + */ +val Member.codegenBehavior: MemberCodegenBehavior + get() = when { + this in unsupportedMembers -> MemberCodegenBehavior.Drop + type in attrMapTypes -> if (name == "key") MemberCodegenBehavior.MapKeys else MemberCodegenBehavior.MapAll + isTableName || isIndexName -> MemberCodegenBehavior.Hoist + else -> MemberCodegenBehavior.PassThrough + } + +private val Member.isTableName: Boolean + get() = name == "tableName" && type == Types.StringNullable + +private val Member.isIndexName: Boolean + get() = name == "indexName" && type == Types.StringNullable + +private fun llType(name: String) = TypeRef(Pkg.Ll.Model, name) + +private val unsupportedMembers = listOf( + // superseded by ConditionExpression + Member("conditionalOperator", llType("ConditionalOperator")), + Member("expected", Type.stringMap(llType("ExpectedAttributeValue"))), + + // superseded by FilterExpression + Member("queryFilter", Type.stringMap(llType("Condition"))), + Member("scanFilter", Type.stringMap(llType("Condition"))), + + // superseded by KeyConditionExpression + Member("keyConditions", Type.stringMap(llType("Condition"))), + + // superseded by ProjectionExpression + Member("attributesToGet", Type.list(Types.String)), + + // superseded by UpdateExpression + Member("attributeUpdates", Type.stringMap(llType("AttributeValueUpdate"))), + + // TODO add support for expressions + Member("expressionAttributeNames", Type.stringMap(Types.String)), + Member("expressionAttributeValues", Types.AttributeMap), + Member("conditionExpression", Types.String), + Member("projectionExpression", Types.String), + Member("updateExpression", Types.String), +).map { member -> + if (member.type is TypeRef) { + member.copy(type = member.type.nullable()) + } else { + member + } +}.toSet() diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt new file mode 100644 index 00000000000..1f474e95227 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt @@ -0,0 +1,22 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import aws.smithy.kotlin.runtime.collections.AttributeKey + +/** + * Defines [AttributeKey] instances that relate to the data model of low-level to high-level codegen + */ +object ModelAttributes { + /** + * For a given high-level [Operation], this attribute key identifies the associated low-level [Operation] + */ + val LowLevelOperation: AttributeKey = AttributeKey("aws.sdk.kotlin.ddbmapper#LowLevelOperation") + + /** + * For a given high-level [Structure], this attribute key identifies the associated low-level [Structure] + */ + val LowLevelStructure: AttributeKey = AttributeKey("aws.sdk.kotlin.ddbmapper#LowLevelStructure") +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt new file mode 100644 index 00000000000..9351301e038 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt @@ -0,0 +1,62 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.capitalizeFirstChar +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.plus +import aws.smithy.kotlin.runtime.collections.Attributes +import aws.smithy.kotlin.runtime.collections.emptyAttributes +import aws.smithy.kotlin.runtime.collections.get +import com.google.devtools.ksp.symbol.KSFunctionDeclaration + +/** + * Describes a service operation (i.e., API method) + * @param methodName The name of the operation as a code-suitable method name. For example, `getItem` is a suitable + * method name in Kotlin, whereas `GetItem` is not (improperly cased) nor is `get item` (contains a space). + * @param request The [Structure] for requests/inputs to this operation + * @param response The [Structure] for responses/output from this operation + * @param attributes An [Attributes] collection for associating typed attributes with this operation + */ +data class Operation( + val methodName: String, + val request: Structure, + val response: Structure, + val attributes: Attributes = emptyAttributes(), +) { + /** + * The capitalized name of this operation's [methodName]. For example, if [methodName] is `getItem` then [name] + * would be `GetItem`. + */ + val name = methodName.capitalizeFirstChar // e.g., "GetItem" vs "getItem" + + companion object { + /** + * Derive an [Operation] from a [KSFunctionDeclaration] + */ + fun from(declaration: KSFunctionDeclaration) = Operation( + methodName = declaration.simpleName.getShortName(), + request = Structure.from(declaration.parameters.single().type), + response = Structure.from(declaration.returnType!!), + ) + } +} + +/** + * Gets the low-level [Operation] equivalent for this high-level operation + */ +val Operation.lowLevel: Operation + get() = attributes[ModelAttributes.LowLevelOperation] + +/** + * Derives a high-level [Operation] equivalent for this low-level operation + * @param pkg The Kotlin package to use for the high-level operation's request and response structures + */ +fun Operation.toHighLevel(pkg: String): Operation { + val llOperation = this@toHighLevel + val hlRequest = llOperation.request.toHighLevel(pkg) + val hlResponse = llOperation.response.toHighLevel(pkg) + val hlAttributes = llOperation.attributes + (ModelAttributes.LowLevelOperation to llOperation) + return Operation(llOperation.methodName, hlRequest, hlResponse, hlAttributes) +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt new file mode 100644 index 00000000000..7e84940f4be --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt @@ -0,0 +1,67 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.plus +import aws.smithy.kotlin.runtime.collections.Attributes +import aws.smithy.kotlin.runtime.collections.emptyAttributes +import aws.smithy.kotlin.runtime.collections.get +import com.google.devtools.ksp.getDeclaredProperties +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSTypeReference + +/** + * Describes a structure (i.e., class, struct, etc.) which contains zero or more [Member] instances + * @param type The [TypeRef] for this structure, which includes its name and Kotlin package + * @param members The [Member] instances which are part of this structure + * @param attributes An [Attributes] collection for associating typed attributes with this structure + */ +data class Structure( + val type: TypeRef, + val members: List, + val attributes: Attributes = emptyAttributes(), +) { + companion object { + /** + * Derives a [Structure] from the given [KSTypeReference] + */ + fun from(ksTypeRef: KSTypeReference) = Structure( + type = Type.from(ksTypeRef), + members = (ksTypeRef.resolve().declaration as KSClassDeclaration) + .getDeclaredProperties() + .map(Member::from) + .toList(), + ) + } +} + +/** + * Gets the low-level [Structure] equivalent for this high-level structure + */ +val Structure.lowLevel: Structure + get() = attributes[ModelAttributes.LowLevelStructure] + +/** + * Derives a a high-level [Structure] equivalent for this low-level structure + * @param pkg The Kotlin package to use for the high-level structure + */ +fun Structure.toHighLevel(pkg: String): Structure { + val llStructure = this@toHighLevel + + val hlType = TypeRef(pkg, llStructure.type.shortName, listOf(TypeVar("T"))) + + val hlMembers = llStructure.members.mapNotNull { llMember -> + when (llMember.codegenBehavior) { + MemberCodegenBehavior.PassThrough -> llMember + MemberCodegenBehavior.MapAll, MemberCodegenBehavior.MapKeys -> + llMember.copy(type = TypeVar("T", llMember.type.nullable)) + else -> null + } + } + + val hlAttributes = llStructure.attributes + (ModelAttributes.LowLevelStructure to llStructure) + + return Structure(hlType, hlMembers, hlAttributes) +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt new file mode 100644 index 00000000000..d29c2dbd4fa --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -0,0 +1,123 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.codegen.model + +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg +import com.google.devtools.ksp.symbol.KSTypeReference + +/** + * Describes a Kotlin data type + */ +sealed interface Type { + companion object { + /** + * Derives a [TypeRef] from a [KSTypeReference] + */ + fun from(ksTypeRef: KSTypeReference): TypeRef { + val resolved = ksTypeRef.resolve() + val name = resolved.declaration.qualifiedName!! + return TypeRef( + pkg = name.getQualifier(), + shortName = name.getShortName(), + genericArgs = resolved.arguments.map { from(it.type!!) }, + nullable = resolved.isMarkedNullable, + ) + } + + /** + * Creates a [TypeRef] for a generic [List] + * @param element The type of elements in the list + */ + fun list(element: Type) = TypeRef(Pkg.Kotlin.Collections, "List", listOf(element)) + + /** + * Creates a [TypeRef] for a named Kotlin type (e.g., `String`) + */ + fun kotlin(name: String) = TypeRef(Pkg.Kotlin.Base, name) + + /** + * Creates a [TypeRef] for a generic [Map] + * @param key The type of keys in the map + * @param value The type of values in the map + */ + fun map(key: Type, value: Type) = TypeRef(Pkg.Kotlin.Collections, "Map", listOf(key, value)) + + /** + * Creates a [TypeRef] for a generic [Map] with [String] keys + * @param value The type of values in the map + */ + fun stringMap(value: Type) = map(Types.String, value) + } + + /** + * Gets the short name (i.e., not including the Kotlin package) for this type + */ + val shortName: String + + /** + * Indicates whether instances of this type allow nullable references + */ + val nullable: Boolean +} + +/** + * A reference to a specific, named type (e.g., [kotlin.String]). + * + * This type reference may have generic arguments, which are themselves instances of a [Type]. For instance, a [TypeRef] + * representing [kotlin.collections.List] would have a single generic argument, which may either be a concrete [TypeRef] + * itself (e.g., `List`) or a generic [TypeVar] (e.g., `List`). + * @param pkg The Kotlin package for this type + * @param shortName The short name (i.e., not include the kotlin package) for this type + * @param genericArgs Zero or more [Type] generic arguments to this type + * @param nullable Indicates whether instances of this type allow nullable references + */ +data class TypeRef( + val pkg: String, + override val shortName: String, + val genericArgs: List = listOf(), + override val nullable: Boolean = false, +) : Type { + /** + * The full name of this type, including the Kotlin package + */ + val fullName: String = "$pkg.$shortName" +} + +/** + * A generic type variable (e.g., `T`) + * @param shortName The name of this type variable + * @param nullable Indicates whether instances of this type allow nullable references + */ +data class TypeVar(override val shortName: String, override val nullable: Boolean = false) : Type + +/** + * Derives a nullable [Type] equivalent for this type + */ +fun Type.nullable() = when { + nullable -> this + this is TypeRef -> copy(nullable = true) + this is TypeVar -> copy(nullable = true) + else -> error("Unknown Type ${this::class}") // Should be unreachable, only here to make compiler happy +} + +/** + * A container/factory object for various [Type] instances + */ +object Types { + // Kotlin standard types + val String = TypeRef("kotlin", "String") + val StringNullable = String.nullable() + + // Low-level types + val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") + val AttributeMap = Type.map(String, AttributeValue) + + // High-level types + val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") + fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) + val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") + val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") + val toItem = TypeRef(Pkg.Hl.Model, "toItem") +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a0b1ce8f837..e6aa6c43e03 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -39,7 +39,8 @@ include(":aws-runtime:aws-core") include(":aws-runtime:aws-config") include(":aws-runtime:aws-endpoint") include(":aws-runtime:aws-http") -include(":hlls") +include(":hll") +include(":hll:codegen") include(":services") include(":tests") include(":tests:codegen:event-stream") From 0a779a16f846858bc04552d5aa397cc66075d1a2 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 9 Aug 2024 10:05:42 -0400 Subject: [PATCH 02/59] Create codegen module --- .../kotlin/aws/sdk/kotlin/hll}/codegen/util/AttributesExt.kt | 2 +- .../src/main/kotlin/aws/sdk/kotlin/hll}/codegen/util/Pkg.kt | 2 +- .../src/main/kotlin/aws/sdk/kotlin/hll}/codegen/util/Strings.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/main/kotlin/aws/sdk/kotlin/hll}/codegen/util/AttributesExt.kt (94%) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/main/kotlin/aws/sdk/kotlin/hll}/codegen/util/Pkg.kt (92%) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/main/kotlin/aws/sdk/kotlin/hll}/codegen/util/Strings.kt (96%) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/AttributesExt.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt similarity index 94% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/AttributesExt.kt rename to hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt index 00a988c4c1f..4bf2c7bb65e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/AttributesExt.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.util +package aws.sdk.kotlin.hll.codegen.util import aws.smithy.kotlin.runtime.collections.AttributeKey import aws.smithy.kotlin.runtime.collections.Attributes diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/Pkg.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/Pkg.kt rename to hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt index 980202f71d4..de5e4697f98 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/Pkg.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.util +package aws.sdk.kotlin.hll.codegen.util /** * Named constants for various mapper runtime packages diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/Strings.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt similarity index 96% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/Strings.kt rename to hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt index ad1a5ab9154..4382e390df7 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/Strings.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.util +package aws.sdk.kotlin.hll.codegen.util private val codepointMap = buildMap { (0..255).filter(Character::isISOControl).forEach { code -> put(code, unicodeEscape(code)) } From 011f367fdbd5d815b95f888d9d9396b3be55e3a0 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 9 Aug 2024 10:48:37 -0400 Subject: [PATCH 03/59] Add tests and .api --- hll/codegen/api/codegen.api | 213 ++++++++++++++++++ .../hll}/codegen/core/TemplateEngineTest.kt | 2 +- .../codegen/core/TemplateProcessorTest.kt | 6 +- .../kotlin/hll}/codegen/util/StringsTest.kt | 2 +- 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 hll/codegen/api/codegen.api rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/test/kotlin/aws/sdk/kotlin/hll}/codegen/core/TemplateEngineTest.kt (97%) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/test/kotlin/aws/sdk/kotlin/hll}/codegen/core/TemplateProcessorTest.kt (92%) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/test/kotlin/aws/sdk/kotlin/hll}/codegen/util/StringsTest.kt (94%) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api new file mode 100644 index 00000000000..5bb044081e8 --- /dev/null +++ b/hll/codegen/api/codegen.api @@ -0,0 +1,213 @@ +public abstract interface class aws/sdk/kotlin/hll/codegen/core/CodeGenerator { + public abstract fun blankLine ()V + public abstract fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public abstract fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public abstract fun dedent (I)V + public abstract fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; + public abstract fun indent (I)V + public abstract fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public abstract fun persist ()V + public abstract fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V + public abstract fun withDocs (Lkotlin/jvm/functions/Function0;)V + public abstract fun write (Ljava/lang/String;[Ljava/lang/Object;)V + public abstract fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V +} + +public final class aws/sdk/kotlin/hll/codegen/core/CodeGenerator$DefaultImpls { + public static synthetic fun dedent$default (Laws/sdk/kotlin/hll/codegen/core/CodeGenerator;IILjava/lang/Object;)V + public static synthetic fun indent$default (Laws/sdk/kotlin/hll/codegen/core/CodeGenerator;IILjava/lang/Object;)V +} + +public final class aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory { + public fun (Lcom/google/devtools/ksp/processing/CodeGenerator;Lcom/google/devtools/ksp/processing/KSPLogger;)V + public final fun generator (Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/CodeGenerator; +} + +public final class aws/sdk/kotlin/hll/codegen/core/CodeGeneratorImpl : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { + public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;)V + public synthetic fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun blankLine ()V + public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun dedent (I)V + public fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; + public fun indent (I)V + public fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun persist ()V + public fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V + public fun withDocs (Lkotlin/jvm/functions/Function0;)V + public fun write (Ljava/lang/String;[Ljava/lang/Object;)V + public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V +} + +public final class aws/sdk/kotlin/hll/codegen/core/ImportDirective { + public fun (Ljava/lang/String;Ljava/lang/String;)V + public synthetic fun (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; + public fun equals (Ljava/lang/Object;)Z + public final fun getAlias ()Ljava/lang/String; + public final fun getFormatted ()Ljava/lang/String; + public final fun getFullName ()Ljava/lang/String; + public final fun getShortName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/core/ImportDirectives : java/util/Set, kotlin/jvm/internal/markers/KMutableSet { + public fun ()V + public fun add (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z + public synthetic fun add (Ljava/lang/Object;)Z + public fun addAll (Ljava/util/Collection;)Z + public fun clear ()V + public fun contains (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z + public final fun contains (Ljava/lang/Object;)Z + public fun containsAll (Ljava/util/Collection;)Z + public final fun get (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; + public final fun getFormatted ()Ljava/lang/String; + public fun getSize ()I + public fun isEmpty ()Z + public fun iterator ()Ljava/util/Iterator; + public fun remove (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z + public final fun remove (Ljava/lang/Object;)Z + public fun removeAll (Ljava/util/Collection;)Z + public fun retainAll (Ljava/util/Collection;)Z + public final fun size ()I + public fun toArray ()[Ljava/lang/Object; + public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object; +} + +public final class aws/sdk/kotlin/hll/codegen/core/ImportDirectivesKt { + public static final fun ImportDirective (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; + public static synthetic fun ImportDirective$default (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; +} + +public final class aws/sdk/kotlin/hll/codegen/core/TemplateEngine { + public fun (Ljava/util/List;)V + public final fun process (Ljava/lang/String;Ljava/util/List;)Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/core/TemplateProcessor { + public static final field Companion Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor$Companion; + public fun (CLkotlin/jvm/functions/Function1;)V + public final fun component1 ()C + public final fun component2 ()Lkotlin/jvm/functions/Function1; + public final fun copy (CLkotlin/jvm/functions/Function1;)Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor;CLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; + public fun equals (Ljava/lang/Object;)Z + public final fun getHandler ()Lkotlin/jvm/functions/Function1; + public final fun getKey ()C + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/core/TemplateProcessor$Companion { + public final fun forType (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;)Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; + public final fun getLiteral ()Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; + public final fun getQuotedString ()Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; +} + +public abstract interface class aws/sdk/kotlin/hll/codegen/model/Type { + public static final field Companion Laws/sdk/kotlin/hll/codegen/model/Type$Companion; + public abstract fun getNullable ()Z + public abstract fun getShortName ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/model/Type$Companion { + public final fun from (Lcom/google/devtools/ksp/symbol/KSTypeReference;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun kotlin (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun list (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun map (Laws/sdk/kotlin/hll/codegen/model/Type;Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun stringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; +} + +public final class aws/sdk/kotlin/hll/codegen/model/TypeKt { + public static final fun nullable (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/Type; +} + +public final class aws/sdk/kotlin/hll/codegen/model/TypeRef : aws/sdk/kotlin/hll/codegen/model/Type { + public fun (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)V + public synthetic fun (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Ljava/lang/String; + public final fun component3 ()Ljava/util/List; + public final fun component4 ()Z + public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public fun equals (Ljava/lang/Object;)Z + public final fun getFullName ()Ljava/lang/String; + public final fun getGenericArgs ()Ljava/util/List; + public fun getNullable ()Z + public final fun getPkg ()Ljava/lang/String; + public fun getShortName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/model/TypeVar : aws/sdk/kotlin/hll/codegen/model/Type { + public fun (Ljava/lang/String;Z)V + public synthetic fun (Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Z + public final fun copy (Ljava/lang/String;Z)Laws/sdk/kotlin/hll/codegen/model/TypeVar; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/model/TypeVar;Ljava/lang/String;ZILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/model/TypeVar; + public fun equals (Ljava/lang/Object;)Z + public fun getNullable ()Z + public fun getShortName ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/model/Types { + public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types; + public final fun StringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getAttributeMap ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getAttributeValue ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getHReqContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getMapperContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getOperation ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getStringNullable ()Laws/sdk/kotlin/hll/codegen/model/Type; + public final fun getToItem ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun itemSchema (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; +} + +public final class aws/sdk/kotlin/hll/codegen/util/AttributesExtKt { + public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/smithy/kotlin/runtime/collections/Attributes; + public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/Pair;)Laws/smithy/kotlin/runtime/collections/Attributes; +} + +public final class aws/sdk/kotlin/hll/codegen/util/Pkg { + public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg; +} + +public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Hl { + public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg$Hl; + public final fun getBase ()Ljava/lang/String; + public final fun getItems ()Ljava/lang/String; + public final fun getModel ()Ljava/lang/String; + public final fun getOps ()Ljava/lang/String; + public final fun getPipelineImpl ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Kotlin { + public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg$Kotlin; + public final fun getBase ()Ljava/lang/String; + public final fun getCollections ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Ll { + public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg$Ll; + public final fun getBase ()Ljava/lang/String; + public final fun getModel ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/util/StringsKt { + public static final fun escape (Ljava/lang/String;)Ljava/lang/String; + public static final fun getCapitalizeFirstChar (Ljava/lang/String;)Ljava/lang/String; + public static final fun getLowercaseFirstChar (Ljava/lang/String;)Ljava/lang/String; + public static final fun quote (Ljava/lang/String;)Ljava/lang/String; +} + diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngineTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt similarity index 97% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngineTest.kt rename to hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt index b9578361c1d..c853b989f7f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngineTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core +package aws.sdk.kotlin.hll.codegen.core import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessorTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessorTest.kt rename to hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt index 4df169db48e..ffc793866f7 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessorTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt @@ -2,10 +2,10 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core +package aws.sdk.kotlin.hll.codegen.core -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeVar import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import kotlin.test.assertContains diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/StringsTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt similarity index 94% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/StringsTest.kt rename to hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt index 0cbbd7cda7b..c2f85036c6d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/test/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/util/StringsTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.util +package aws.sdk.kotlin.hll.codegen.util import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test From 75e208a434ea8255b1b16f65a635fbc108d1afb4 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 9 Aug 2024 10:52:57 -0400 Subject: [PATCH 04/59] Bootstrap --- hll/codegen/build.gradle.kts | 1 + .../hll/codegen/core/DataTypeGenerator.kt | 112 --------- .../hll/codegen/core/ImportDirectives.kt | 2 +- .../hll/codegen/core/TemplateProcessor.kt | 6 +- .../hll/codegen/model/ItemSourceKind.kt | 54 ----- .../sdk/kotlin/hll/codegen/model/Member.kt | 24 -- .../codegen/model/MemberCodegenBehavior.kt | 114 --------- .../hll/codegen/model/ModelAttributes.kt | 22 -- .../sdk/kotlin/hll/codegen/model/Operation.kt | 62 ----- .../sdk/kotlin/hll/codegen/model/Structure.kt | 67 ------ .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 11 +- .../build.gradle.kts | 1 + .../codegen/HighLevelOpsProcessor.kt | 4 +- .../codegen/core/CodeGenerator.kt | 224 ------------------ .../codegen/core/CodeGeneratorFactory.kt | 47 ---- .../codegen/core/DataTypeGenerator.kt | 4 + .../codegen/core/ImportDirectives.kt | 59 ----- .../codegen/core/TemplateEngine.kt | 118 --------- .../codegen/core/TemplateProcessor.kt | 87 ------- .../codegen/model/ItemSourceKind.kt | 4 +- .../dynamodbmapper/codegen/model/Member.kt | 1 + .../codegen/model/MemberCodegenBehavior.kt | 18 +- .../dynamodbmapper/codegen/model/Operation.kt | 4 +- .../dynamodbmapper/codegen/model/Structure.kt | 5 +- .../hll/dynamodbmapper/codegen/model/Type.kt | 123 ---------- .../codegen/rendering/HighLevelRenderer.kt | 3 +- .../codegen/rendering/OperationRenderer.kt | 3 +- .../rendering/OperationsTypeRenderer.kt | 5 +- .../codegen/rendering/RenderContext.kt | 2 +- .../codegen/rendering/RendererBase.kt | 2 +- 30 files changed, 52 insertions(+), 1137 deletions(-) delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt delete mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGenerator.kt delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGeneratorFactory.kt delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/ImportDirectives.kt delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngine.kt delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessor.kt delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Type.kt diff --git a/hll/codegen/build.gradle.kts b/hll/codegen/build.gradle.kts index 8f3ff496955..99f4139e293 100644 --- a/hll/codegen/build.gradle.kts +++ b/hll/codegen/build.gradle.kts @@ -9,6 +9,7 @@ plugins { dependencies { implementation(libs.ksp.api) + implementation(libs.smithy.kotlin.runtime.core) testImplementation(libs.junit.jupiter) testImplementation(libs.junit.jupiter.params) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt deleted file mode 100644 index 9ee06cb1700..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/DataTypeGenerator.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.core - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Member -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Structure -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.RenderContext - -/** - * Generates immutable data types from a [Structure] into an underlying [CodeGenerator]. These data types consist of a - * read-only `interface` (with a `val` field for each [Structure] member), a `private data class` that serves as the - * default implementation, and a `public` factory function which allows constructing new instances by passing values as - * arguments. - * - * **FIXME**: This generator SHOULD generate a mutable builder object instead of a factory function for backwards - * compatibility. - * - * Example of generated data type: - * - * ```kotlin - * public interface User { - * public companion object { } - * - * public val id: Int - * public val name: String - * public val active: Boolean - * } - * - * private data class UserImpl( - * override val id: Int, - * override val name: String, - * override val active: Boolean, - * ) - * - * public fun User( - * id: Int, - * name: String, - * active: Boolean, - * ): User = UserImpl( - * id, - * name, - * active, - * ) - * ``` - * @param ctx The active rendering context - * @param generator The underlying generator for the context into which the data type should be written - * @param structure The [Structure] which describes the data type for which to generate code - */ -class DataTypeGenerator( - private val ctx: RenderContext, - generator: CodeGenerator, - val structure: Structure, -) : CodeGenerator by generator { - fun generate() { - withBlock("public interface #T {", "}", structure.type) { - write("public companion object { }") // leave room for future expansion - blankLine() - members { write("public val #L: #T", name, type) } - } - blankLine() - - val genericParams = structure - .members - .flatMap { it.type.generics() } - .map { it.shortName } - .requireAllDistinct() - .takeUnless { it.isEmpty() } - ?.joinToString(", ", "<", ">") - ?: "" - - val implName = "${structure.type.shortName}Impl" - openBlock("private data class #L#L(", implName, genericParams) - members { write("override val #L: #T,", name, type) } - closeBlock("): #T", structure.type) - blankLine() - - // TODO replace function builder with Builder interface+impl - openBlock("public fun #L #L(", genericParams, structure.type.shortName) - members { write("#L: #T,", name, type) } - closeAndOpenBlock("): #T = #L(", structure.type, implName) - members { write("#L,", name) } - closeBlock(")") - } - - private inline fun members(crossinline block: Member.() -> Unit) { - structure.members.forEach { it.block() } - } -} - -private fun Type.generics(): List = buildList { - when (val type = this@generics) { - is TypeVar -> add(type) - is TypeRef -> type.genericArgs.flatMap { it.generics() } - } -} - -private fun > C.requireAllDistinct(): C { - val collection = this - val itemCounts = buildMap { - collection.forEach { element -> - compute(element) { _, existingCount -> (existingCount ?: 0) + 1 } - } - } - - val duplicates = itemCounts.filter { (_, count) -> count > 1 }.keys - require(duplicates.isEmpty()) { "Found duplicated items: $duplicates" } - - return collection -} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt index abb44685f5f..cfc0e96b76b 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt @@ -4,7 +4,7 @@ */ package aws.sdk.kotlin.hll.codegen.core -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeRef /** * A mutable collection of [ImportDirectives] for eventually writing to a code generator diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt index 9983b676c1a..42c5fb4f1fe 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt @@ -4,9 +4,9 @@ */ package aws.sdk.kotlin.hll.codegen.core -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Type -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.quote +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.util.quote /** * Defines a template processor which maps an argument value of any type to a string value diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt deleted file mode 100644 index 39225e29c86..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ItemSourceKind.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.model - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg - -/** - * Identifies a type in the `ItemSource` hierarchy - * @param hoistedFields Which fields should be hoisted from the low-level request type for this item source kind (e.g., - * for `TableSpec` the `tableName` field should be hoisted) - * @param parent The parent type of this type (if any) - * @param isAbstract Indicates whether this item source kind is purely abstract and should not have an implementation - * class (e.g., `ItemSource` should be abstract and non-instantiable) - */ -enum class ItemSourceKind( - val hoistedFields: List, - val parent: ItemSourceKind? = null, - val isAbstract: Boolean = false, -) { - /** - * Indicates the `ItemSource` interface - */ - ItemSource(listOf(), isAbstract = true), - - /** - * Indicates the `Index` interface - */ - Index(listOf("indexName", "tableName"), ItemSource), - - /** - * Indicates the `Table` interface - */ - Table(listOf("tableName"), ItemSource), - - ; - - /** - * Get the [TypeRef] for the `*Spec` type for this item source kind - * @param typeVar The type variable name to use for the generic type - */ - fun getSpecType(typeVar: String): TypeRef = TypeRef(Pkg.Hl.Model, "${name}Spec", listOf(TypeVar(typeVar))) -} - -/** - * Identifies the types of `ItemSource` on which an operation can be invoked (e.g., `Scan` can be invoked on a table, - * index, or any generic item source, whereas `GetItem` can only be invoked on a table) - */ -val Operation.itemSourceKinds: Set - get() = when (name) { - "Query", "Scan" -> setOf(ItemSourceKind.ItemSource, ItemSourceKind.Index, ItemSourceKind.Table) - else -> setOf(ItemSourceKind.Table) - } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt deleted file mode 100644 index ec2b6dfa374..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.model - -import com.google.devtools.ksp.symbol.KSPropertyDeclaration - -/** - * Describes a member (i.e., component field, attribute, property, etc.) of a [Structure] - * @param name The name of the member inside its parent [Structure] - * @param type The [Type] of the member - */ -data class Member(val name: String, val type: Type) { - companion object { - /** - * Derive a [Member] from a [KSPropertyDeclaration] - */ - fun from(prop: KSPropertyDeclaration) = Member( - name = prop.simpleName.getShortName(), - type = Type.from(prop.type), - ) - } -} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt deleted file mode 100644 index 533755d18fc..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/MemberCodegenBehavior.kt +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.model - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg - -private val attrMapTypes = setOf(Types.AttributeMap, Types.AttributeMap.nullable()) - -/** - * Describes a behavior to apply for a given [Member] in a low-level structure when generating code for an equivalent - * high-level structure. This interface implements no behaviors on its own; it merely gives strongly-typed names to - * behaviors that will be implemented by calling code. - */ -sealed interface MemberCodegenBehavior { - companion object { - /** - * Identifies a [MemberCodegenBehavior] for the given [Member] by way of various heuristics - * @param member The [Member] for which to identify a codegen behavior - */ - fun identifyFor(member: Member) = when { - member in unsupportedMembers -> Drop - member.type in attrMapTypes -> if (member.name == "key") MapKeys else MapAll - member.isTableName -> Hoist - else -> PassThrough - } - } - - /** - * Indicates that a member should be copied as-is from a low-level structure to a high-level equivalent (i.e., no - * changes to name, type, etc. are required) - */ - data object PassThrough : MemberCodegenBehavior - - /** - * Indicates that a member is an attribute map which may contain _all_ attributes for a data type (as opposed to - * only _key_ attributes) and should be replaced with a generic type (i.e., a `Map` member - * in a low-level structure should be replaced with a generic `T` member in a high-level structure) - */ - data object MapAll : MemberCodegenBehavior - - /** - * Indicates that a member is an attribute map which contains _key_ attributes for a data type (as opposed to _all_ - * attributes) and should be replaced with a generic type (i.e., a `Map` member - * in a low-level structure should be replaced with a generic `T` member in a high-level structure) - */ - data object MapKeys : MemberCodegenBehavior - - /** - * Indicates that a member is unsupported and should not be replicated from a low-level structure to the high-level - * equivalent (e.g., a deprecated member that has been replaced with new features need not be carried forward) - */ - data object Drop : MemberCodegenBehavior - - /** - * Indicates that a member from a low-level structure should be "hoisted" outside its high-level equivalent. This is - * similar to [Drop] but indicates that other codegen may use the member in different ways (e.g., a table name - * parameter in a low-level structure may be hoisted to a different API but not added to the equivalent high-level - * structure). - */ - data object Hoist : MemberCodegenBehavior -} - -/** - * Identifies a [MemberCodegenBehavior] for this [Member] by way of various heuristics - */ -val Member.codegenBehavior: MemberCodegenBehavior - get() = when { - this in unsupportedMembers -> MemberCodegenBehavior.Drop - type in attrMapTypes -> if (name == "key") MemberCodegenBehavior.MapKeys else MemberCodegenBehavior.MapAll - isTableName || isIndexName -> MemberCodegenBehavior.Hoist - else -> MemberCodegenBehavior.PassThrough - } - -private val Member.isTableName: Boolean - get() = name == "tableName" && type == Types.StringNullable - -private val Member.isIndexName: Boolean - get() = name == "indexName" && type == Types.StringNullable - -private fun llType(name: String) = TypeRef(Pkg.Ll.Model, name) - -private val unsupportedMembers = listOf( - // superseded by ConditionExpression - Member("conditionalOperator", llType("ConditionalOperator")), - Member("expected", Type.stringMap(llType("ExpectedAttributeValue"))), - - // superseded by FilterExpression - Member("queryFilter", Type.stringMap(llType("Condition"))), - Member("scanFilter", Type.stringMap(llType("Condition"))), - - // superseded by KeyConditionExpression - Member("keyConditions", Type.stringMap(llType("Condition"))), - - // superseded by ProjectionExpression - Member("attributesToGet", Type.list(Types.String)), - - // superseded by UpdateExpression - Member("attributeUpdates", Type.stringMap(llType("AttributeValueUpdate"))), - - // TODO add support for expressions - Member("expressionAttributeNames", Type.stringMap(Types.String)), - Member("expressionAttributeValues", Types.AttributeMap), - Member("conditionExpression", Types.String), - Member("projectionExpression", Types.String), - Member("updateExpression", Types.String), -).map { member -> - if (member.type is TypeRef) { - member.copy(type = member.type.nullable()) - } else { - member - } -}.toSet() diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt deleted file mode 100644 index 1f474e95227..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/ModelAttributes.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.model - -import aws.smithy.kotlin.runtime.collections.AttributeKey - -/** - * Defines [AttributeKey] instances that relate to the data model of low-level to high-level codegen - */ -object ModelAttributes { - /** - * For a given high-level [Operation], this attribute key identifies the associated low-level [Operation] - */ - val LowLevelOperation: AttributeKey = AttributeKey("aws.sdk.kotlin.ddbmapper#LowLevelOperation") - - /** - * For a given high-level [Structure], this attribute key identifies the associated low-level [Structure] - */ - val LowLevelStructure: AttributeKey = AttributeKey("aws.sdk.kotlin.ddbmapper#LowLevelStructure") -} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt deleted file mode 100644 index 9351301e038..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Operation.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.model - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.capitalizeFirstChar -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.plus -import aws.smithy.kotlin.runtime.collections.Attributes -import aws.smithy.kotlin.runtime.collections.emptyAttributes -import aws.smithy.kotlin.runtime.collections.get -import com.google.devtools.ksp.symbol.KSFunctionDeclaration - -/** - * Describes a service operation (i.e., API method) - * @param methodName The name of the operation as a code-suitable method name. For example, `getItem` is a suitable - * method name in Kotlin, whereas `GetItem` is not (improperly cased) nor is `get item` (contains a space). - * @param request The [Structure] for requests/inputs to this operation - * @param response The [Structure] for responses/output from this operation - * @param attributes An [Attributes] collection for associating typed attributes with this operation - */ -data class Operation( - val methodName: String, - val request: Structure, - val response: Structure, - val attributes: Attributes = emptyAttributes(), -) { - /** - * The capitalized name of this operation's [methodName]. For example, if [methodName] is `getItem` then [name] - * would be `GetItem`. - */ - val name = methodName.capitalizeFirstChar // e.g., "GetItem" vs "getItem" - - companion object { - /** - * Derive an [Operation] from a [KSFunctionDeclaration] - */ - fun from(declaration: KSFunctionDeclaration) = Operation( - methodName = declaration.simpleName.getShortName(), - request = Structure.from(declaration.parameters.single().type), - response = Structure.from(declaration.returnType!!), - ) - } -} - -/** - * Gets the low-level [Operation] equivalent for this high-level operation - */ -val Operation.lowLevel: Operation - get() = attributes[ModelAttributes.LowLevelOperation] - -/** - * Derives a high-level [Operation] equivalent for this low-level operation - * @param pkg The Kotlin package to use for the high-level operation's request and response structures - */ -fun Operation.toHighLevel(pkg: String): Operation { - val llOperation = this@toHighLevel - val hlRequest = llOperation.request.toHighLevel(pkg) - val hlResponse = llOperation.response.toHighLevel(pkg) - val hlAttributes = llOperation.attributes + (ModelAttributes.LowLevelOperation to llOperation) - return Operation(llOperation.methodName, hlRequest, hlResponse, hlAttributes) -} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt deleted file mode 100644 index 7e84940f4be..00000000000 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Structure.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.codegen.model - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.plus -import aws.smithy.kotlin.runtime.collections.Attributes -import aws.smithy.kotlin.runtime.collections.emptyAttributes -import aws.smithy.kotlin.runtime.collections.get -import com.google.devtools.ksp.getDeclaredProperties -import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSTypeReference - -/** - * Describes a structure (i.e., class, struct, etc.) which contains zero or more [Member] instances - * @param type The [TypeRef] for this structure, which includes its name and Kotlin package - * @param members The [Member] instances which are part of this structure - * @param attributes An [Attributes] collection for associating typed attributes with this structure - */ -data class Structure( - val type: TypeRef, - val members: List, - val attributes: Attributes = emptyAttributes(), -) { - companion object { - /** - * Derives a [Structure] from the given [KSTypeReference] - */ - fun from(ksTypeRef: KSTypeReference) = Structure( - type = Type.from(ksTypeRef), - members = (ksTypeRef.resolve().declaration as KSClassDeclaration) - .getDeclaredProperties() - .map(Member::from) - .toList(), - ) - } -} - -/** - * Gets the low-level [Structure] equivalent for this high-level structure - */ -val Structure.lowLevel: Structure - get() = attributes[ModelAttributes.LowLevelStructure] - -/** - * Derives a a high-level [Structure] equivalent for this low-level structure - * @param pkg The Kotlin package to use for the high-level structure - */ -fun Structure.toHighLevel(pkg: String): Structure { - val llStructure = this@toHighLevel - - val hlType = TypeRef(pkg, llStructure.type.shortName, listOf(TypeVar("T"))) - - val hlMembers = llStructure.members.mapNotNull { llMember -> - when (llMember.codegenBehavior) { - MemberCodegenBehavior.PassThrough -> llMember - MemberCodegenBehavior.MapAll, MemberCodegenBehavior.MapKeys -> - llMember.copy(type = TypeVar("T", llMember.type.nullable)) - else -> null - } - } - - val hlAttributes = llStructure.attributes + (ModelAttributes.LowLevelStructure to llStructure) - - return Structure(hlType, hlMembers, hlAttributes) -} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index d29c2dbd4fa..34e8acbc2ce 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -4,7 +4,8 @@ */ package aws.sdk.kotlin.hll.codegen.model -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg +import aws.sdk.kotlin.hll.codegen.model.Type.Companion.map +import aws.sdk.kotlin.hll.codegen.util.Pkg import com.google.devtools.ksp.symbol.KSTypeReference /** @@ -95,7 +96,7 @@ data class TypeVar(override val shortName: String, override val nullable: Boolea /** * Derives a nullable [Type] equivalent for this type */ -fun Type.nullable() = when { +public fun Type.nullable() = when { nullable -> this this is TypeRef -> copy(nullable = true) this is TypeVar -> copy(nullable = true) @@ -110,6 +111,12 @@ object Types { val String = TypeRef("kotlin", "String") val StringNullable = String.nullable() + /** + * Creates a [TypeRef] for a generic [Map] with [String] keys + * @param value The type of values in the map + */ + fun StringMap(value: Type) = map(String, value) + // Low-level types val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") val AttributeMap = Type.map(String, AttributeValue) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts index 783dfd4ec8e..dcc690d008f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts @@ -9,6 +9,7 @@ plugins { dependencies { implementation(libs.ksp.api) + implementation(project(":hll:codegen")) implementation(project(":services:dynamodb")) testImplementation(libs.junit.jupiter) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt index 4f5ea63db50..dcec8037698 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt @@ -4,12 +4,12 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.CodeGeneratorFactory +import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.toHighLevel import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.HighLevelRenderer import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.RenderContext -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg +import aws.sdk.kotlin.hll.codegen.util.Pkg import aws.sdk.kotlin.services.dynamodb.DynamoDbClient import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.getDeclaredFunctions diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGenerator.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGenerator.kt deleted file mode 100644 index 4a674776e8a..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGenerator.kt +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core - -private const val INDENT = " " - -/** - * An object which generates code into some context (typically an in-memory buffer which will eventually be written to a - * file). It includes basic methods for writing code in Kotlin such as creating blocks and indentation, docs, and - * ordinary lines of code. - * - * # String templates - * - * All methods which accept text to be written (e.g., [write], [openBlock], etc.) allow for the use of a string template - * with zero or more arguments substituted in for placeholders. See [TemplateEngine] for more details on string - * templates and argument substitution. - * - * # Indentation tracking - * - * Code generators track a running indentation level, which is used to form an indentation prefix prepended to lines - * written by this generator. The default indentation string per level is 4 spaces and the indentation level starts at 0 - * for new generators. The indentation level may be increased or decreased manually via the methods [indent] and - * [dedent]. The indentation level is also adjusted by **block** methods (e.g., [openBlock], [withBlock], etc.), which - * automatically indent/dedent around logical blocks of code. - */ -interface CodeGenerator { - /** - * The import directives for the current context - */ - val imports: ImportDirectives - - /** - * Append a blank line if there isn't already one in the buffer (i.e., invoking this method multiple times - * sequentially will append _only one_ blank line). - */ - fun blankLine() - - /** - * Close a manually-opened block of code by dedenting and appending some finalizing text - * @param template The string template or literal to append after dedenting (e.g., `}`) - * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on - * string templates and argument substitution. - */ - fun closeBlock(template: String, vararg args: Any) - - /** - * Close a manually-opened block and open a new one by dedenting, appending some intermediate text, and then - * indenting again - * @param template The string template or literal to append after dedenting and before re-indenting (e.g., - * `} else {`) - * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on - * string templates and argument substitution. - */ - fun closeAndOpenBlock(template: String, vararg args: Any) - - /** - * Decreases the active indentation level - * @param levels The number of levels to decrement. Defaults to `1` if unspecified. - */ - fun dedent(levels: Int = 1) - - /** - * Increases the active indentation level - * @param levels The number of levels to increment. Defaults to `1` if unspecified. - */ - fun indent(levels: Int = 1) - - /** - * Open a block of code manually by appending some starting text and then indenting - * @param template The string template or literal to append before indenting (e.g., `if (foo) {`) - * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on - * string templates and argument substitution. - */ - fun openBlock(template: String, vararg args: Any) - - /** - * Sends the accumulated text of this generator to the backing buffer (e.g., writes it to a file) - */ - fun persist() - - /** - * Writes a logical block of text by appending some starting text, indenting, executing the [block] function which - * may add text inside the block, dedenting, and writing some finalizing text - * @param preTemplate The string template or literal to append before indenting (e.g., `if (foo) {`) - * @param postText The string literal to append after dedenting (e.g., `}`). No templating or argument substitution - * will be performed on this string. - * @param args The arguments to substitute into the [preTemplate] (if any). See [TemplateEngine] for more details on - * string templates and argument substitution. - * @param block A function to execute in between appending the [preTemplate] and before appending the [postText]. - * This function typically writes more code, which will inherit the active indentation level which will have been - * incremented by `1` by this method. - */ - fun withBlock(preTemplate: String, postText: String, vararg args: Any, block: () -> Unit) - - /** - * Writes a block of documentation by automatically prepending KDoc-style comment tokens as prefixes. This method - * will append an opening comment token (i.e., `/**`), add a special indentation prefix (i.e., ` * `) to the - * existing indentation, execute the given [block], dedent back to the non-comment indentation prefix, and append a - * closing comment token (i.e., `*/`). - * @param block The function to execute in between appending the opening comment token and the closing comment - * token. This function typically writes more code, which will inherit the active indentation prefix and be rendered - * as a KDoc-style comment. - */ - fun withDocs(block: () -> Unit) - - /** - * Writes a line of text, including a terminating newline (i.e., `\n`) - * @param template The string template or literal to append - * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on - * string templates and argument substitution. - */ - fun write(template: String, vararg args: Any) - - /** - * Writes a string of text, _not_ including a terminating newline. Invoking this method repeatedly in sequence - * allows gradually forming an entire line incrementally rather than using a single [write] call. An in-progress - * line may be terminated by invoking a method such as [write] (which will continue on the current line) or - * [blankLine] (which will append a blank line). - * @param template The string template or literal to append - * @param args The arguments to substitute into the [template] (if any). See [TemplateEngine] for more details on - * string templates and argument substitution. - */ - fun writeInline(template: String, vararg args: Any) -} - -/** - * The standard implementation of [CodeGenerator]. This implementation automatically prepends a comment indicating the - * source is codegenned, a `package` directive specified by the constructor parameter [pkg], and a set of `import` - * directives (if any) from [imports]. - * - * Example of automatically prepended content: - * - * ```kotlin - * // Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT! - * - * package foo.bar - * - * import a.A - * import b.B - * import c.C - * ``` - * @param pkg The Kotlin package for the generated code (e.g., `aws.sdk.kotlin.hll.dynamodbmapper.operations`) - * @param engine A configured template engine to use while processing string templates - * @param persistCallback A callback method to invoke when the [persist] method is called on this class - * @param imports The import directives for the generator. These may be appended by more lines being written. - */ -class CodeGeneratorImpl( - private val pkg: String, - private val engine: TemplateEngine, - private val persistCallback: (String) -> Unit, - override val imports: ImportDirectives = ImportDirectives(), -) : CodeGenerator { - private val builder = StringBuilder() - private var indent = "" - - override fun blankLine() { - if (!builder.endsWith("\n\n")) builder.append('\n') - } - - override fun closeBlock(template: String, vararg args: Any) { - dedent() - write(template, *args) - } - - override fun closeAndOpenBlock(template: String, vararg args: Any) { - dedent() - write(template, *args) - indent() - } - - override fun dedent(levels: Int) { - repeat(levels) { - indent = indent.removeSuffix(INDENT) - } - } - - override fun indent(levels: Int) { - indent += INDENT.repeat(levels) - } - - override fun openBlock(template: String, vararg args: Any) { - write(template, *args) - indent() - } - - override fun persist() { - val content = buildString { - appendLine("// Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT!") - appendLine() - appendLine("package $pkg") - appendLine() - imports.formatted.takeIf { it.isNotBlank() }?.let { appendLine(it) } - append(builder) - } - persistCallback(content) - } - - override fun withBlock(preTemplate: String, postText: String, vararg args: Any, block: () -> Unit) { - openBlock(preTemplate, *args) - block() - closeBlock(postText) - } - - override fun withDocs(block: () -> Unit) { - write("/**") - indent += " * " - block() - indent = indent.removeSuffix(" * ") - write(" */") - } - - override fun write(template: String, vararg args: Any) { - writeInline(template, *args) - builder.append('\n') - } - - override fun writeInline(template: String, vararg args: Any) { - val text = engine.process(template, args.toList()) - if (builder.endsWith('\n')) builder.append(indent) - builder.append(text) - } -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGeneratorFactory.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGeneratorFactory.kt deleted file mode 100644 index 4e4950dd16f..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/CodeGeneratorFactory.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core - -import com.google.devtools.ksp.processing.Dependencies -import com.google.devtools.ksp.processing.KSPLogger -import com.google.devtools.ksp.processing.CodeGenerator as KSCodeGenerator - -/** - * A factory for [CodeGenerator] instances which will be backed by a [KSCodeGenerator] instance - * @param ksCodeGenerator The underlying KSP [KSCodeGenerator] to use for low-level file access and dependency tracking - * @param logger A logger instance to use for message - */ -class CodeGeneratorFactory(private val ksCodeGenerator: KSCodeGenerator, private val logger: KSPLogger) { - private val dependencies = Dependencies.ALL_FILES - - /** - * Creates a new [CodeGenerator] backed by a [KSCodeGenerator]. The returned generator starts with no imports and - * uses a configured [TemplateEngine] with the default set of processors. - * @param name The name of the file which should be created _without_ parent directory or extension (which is always - * **.kt**) - * @param pkg The Kotlin package for the generated code (e.g., `aws.sdk.kotlin.hll.dynamodbmapper.operations`) - */ - fun generator(name: String, pkg: String): CodeGenerator { - val imports = ImportDirectives() - val processors = listOf( - TemplateProcessor.Literal, - TemplateProcessor.QuotedString, - TemplateProcessor.forType(pkg, imports), - ) - val engine = TemplateEngine(processors) - - val persistCallback: (String) -> Unit = { content -> - logger.info("Checking out code generator for class $pkg.$name") - - ksCodeGenerator - .createNewFile(dependencies, pkg, name) // FIXME don't depend on ALL_FILES - .use { outputStream -> - outputStream.writer().use { writer -> writer.append(content) } - } - } - - return CodeGeneratorImpl(pkg, engine, persistCallback, imports) - } -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt index d50ac5a1e35..3fdc6513049 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt @@ -4,6 +4,10 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core +import aws.sdk.kotlin.hll.codegen.core.CodeGenerator +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Member import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Structure diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/ImportDirectives.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/ImportDirectives.kt deleted file mode 100644 index e899160da8c..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/ImportDirectives.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef - -/** - * A mutable collection of [ImportDirectives] for eventually writing to a code generator - */ -class ImportDirectives : MutableSet by mutableSetOf() { - operator fun get(shortName: String) = firstOrNull { it.shortName == shortName } - - /** - * Returns a formatted code string with each import on a dedicated line. Imports will be sorted with the following - * precedence: - * 1. Unaliased imports before alised imports - * 2. The special package prefixes `java`, `javax`, `kotlin` after all other imports - * 3. Lexicographically sorted - */ - val formatted: String - get() = buildString { - sortedWith(importComparator).forEach { appendLine(it.formatted) } - } -} - -private val specialPrefixes = setOf( - "java.", - "javax.", - "kotlin.", -) - -private val importComparator = compareBy { it.alias != null } // aliased imports at the very end - .thenBy { directive -> specialPrefixes.any { directive.fullName.startsWith(it) } } // special prefixes < aliases - .thenBy { it.fullName } // sort alphabetically - -/** - * Describes a Kotlin `import` directive - * @param fullName The full name of the import (e.g., `java.net.Socket`) - * @param alias An optional alias for the import (e.g., `JavaSocket`). If present, a formatted code string for this - * directive will include an `as` clause (e.g., `import java.net.Socket as JavaSocket`). - */ -data class ImportDirective(val fullName: String, val alias: String? = null) { - /** - * The unaliased "short name" of an import directive—namely, everything after the last `.` separator. For example, - * for the full name `java.net.Socket` the short name is `Socket`. - */ - val shortName = fullName.split(".").last() - - private val aliasFormatted = alias?.let { " as $it" } ?: "" - - /** - * The formatted `import` code string for this directive - */ - val formatted = "import $fullName$aliasFormatted" -} - -fun ImportDirective(type: TypeRef, alias: String? = null) = ImportDirective(type.fullName, alias) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngine.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngine.kt deleted file mode 100644 index d180e781f88..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateEngine.kt +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core - -/** - * A string processing engine that replaces template parameters with passed arguments to form a final string. String - * templates take the form of string literals containing zero or more **parameters**, which are special sequences - * starting with `#`. When the engine encounters these parameters, it endeavors to replace the entire parameter with an - * argument value by using a matching [TemplateProcessor]. This may fail if no matching processor is found, there is a - * mismatch between the template and passed arguments, if data types of arguments are incorrect, or other reasons, in - * which case an exception will be thrown. - * - * # Parameters - * - * All parameters start with `#` and end with an uppercase letter (`[A-Z]`). They may optionally contain a number as - * well, which makes them **Positional Parameters**. Otherwise, they are **Sequential Parameters**. Templates cannot - * contain _both_ types of parameters, otherwise an exception will be thrown. - * - * ## Sequential Parameters - * - * Parameters in the form of `#[A-Z]` are sequential parameters. The first such sequential parameter will be substituted - * with the first passed argument, the second will be replaced with the second argument, and so forth. If the number of - * sequential parameters does not match the number of arguments, an exception will be thrown. - * - * Note that with this type of parameter, substituting the same argument value multiple times requires passing that - * argument multiple times. - * - * ## Positional Parameters - * - * Parameters in the form of `#n[A-Z]` (where `n > 0`) are positional parameters. The number `n` in the parameter - * indicates the 1-based index of the argument to use for substitution. If the number `n` references an index outside - * the range of arguments (e.g., less than `0` or greater than the number of passed arguments), an exception will be - * thrown. - * - * Note that with this type of parameter, substituting the same argument value multiple times does not require _passing_ - * that argument multiple times, merely using the same `n` value for multiple parameters. - * - * # Processors - * - * Template engines reference zero or more [TemplateProcessor] instances which perform mapping from raw argument values - * to strings to be used in parameter substitution. When the template engine encounters a parameter in a string - * template, it attempts to match the parameter **key** (an uppercase letter `[A-Z]`) to the key of a processor. If no - * referenced processor has a matching key, an exception will be thrown. - */ -class TemplateEngine(processors: List) { - private val processors = processors.associate { it.key to it.handler } - private val parameterRegex = """(?): String { - var allIndexed: Boolean? = null - - return parameterRegex.replaceIndexed(template) { pos, result -> - val explicitIndex = result.groupValues[1].takeUnless { it.isEmpty() }?.toInt()?.minus(1) - val indexed = explicitIndex != null - - fun req(condition: Boolean, message: () -> String) { - require(condition) { - buildString { - append("Error in template '") - append(template) - append("' for parameter '") - append(result.value) - append("' at index ") - append(result.range.first) - append(": ") - - append(message()) - } - } - } - - fun reqNotNull(element: T?, message: () -> String): T { - req(element != null, message) - return element!! - } - - req(allIndexed == null || allIndexed == indexed) { - "Cannot mix indexed and non-indexed parameters in the same template" - } - allIndexed = indexed - - val key = result.groupValues[2].toCharArray().single() - val handler = reqNotNull(processors[key]) { "No processor found for key character '$key'" } - - val index = explicitIndex ?: pos - req(index in args.indices) { - buildString { - if (indexed) { - append("Index ") - append(result.groupValues[1]) - } else { - append("Parameter index ") - append(pos) - } - append(" is outside of args bounds ") - append(args.indices) - } - } - - handler(args[index]) - } - } -} - -private fun Regex.replaceIndexed(input: CharSequence, transform: (index: Int, MatchResult) -> CharSequence): String { - var index = 0 - return replace(input) { - transform(index, it).also { index++ } - } -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessor.kt deleted file mode 100644 index f0981dccdb7..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/TemplateProcessor.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Type -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.TypeRef -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.quote - -/** - * Defines a template processor which maps an argument value of any type to a string value - * @param key The identifier for this processor, which will be used by the [TemplateEngine] to match a parameter with - * this processor - * @param handler A function that accepts an input argument (as an [Any]) and returns a formatted string - */ -data class TemplateProcessor(val key: Char, val handler: (Any) -> String) { - companion object { - /** - * Instantiate a new typed template processor which only receives arguments of a specific type [T] - * @param T The type of argument values this processor will accept - * @param key The identifier for this processor, which will be used by the [TemplateEngine] to match a parameter - * with this processor - * @param handler A function that accepts an input argument of type [T] and returns a formatted string - */ - inline fun typed(key: Char, crossinline handler: (T) -> String) = TemplateProcessor(key) { value -> - require(value is T) { "Expected argument of type ${T::class} but found $value" } - handler(value) - } - - /** - * A literal template processor. This processor substitutes parameters in the form of `#L` with the [toString] - * representation of the corresponding argument. - */ - val Literal = TemplateProcessor('L') { it.toString() } - - /** - * A quoted string template processor. This processor substitutes parameters in the form of `#S` with the - * quoted/escaped form of a string argument. See [quote] for more details. - */ - val QuotedString = typed('S') { it.quote() } - - /** - * Creates a template processor for [Type] values. This processor substitutes parameters in the form of `#T` - * with the name or an alias of the type. It also appends `import` directives if necessary. - * @param pkg The Kotlin package into which code is being generated. An `import` directive will not be added if - * a passed argument has the same package as this processor. - * @param imports An [ImportDirectives] collection to which new imports will be appended - */ - fun forType(pkg: String, imports: ImportDirectives): TemplateProcessor { - val processor = ImportingTypeProcessor(pkg, imports) - return typed('T', processor::format) - } - } - - init { - require(key in 'A'..'Z') { "Key character must be a capital letter (A-Z)" } - } -} - -private open class TypeProcessor { - open fun format(type: Type): String = buildString { - append(type.shortName) - if (type is TypeRef && type.genericArgs.isNotEmpty()) { - type.genericArgs.joinToString(", ", "<", ">", transform = ::format).let(::append) - } - - if (type.nullable) append('?') - } -} - -private class ImportingTypeProcessor(private val pkg: String, private val imports: ImportDirectives) : TypeProcessor() { - override fun format(type: Type): String = buildString { - if (type is TypeRef && type.pkg != pkg) { - val existingImport = imports[type.shortName] - - if (existingImport == null) { - imports += ImportDirective(type) - } else if (existingImport.fullName != type.fullName) { - append(type.pkg) - append('.') - } - } - - append(super.format(type)) - } -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt index f40be22e339..7d305442b6a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt @@ -4,7 +4,9 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.util.Pkg /** * Identifies a type in the `ItemSource` hierarchy diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt index 36fe074ef44..8cdcd3660e4 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +import aws.sdk.kotlin.hll.codegen.model.Type import com.google.devtools.ksp.symbol.KSPropertyDeclaration /** diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt index f192b0ef472..cf9ae4af01a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt @@ -4,7 +4,11 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.Types +import aws.sdk.kotlin.hll.codegen.model.nullable +import aws.sdk.kotlin.hll.codegen.util.Pkg private val attrMapTypes = setOf(Types.AttributeMap, Types.AttributeMap.nullable()) @@ -84,23 +88,23 @@ private fun llType(name: String) = TypeRef(Pkg.Ll.Model, name) private val unsupportedMembers = listOf( // superseded by ConditionExpression Member("conditionalOperator", llType("ConditionalOperator")), - Member("expected", Type.stringMap(llType("ExpectedAttributeValue"))), + Member("expected", Types.StringMap(llType("ExpectedAttributeValue"))), // superseded by FilterExpression - Member("queryFilter", Type.stringMap(llType("Condition"))), - Member("scanFilter", Type.stringMap(llType("Condition"))), + Member("queryFilter", Types.StringMap(llType("Condition"))), + Member("scanFilter", Types.StringMap(llType("Condition"))), // superseded by KeyConditionExpression - Member("keyConditions", Type.stringMap(llType("Condition"))), + Member("keyConditions", Types.StringMap(llType("Condition"))), // superseded by ProjectionExpression Member("attributesToGet", Type.list(Types.String)), // superseded by UpdateExpression - Member("attributeUpdates", Type.stringMap(llType("AttributeValueUpdate"))), + Member("attributeUpdates", Types.StringMap(llType("AttributeValueUpdate"))), // TODO add support for expressions - Member("expressionAttributeNames", Type.stringMap(Types.String)), + Member("expressionAttributeNames", Types.StringMap(Types.String)), Member("expressionAttributeValues", Types.AttributeMap), Member("conditionExpression", Types.String), Member("projectionExpression", Types.String), diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt index cdbc08a1261..29f548d8e4c 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt @@ -4,8 +4,8 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.capitalizeFirstChar -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.plus +import aws.sdk.kotlin.hll.codegen.util.capitalizeFirstChar +import aws.sdk.kotlin.hll.codegen.util.plus import aws.smithy.kotlin.runtime.collections.Attributes import aws.smithy.kotlin.runtime.collections.emptyAttributes import aws.smithy.kotlin.runtime.collections.get diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt index 5d1198ecd42..7d029bbb406 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt @@ -4,7 +4,10 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.plus +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.util.plus import aws.smithy.kotlin.runtime.collections.Attributes import aws.smithy.kotlin.runtime.collections.emptyAttributes import aws.smithy.kotlin.runtime.collections.get diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Type.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Type.kt deleted file mode 100644 index b2c6985ddbe..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Type.kt +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model - -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.Pkg -import com.google.devtools.ksp.symbol.KSTypeReference - -/** - * Describes a Kotlin data type - */ -sealed interface Type { - companion object { - /** - * Derives a [TypeRef] from a [KSTypeReference] - */ - fun from(ksTypeRef: KSTypeReference): TypeRef { - val resolved = ksTypeRef.resolve() - val name = resolved.declaration.qualifiedName!! - return TypeRef( - pkg = name.getQualifier(), - shortName = name.getShortName(), - genericArgs = resolved.arguments.map { from(it.type!!) }, - nullable = resolved.isMarkedNullable, - ) - } - - /** - * Creates a [TypeRef] for a generic [List] - * @param element The type of elements in the list - */ - fun list(element: Type) = TypeRef(Pkg.Kotlin.Collections, "List", listOf(element)) - - /** - * Creates a [TypeRef] for a named Kotlin type (e.g., `String`) - */ - fun kotlin(name: String) = TypeRef(Pkg.Kotlin.Base, name) - - /** - * Creates a [TypeRef] for a generic [Map] - * @param key The type of keys in the map - * @param value The type of values in the map - */ - fun map(key: Type, value: Type) = TypeRef(Pkg.Kotlin.Collections, "Map", listOf(key, value)) - - /** - * Creates a [TypeRef] for a generic [Map] with [String] keys - * @param value The type of values in the map - */ - fun stringMap(value: Type) = map(Types.String, value) - } - - /** - * Gets the short name (i.e., not including the Kotlin package) for this type - */ - val shortName: String - - /** - * Indicates whether instances of this type allow nullable references - */ - val nullable: Boolean -} - -/** - * A reference to a specific, named type (e.g., [kotlin.String]). - * - * This type reference may have generic arguments, which are themselves instances of a [Type]. For instance, a [TypeRef] - * representing [kotlin.collections.List] would have a single generic argument, which may either be a concrete [TypeRef] - * itself (e.g., `List`) or a generic [TypeVar] (e.g., `List`). - * @param pkg The Kotlin package for this type - * @param shortName The short name (i.e., not include the kotlin package) for this type - * @param genericArgs Zero or more [Type] generic arguments to this type - * @param nullable Indicates whether instances of this type allow nullable references - */ -data class TypeRef( - val pkg: String, - override val shortName: String, - val genericArgs: List = listOf(), - override val nullable: Boolean = false, -) : Type { - /** - * The full name of this type, including the Kotlin package - */ - val fullName: String = "$pkg.$shortName" -} - -/** - * A generic type variable (e.g., `T`) - * @param shortName The name of this type variable - * @param nullable Indicates whether instances of this type allow nullable references - */ -data class TypeVar(override val shortName: String, override val nullable: Boolean = false) : Type - -/** - * Derives a nullable [Type] equivalent for this type - */ -fun Type.nullable() = when { - nullable -> this - this is TypeRef -> copy(nullable = true) - this is TypeVar -> copy(nullable = true) - else -> error("Unknown Type ${this::class}") // Should be unreachable, only here to make compiler happy -} - -/** - * A container/factory object for various [Type] instances - */ -object Types { - // Kotlin standard types - val String = TypeRef("kotlin", "String") - val StringNullable = String.nullable() - - // Low-level types - val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") - val AttributeMap = Type.map(String, AttributeValue) - - // High-level types - val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") - fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) - val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") - val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") - val toItem = TypeRef(Pkg.Hl.Model, "toItem") -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt index bb86dc24b77..8006580a0e5 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt @@ -6,7 +6,8 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.ItemSourceKind import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.util.plus import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.itemSourceKinds /** diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt index 365919f75df..840206849ba 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt @@ -5,7 +5,8 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.DataTypeGenerator -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.ImportDirective +import aws.sdk.kotlin.hll.codegen.core.* +import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt index e39a3d51de7..ce9513e6ab9 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt @@ -4,8 +4,11 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.util.lowercaseFirstChar +import aws.sdk.kotlin.hll.codegen.util.lowercaseFirstChar /** * Renders the `*Operations` interface and `*OperationsImpl` class which contain a method for each codegenned diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt index 3461f321fd8..e5385704d1d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt @@ -4,7 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.CodeGeneratorFactory +import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSNode diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt index 1eb1fc8c336..39694e26ae2 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt @@ -4,7 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.CodeGenerator +import aws.sdk.kotlin.hll.codegen.core.CodeGenerator /** * The parent class for renderers backed by a [CodeGenerator] From d8c65c9c64a54852ddd346d4ab005be1e9e0ee30 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 9 Aug 2024 11:08:40 -0400 Subject: [PATCH 05/59] tests --- .../aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt | 2 +- .../aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt | 2 +- .../kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt index c853b989f7f..c585b81d70f 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt @@ -53,4 +53,4 @@ class TemplateEngineTest { test("n/a", "This should fail: #L #L #1L #L", "a", "b", "c") } } -} +} \ No newline at end of file diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt index ffc793866f7..1e94fd0c254 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt @@ -58,4 +58,4 @@ class TemplateProcessorTest { assertContains(imports, ImportDirective(elderberry)) assertContains(imports, ImportDirective(fig)) } -} +} \ No newline at end of file diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt index c2f85036c6d..a9f4c96a4cd 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.codegen.util +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.util import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test @@ -23,4 +23,4 @@ class StringsTest { fun testQuote() { assertEquals("\"This \\t is a \\\"test\\\"!\"", "This \t is a \"test\"!".quote()) } -} +} \ No newline at end of file From 5edef545df0f0575471ee4342c9de6766e4106b0 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 9 Aug 2024 11:08:51 -0400 Subject: [PATCH 06/59] Fix package name in StringsTest --- .../test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt index a9f4c96a4cd..571dd32882d 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.util +package aws.sdk.kotlin.hll.codegen.util import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test From df80d6603a90c2f86c8bbb9f219ed2f3d2665aea Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 09:52:07 -0400 Subject: [PATCH 07/59] Latest --- hll/codegen/api/codegen.api | 62 ++++++++ .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 20 +++ .../hll}/codegen/rendering/RenderContext.kt | 2 +- .../hll}/codegen/rendering/RendererBase.kt | 2 +- .../aws/sdk/kotlin/hll/codegen/util/Pkg.kt | 1 + .../build.gradle.kts | 1 + .../processor/MapperProcessor.kt | 52 ++----- .../processor/rendering/AnnotationRenderer.kt | 145 ++++++++++++++++++ .../processor/rendering/HighLevelRenderer.kt | 25 +++ .../codegen/HighLevelOpsProcessor.kt | 2 +- .../codegen/core/DataTypeGenerator.kt | 2 +- .../codegen/rendering/HighLevelRenderer.kt | 2 +- .../codegen/rendering/OperationRenderer.kt | 3 + .../rendering/OperationsTypeRenderer.kt | 2 + .../tests/processor/data/UserTest.kt | 66 ++++---- 15 files changed, 314 insertions(+), 73 deletions(-) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/main/kotlin/aws/sdk/kotlin/hll}/codegen/rendering/RenderContext.kt (95%) rename hll/{dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper => codegen/src/main/kotlin/aws/sdk/kotlin/hll}/codegen/rendering/RendererBase.kt (92%) create mode 100644 hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt create mode 100644 hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 5bb044081e8..cae19a62450 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -163,17 +163,78 @@ public final class aws/sdk/kotlin/hll/codegen/model/TypeVar : aws/sdk/kotlin/hll public final class aws/sdk/kotlin/hll/codegen/model/Types { public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types; public final fun StringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getArrayOf ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getAttributeDescriptor ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getAttributeMap ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getAttributeValue ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getBooleanConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getDefaultInstantConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getDynamoDbMapper ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getGetTable ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getHReqContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getIntConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getItemSchema ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getKeySpec ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getKeySpecNumber ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getKeySpecString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getMapperContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getOperation ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getPartitionKey ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getSimpleItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getStringConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getStringNullable ()Laws/sdk/kotlin/hll/codegen/model/Type; + public final fun getTable ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getToItem ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun itemSchema (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; } +public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContext { + public fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;)V + public final fun component1 ()Lcom/google/devtools/ksp/processing/KSPLogger; + public final fun component2 ()Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory; + public final fun component3 ()Ljava/lang/String; + public final fun copy (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; + public fun equals (Ljava/lang/Object;)Z + public final fun getCodegenFactory ()Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory; + public final fun getLogger ()Lcom/google/devtools/ksp/processing/KSPLogger; + public final fun getPkg ()Ljava/lang/String; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContextKt { + public static final fun error (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V + public static synthetic fun error$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V + public static final fun exception (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/Throwable;)V + public static final fun info (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V + public static synthetic fun info$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V + public static final fun logging (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V + public static synthetic fun logging$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V + public static final fun warn (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V + public static synthetic fun warn$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V +} + +public abstract class aws/sdk/kotlin/hll/codegen/rendering/RendererBase : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;)V + public fun blankLine ()V + public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun dedent (I)V + protected abstract fun generate ()V + public fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; + public fun indent (I)V + public fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun persist ()V + public final fun render ()V + public fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V + public fun withDocs (Lkotlin/jvm/functions/Function0;)V + public fun write (Ljava/lang/String;[Ljava/lang/Object;)V + public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V +} + public final class aws/sdk/kotlin/hll/codegen/util/AttributesExtKt { public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/smithy/kotlin/runtime/collections/Attributes; public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/Pair;)Laws/smithy/kotlin/runtime/collections/Attributes; @@ -190,6 +251,7 @@ public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Hl { public final fun getModel ()Ljava/lang/String; public final fun getOps ()Ljava/lang/String; public final fun getPipelineImpl ()Ljava/lang/String; + public final fun getValues ()Ljava/lang/String; } public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Kotlin { diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 34e8acbc2ce..e5356e374b4 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -108,6 +108,7 @@ public fun Type.nullable() = when { */ object Types { // Kotlin standard types + val arrayOf = TypeRef("kotlin", "arrayOf") val String = TypeRef("kotlin", "String") val StringNullable = String.nullable() @@ -122,9 +123,28 @@ object Types { val AttributeMap = Type.map(String, AttributeValue) // High-level types + val DynamoDbMapper = TypeRef(Pkg.Hl.Base, "DynamoDbMapper") + val getTable = TypeRef(Pkg.Hl.Base, "getTable") + val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") + + val Table = TypeRef(Pkg.Hl.Model, "Table") val toItem = TypeRef(Pkg.Hl.Model, "toItem") + + val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") + val KeySpecNumber = TypeRef(Pkg.Hl.Items, "KeySpec.Number") + val KeySpecString = TypeRef(Pkg.Hl.Items, "KeySpec.String") + val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") + val PartitionKey = TypeRef(Pkg.Hl.Items, "PartitionKey") + val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") + val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") + val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") + + val DefaultInstantConverter = TypeRef(Pkg.Hl.Values, "InstantConverter.Default") + val BooleanConverter = TypeRef(Pkg.Hl.Values, "BooleanConverter") + val IntConverter = TypeRef(Pkg.Hl.Values, "IntConverter") + val StringConverter = TypeRef(Pkg.Hl.Values, "StringConverter") } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt similarity index 95% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt rename to hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt index e5385704d1d..fe7d30e3a3d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RenderContext.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering +package aws.sdk.kotlin.hll.codegen.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import com.google.devtools.ksp.processing.KSPLogger diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt rename to hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt index 39694e26ae2..2cf9760c694 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/RendererBase.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering +package aws.sdk.kotlin.hll.codegen.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGenerator diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt index de5e4697f98..68da7965be9 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt @@ -14,6 +14,7 @@ object Pkg { val Model = "$Base.model" val Ops = "$Base.operations" val PipelineImpl = "$Base.pipeline.internal" + val Values = "$Base.values" } object Kotlin { diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts index 4459c69f9a0..ff5a73ee480 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts @@ -7,6 +7,7 @@ kotlin { sourceSets { jvmMain { dependencies { + implementation(project(":hll:codegen")) implementation(project(":hll:dynamodb-mapper:dynamodb-mapper-annotations")) implementation(libs.ksp.api) } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt index 14797b5c09e..395ed4ca8e6 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.processor +import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbItem import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey @@ -16,24 +17,33 @@ import com.google.devtools.ksp.validate private val annotationName = DynamoDbItem::class.qualifiedName!! -public class MapperProcessor(private val env: SymbolProcessorEnvironment) : SymbolProcessor { +public class MapperProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor { + + private var invoked = false + private val logger = environment.logger + private val codeGenerator = environment.codeGenerator + private val codeGeneratorFactory = CodeGeneratorFactory(codeGenerator, logger) + override fun process(resolver: Resolver): List { - env.logger.info("Searching for symbols annotated with $annotationName") + if (invoked) { return listOf() } + invoked = true + + logger.info("Searching for symbols annotated with $annotationName") val annotated = resolver.getSymbolsWithAnnotation(annotationName) val invalid = annotated.filterNot { it.validate() }.toList() - env.logger.info("Found invalid classes $invalid") + logger.info("Found invalid classes $invalid") annotated .toList() - .also { env.logger.info("Found annotated classes: $it") } + .also { logger.info("Found annotated classes: $it") } .filterIsInstance() .filter { it.validate() } - .forEach { it.accept(ItemVisitor(), Unit) } +// .associateWith { } return invalid } - private inner class ItemVisitor : KSVisitorVoid() { + private inner class ClassVisitor : KSVisitorVoid() { override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) { val basePackageName = classDeclaration.packageName.asString() val packageName = "$basePackageName.mapper.schemas" @@ -49,9 +59,6 @@ public class MapperProcessor(private val env: SymbolProcessorEnvironment) : Symb } env.codeGenerator.createNewFile( - Dependencies(true, classDeclaration.containingFile!!), - packageName, - schemaName, ).use { file -> file.bufferedWriter().use { writer -> writer.append( @@ -165,29 +172,4 @@ public class MapperProcessor(private val env: SymbolProcessorEnvironment) : Symb } } } -} - -private data class Property(val name: String, val ddbName: String, val typeName: KSName, val isPk: Boolean) { - companion object { - @OptIn(KspExperimental::class) - fun from(ksProperty: KSPropertyDeclaration) = ksProperty - .getter - ?.returnType - ?.resolve() - ?.declaration - ?.qualifiedName - ?.let { typeName -> - val isPk = ksProperty.isAnnotationPresent(DynamoDbPartitionKey::class) - val name = ksProperty.simpleName.getShortName() - val ddbName = ksProperty.getAnnotationsByType(DynamoDbAttribute::class).singleOrNull()?.name ?: name - Property(name, ddbName, typeName, isPk) - } - } -} - -private val Property.keySpecType: String - get() = when (val fqTypeName = typeName.asString()) { - "kotlin.Int" -> "Number" - "kotlin.String" -> "String" - else -> error("Unsupported key type $fqTypeName, expected Int or String") - } +} \ No newline at end of file diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt new file mode 100644 index 00000000000..311f81405c9 --- /dev/null +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt @@ -0,0 +1,145 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering + +import aws.sdk.kotlin.hll.codegen.core.ImportDirective +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.Types +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import aws.sdk.kotlin.hll.codegen.rendering.RendererBase +import aws.sdk.kotlin.hll.codegen.util.Pkg +import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute +import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey +import com.google.devtools.ksp.KspExperimental +import com.google.devtools.ksp.getAnnotationsByType +import com.google.devtools.ksp.isAnnotationPresent +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSName +import com.google.devtools.ksp.symbol.KSPropertyDeclaration + +public class AnnotationRenderer( + private val classDeclaration: KSClassDeclaration, + private val ctx: RenderContext +) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema") { + private val className = classDeclaration.qualifiedName!!.getShortName() + private val builderName = "${className}Builder" + private val converterName = "${className}Converter" + private val schemaName = "${className}Schema" + + private val properties = classDeclaration.getAllProperties().mapNotNull(Property.Companion::from) + private val keyProperty = checkNotNull(properties.singleOrNull { it.isPk }) { + "Expected exactly one @DynamoDbPartitionKey annotation on a property" + } + + override fun generate() { + val basePackageName = classDeclaration.packageName.asString() + + write("package #L", "$basePackageName.mapper.schemas") + blankLine() + // TODO replace with import directives + write("import aws.sdk.kotlin.hll.dynamodbmapper.*") + write("import aws.sdk.kotlin.hll.dynamodbmapper.items.*") + write("import aws.sdk.kotlin.hll.dynamodbmapper.model.*") + write("import aws.sdk.kotlin.hll.dynamodbmapper.values.*") + write("import $basePackageName.$className") + blankLine() + + renderBuilder() + renderItemConverter() + renderSchema() + renderGetTable() + } + + private fun renderBuilder() { + checkNotNull(properties.singleOrNull { it.isPk }) { "Expected exactly one @DynamoDbPartitionKey annotation on a property" } + + withBlock("public class #L {", "}", builderName) { + properties.forEach { + write("public var #L: #T? = null", it.name, it.typeName.asString()) + } + + withBlock("public fun build(): #T {", "}", className) { + properties.forEach { + write("val #1L = requireNotNull(#1L) { #S }", it.name, "Missing value for $className.${it.name}") + } + blankLine() + withBlock("return $className(", ")") { + properties.joinToString(", ") { it.name } + } + } + } + } + + private fun renderItemConverter() { + withBlock("public object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { + write("builderFactory = ::#L", builderName) + write("build = #L::build", builderName) + withBlock("descriptors = #L(", ")", Types.arrayOf) { + properties.forEach { + renderAttributeDescriptor(it) + } + } + } + } + + private fun renderAttributeDescriptor(prop: Property) { + withBlock("#T(", ")", Types.AttributeDescriptor) { + write("#S,", prop.ddbName) // key + write("#L,", "${className}::${prop.name}") // getter + write("#L,", "${builderName}::${prop.name}::set") // setter + write("#T", prop.valueConverter) // converter + } + } + + private val Property.valueConverter: Type + get() = when (typeName.asString()) { + "aws.smithy.kotlin.runtime.time.Instant" -> Types.DefaultInstantConverter + "kotlin.Boolean" -> Types.BooleanConverter + "kotlin.Int" -> Types.IntConverter + "kotlin.String" -> Types.StringConverter + else -> error("Unsupported attribute type ${typeName.asString()}") + } + + private fun renderSchema() { + withBlock("public object #L : #T.#T<#L, #L> {", "}", schemaName, Types.ItemSchema, Types.PartitionKey, className, keyProperty.typeName.getShortName()) { + write("override val converter : #1L = #1L", converterName) + write("override val partitionKey: #T<#2L> = #2L(#S)", Types.KeySpec, keyProperty.keySpec, keyProperty.name) + } + } + + private val Property.keySpec: Type + get() = when (typeName.asString()) { + "kotlin.Int" -> Types.KeySpecNumber + "kotlin.String" -> Types.KeySpecString + else -> error("Unsupported key type ${typeName.asString()}, expected Int or String") + } + + private fun renderGetTable() { + write("public fun #T.get#2LTable(name: #T): #L.#L<#2L, #L> = #L(name, #L)", + Types.DynamoDbMapper, className, Types.String, Types.Table, Types.PartitionKey, keyProperty.typeName.getShortName(), Types.getTable, schemaName + ) + } +} + +private data class Property(val name: String, val ddbName: String, val typeName: KSName, val isPk: Boolean) { + companion object { + @OptIn(KspExperimental::class) + fun from(ksProperty: KSPropertyDeclaration) = ksProperty + .getter + ?.returnType + ?.resolve() + ?.declaration + ?.qualifiedName + ?.let { typeName -> + val isPk = ksProperty.isAnnotationPresent(DynamoDbPartitionKey::class) + val name = ksProperty.simpleName.getShortName() + val ddbName = ksProperty.getAnnotationsByType(DynamoDbAttribute::class).singleOrNull()?.name ?: name + Property(name, ddbName, typeName, isPk) + } + } +} + + diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt new file mode 100644 index 00000000000..bf95bed3c96 --- /dev/null +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt @@ -0,0 +1,25 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering + +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import com.google.devtools.ksp.symbol.KSClassDeclaration + +/** + * The parent renderer for all codegen from this package. This class orchestrates the various sub-renderers. + * @param annotations A list of annotated classes + */ +public class HighLevelRenderer( + private val ctx: RenderContext, + private val annotations: List +) { + public fun render() { + annotations.forEach { + val renderCtx = RenderContext(ctx.logger, ctx.codegenFactory, "${it.packageName.asString()}.mapper.schemas") + val annotation = AnnotationRenderer(it, renderCtx) + annotation.render() + } + } +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt index dcec8037698..2c7b086540f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt @@ -5,10 +5,10 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.toHighLevel import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.HighLevelRenderer -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.util.Pkg import aws.sdk.kotlin.services.dynamodb.DynamoDbClient import com.google.devtools.ksp.getClassDeclarationByName diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt index 3fdc6513049..94ae3efbcfb 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt @@ -8,10 +8,10 @@ import aws.sdk.kotlin.hll.codegen.core.CodeGenerator import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Member import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Structure -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.RenderContext /** * Generates immutable data types from a [Structure] into an underlying [CodeGenerator]. These data types consist of a diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt index 8006580a0e5..5eb1b511ce7 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt @@ -7,7 +7,7 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.ItemSourceKind import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation import aws.sdk.kotlin.hll.codegen.model.Type -import aws.sdk.kotlin.hll.codegen.util.plus +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.itemSourceKinds /** diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt index 840206849ba..6cd785638d4 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt @@ -7,6 +7,9 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.DataTypeGenerator import aws.sdk.kotlin.hll.codegen.core.* import aws.sdk.kotlin.hll.codegen.model.Types +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import aws.sdk.kotlin.hll.codegen.rendering.RendererBase +import aws.sdk.kotlin.hll.codegen.rendering.info import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt index ce9513e6ab9..e60a81d8755 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt @@ -7,6 +7,8 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* import aws.sdk.kotlin.hll.codegen.util.lowercaseFirstChar diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt index 0f2cbe70fdf..0edb63a637e 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt @@ -1,33 +1,33 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data - -import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf -import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter -import aws.sdk.kotlin.services.dynamodb.model.AttributeValue -import kotlin.test.Test -import kotlin.test.assertEquals - -class UserTest { - @Test - fun testConversion() { - val user = User(123, "Steve", "Rogers", 84) - val converted = UserConverter.toItem(user) - - assertEquals( - itemOf( - "id" to AttributeValue.N("123"), - "fName" to AttributeValue.S("Steve"), - "lName" to AttributeValue.S("Rogers"), - "age" to AttributeValue.N("84"), - ), - converted, - ) - - val unconverted = UserConverter.fromItem(converted) - - assertEquals(user, unconverted) - } -} +///* +// * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// * SPDX-License-Identifier: Apache-2.0 +// */ +//package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data +// +//import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf +//import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter +//import aws.sdk.kotlin.services.dynamodb.model.AttributeValue +//import kotlin.test.Test +//import kotlin.test.assertEquals +// +//class UserTest { +// @Test +// fun testConversion() { +// val user = User(123, "Steve", "Rogers", 84) +// val converted = UserConverter.toItem(user) +// +// assertEquals( +// itemOf( +// "id" to AttributeValue.N("123"), +// "fName" to AttributeValue.S("Steve"), +// "lName" to AttributeValue.S("Rogers"), +// "age" to AttributeValue.N("84"), +// ), +// converted, +// ) +// +// val unconverted = UserConverter.fromItem(converted) +// +// assertEquals(user, unconverted) +// } +//} From 3d5818e2844b5a3fc9af37597e80128c7ae6406c Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 11:04:07 -0400 Subject: [PATCH 08/59] Rendering correctly now --- hll/codegen/api/codegen.api | 3 +- .../kotlin/hll/codegen/core/CodeGenerator.kt | 2 - .../hll/codegen/core/ImportDirectives.kt | 2 + .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 2 - .../processor/MapperProcessor.kt | 266 +++++++++--------- .../processor/rendering/AnnotationRenderer.kt | 68 ++--- .../processor/rendering/HighLevelRenderer.kt | 10 +- 7 files changed, 179 insertions(+), 174 deletions(-) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index cae19a62450..861fb515cd2 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -59,6 +59,7 @@ public final class aws/sdk/kotlin/hll/codegen/core/ImportDirective { public final class aws/sdk/kotlin/hll/codegen/core/ImportDirectives : java/util/Set, kotlin/jvm/internal/markers/KMutableSet { public fun ()V public fun add (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z + public final fun add (Laws/sdk/kotlin/hll/codegen/model/TypeRef;)Z public synthetic fun add (Ljava/lang/Object;)Z public fun addAll (Ljava/util/Collection;)Z public fun clear ()V @@ -176,8 +177,6 @@ public final class aws/sdk/kotlin/hll/codegen/model/Types { public final fun getItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getItemSchema ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getKeySpec ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getKeySpecNumber ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getKeySpecString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getMapperContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getOperation ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getPartitionKey ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt index 8e77f92d1ea..db7c910a0b8 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt @@ -187,8 +187,6 @@ class CodeGeneratorImpl( override fun persist() { val content = buildString { - appendLine("// Code generated by dynamodb-mapper-ops-codegen. DO NOT EDIT!") - appendLine() appendLine("package $pkg") appendLine() imports.formatted.takeIf { it.isNotBlank() }?.let { appendLine(it) } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt index cfc0e96b76b..8d189677464 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt @@ -23,6 +23,8 @@ class ImportDirectives : MutableSet by mutableSetOf() { get() = buildString { sortedWith(importComparator).forEach { appendLine(it.formatted) } } + + public fun add(type: TypeRef) = add(ImportDirective(type)) } private val specialPrefixes = setOf( diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index e5356e374b4..143fdd35a4a 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -135,8 +135,6 @@ object Types { val toItem = TypeRef(Pkg.Hl.Model, "toItem") val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") - val KeySpecNumber = TypeRef(Pkg.Hl.Items, "KeySpec.Number") - val KeySpecString = TypeRef(Pkg.Hl.Items, "KeySpec.String") val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") val PartitionKey = TypeRef(Pkg.Hl.Items, "PartitionKey") val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt index 395ed4ca8e6..e5924b7db0b 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt @@ -8,17 +8,18 @@ import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbItem import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey +import aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering.HighLevelRenderer import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.isAnnotationPresent import com.google.devtools.ksp.processing.* import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.validate +import java.awt.image.renderable.RenderContext private val annotationName = DynamoDbItem::class.qualifiedName!! public class MapperProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor { - private var invoked = false private val logger = environment.logger private val codeGenerator = environment.codeGenerator @@ -33,143 +34,144 @@ public class MapperProcessor(private val environment: SymbolProcessorEnvironment val invalid = annotated.filterNot { it.validate() }.toList() logger.info("Found invalid classes $invalid") - annotated + val annotations = annotated .toList() .also { logger.info("Found annotated classes: $it") } .filterIsInstance() .filter { it.validate() } -// .associateWith { } + + HighLevelRenderer(annotations, logger, codeGeneratorFactory).render() return invalid } - private inner class ClassVisitor : KSVisitorVoid() { - override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) { - val basePackageName = classDeclaration.packageName.asString() - val packageName = "$basePackageName.mapper.schemas" - - val className = classDeclaration.qualifiedName!!.getShortName() - val builderName = "${className}Builder" - val converterName = "${className}Converter" - val schemaName = "${className}Schema" - - val props = classDeclaration.getAllProperties().mapNotNull(Property.Companion::from) - val keyProp = checkNotNull(props.singleOrNull { it.isPk }) { - "Expected exactly one @DynamoDbPartitionKey annotation on a property" - } - - env.codeGenerator.createNewFile( - ).use { file -> - file.bufferedWriter().use { writer -> - writer.append( - """ - |package $packageName - | - |import aws.sdk.kotlin.hll.dynamodbmapper.* - |import aws.sdk.kotlin.hll.dynamodbmapper.items.* - |import aws.sdk.kotlin.hll.dynamodbmapper.model.* - |import aws.sdk.kotlin.hll.dynamodbmapper.values.* - |import $basePackageName.$className - | - |public class $builderName { - ${generateProperties(props)} - | ${generateBuildMethod(className, props)} - |} - | - |public object $converterName : ItemConverter<$className> by SimpleItemConverter( - | builderFactory = ::$builderName, - | build = $builderName::build, - | descriptors = arrayOf( - ${generateDescriptors(className, builderName, props)} - | ), - |) - | - |public object $schemaName : ItemSchema.PartitionKey<$className, ${keyProp.typeName.getShortName()}> { - | override val converter: $converterName = $converterName - | override val partitionKey: KeySpec<${keyProp.keySpecType}> = ${generateKeySpec(keyProp)} - |} - | - |public fun DynamoDbMapper.get${className}Table(name: String): Table.PartitionKey<$className, ${keyProp.typeName.getShortName()}> = getTable(name, $schemaName) - | - """.trimMargin(), - ) - } - } - } - - private fun generateBuildMethod(className: String, props: Sequence) = - buildString { - appendLine("public fun build(): $className {") - - props.forEach { prop -> - appendLine(""" val ${prop.name} = requireNotNull(${prop.name}) { "Missing value for $className.${prop.name}" }""") - } - - appendLine() - - append(" return $className(") - append(props.joinToString(", ") { it.name }) - appendLine(")") - - appendLine(" }") - }.trimEnd() - - private fun generateDescriptors( - className: String, - builderName: String, - props: Sequence, - ) = buildString { - props.forEach { prop -> - val converterType = when (val fqTypeName = prop.typeName.asString()) { - "aws.smithy.kotlin.runtime.time.Instant" -> "InstantConverter.Default" - "kotlin.Boolean" -> "BooleanConverter" - "kotlin.Int" -> "IntConverter" - "kotlin.String" -> "StringConverter" - else -> error("Unsupported attribute type $fqTypeName") - } - - append("| AttributeDescriptor(") - - // key - append("\"") - append(prop.ddbName) - append("\", ") - - // getter - append(className) - append("::") - append(prop.name) - append(", ") - - // setter - append(builderName) - append("::") - append(prop.name) - append("::set, ") - - // converter - append(converterType) - - appendLine("),") - } - }.trimEnd() - - private fun generateKeySpec(keyProp: Property) = buildString { - append("KeySpec.") - append(keyProp.keySpecType) - append("(\"") - append(keyProp.name) - append("\")") - } - - private fun generateProperties(props: Sequence) = buildString { - props.forEach { prop -> - append("| public var ") - append(prop.name) - append(": ") - append(prop.typeName.asString()) - appendLine("? = null") - } - } - } +// private inner class ClassVisitor : KSVisitorVoid() { +// override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) { +// val basePackageName = classDeclaration.packageName.asString() +// val packageName = "$basePackageName.mapper.schemas" +// +// val className = classDeclaration.qualifiedName!!.getShortName() +// val builderName = "${className}Builder" +// val converterName = "${className}Converter" +// val schemaName = "${className}Schema" +// +// val props = classDeclaration.getAllProperties().mapNotNull(Property.Companion::from) +// val keyProp = checkNotNull(props.singleOrNull { it.isPk }) { +// "Expected exactly one @DynamoDbPartitionKey annotation on a property" +// } +// +// env.codeGenerator.createNewFile( +// ).use { file -> +// file.bufferedWriter().use { writer -> +// writer.append( +// """ +// |package $packageName +// | +// |import aws.sdk.kotlin.hll.dynamodbmapper.* +// |import aws.sdk.kotlin.hll.dynamodbmapper.items.* +// |import aws.sdk.kotlin.hll.dynamodbmapper.model.* +// |import aws.sdk.kotlin.hll.dynamodbmapper.values.* +// |import $basePackageName.$className +// | +// |public class $builderName { +// ${generateProperties(props)} +// | ${generateBuildMethod(className, props)} +// |} +// | +// |public object $converterName : ItemConverter<$className> by SimpleItemConverter( +// | builderFactory = ::$builderName, +// | build = $builderName::build, +// | descriptors = arrayOf( +// ${generateDescriptors(className, builderName, props)} +// | ), +// |) +// | +// |public object $schemaName : ItemSchema.PartitionKey<$className, ${keyProp.typeName.getShortName()}> { +// | override val converter: $converterName = $converterName +// | override val partitionKey: KeySpec<${keyProp.keySpecType}> = ${generateKeySpec(keyProp)} +// |} +// | +// |public fun DynamoDbMapper.get${className}Table(name: String): Table.PartitionKey<$className, ${keyProp.typeName.getShortName()}> = getTable(name, $schemaName) +// | +// """.trimMargin(), +// ) +// } +// } +// } +// +// private fun generateBuildMethod(className: String, props: Sequence) = +// buildString { +// appendLine("public fun build(): $className {") +// +// props.forEach { prop -> +// appendLine(""" val ${prop.name} = requireNotNull(${prop.name}) { "Missing value for $className.${prop.name}" }""") +// } +// +// appendLine() +// +// append(" return $className(") +// append(props.joinToString(", ") { it.name }) +// appendLine(")") +// +// appendLine(" }") +// }.trimEnd() +// +// private fun generateDescriptors( +// className: String, +// builderName: String, +// props: Sequence, +// ) = buildString { +// props.forEach { prop -> +// val converterType = when (val fqTypeName = prop.typeName.asString()) { +// "aws.smithy.kotlin.runtime.time.Instant" -> "InstantConverter.Default" +// "kotlin.Boolean" -> "BooleanConverter" +// "kotlin.Int" -> "IntConverter" +// "kotlin.String" -> "StringConverter" +// else -> error("Unsupported attribute type $fqTypeName") +// } +// +// append("| AttributeDescriptor(") +// +// // key +// append("\"") +// append(prop.ddbName) +// append("\", ") +// +// // getter +// append(className) +// append("::") +// append(prop.name) +// append(", ") +// +// // setter +// append(builderName) +// append("::") +// append(prop.name) +// append("::set, ") +// +// // converter +// append(converterType) +// +// appendLine("),") +// } +// }.trimEnd() +// +// private fun generateKeySpec(keyProp: Property) = buildString { +// append("KeySpec.") +// append(keyProp.keySpecType) +// append("(\"") +// append(keyProp.name) +// append("\")") +// } +// +// private fun generateProperties(props: Sequence) = buildString { +// props.forEach { prop -> +// append("| public var ") +// append(prop.name) +// append(": ") +// append(prop.typeName.asString()) +// appendLine("? = null") +// } +// } +// } } \ No newline at end of file diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt index 311f81405c9..263d0a56bd2 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt @@ -6,11 +6,9 @@ package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type -import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase -import aws.sdk.kotlin.hll.codegen.util.Pkg import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey import com.google.devtools.ksp.KspExperimental @@ -35,18 +33,7 @@ public class AnnotationRenderer( } override fun generate() { - val basePackageName = classDeclaration.packageName.asString() - - write("package #L", "$basePackageName.mapper.schemas") - blankLine() - // TODO replace with import directives - write("import aws.sdk.kotlin.hll.dynamodbmapper.*") - write("import aws.sdk.kotlin.hll.dynamodbmapper.items.*") - write("import aws.sdk.kotlin.hll.dynamodbmapper.model.*") - write("import aws.sdk.kotlin.hll.dynamodbmapper.values.*") - write("import $basePackageName.$className") - blankLine() - + imports.add(ImportDirective(classDeclaration.qualifiedName!!.asString())) // Import the class that's getting processed renderBuilder() renderItemConverter() renderSchema() @@ -56,37 +43,44 @@ public class AnnotationRenderer( private fun renderBuilder() { checkNotNull(properties.singleOrNull { it.isPk }) { "Expected exactly one @DynamoDbPartitionKey annotation on a property" } + withDocs { + write("A DSL-style builder for instances of [#L]", className) + } + withBlock("public class #L {", "}", builderName) { properties.forEach { - write("public var #L: #T? = null", it.name, it.typeName.asString()) + write("public var #L: #L? = null", it.name, it.typeName.asString().removePrefix("kotlin.")) } + blankLine() - withBlock("public fun build(): #T {", "}", className) { + withBlock("public fun build(): #L {", "}", className) { properties.forEach { - write("val #1L = requireNotNull(#1L) { #S }", it.name, "Missing value for $className.${it.name}") + write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for $className.${it.name}") } blankLine() - withBlock("return $className(", ")") { - properties.joinToString(", ") { it.name } + withBlock("return #L(", ")", className) { + write("#L", properties.joinToString(", ") { it.name }) } } } + blankLine() } private fun renderItemConverter() { - withBlock("public object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { - write("builderFactory = ::#L", builderName) - write("build = #L::build", builderName) - withBlock("descriptors = #L(", ")", Types.arrayOf) { + withBlock("internal object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { + write("builderFactory = ::#L,", builderName) + write("build = #L::build,", builderName) + withBlock("descriptors = arrayOf(", "),") { properties.forEach { renderAttributeDescriptor(it) } } } + blankLine() } private fun renderAttributeDescriptor(prop: Property) { - withBlock("#T(", ")", Types.AttributeDescriptor) { + withBlock("#T(", "),", Types.AttributeDescriptor) { write("#S,", prop.ddbName) // key write("#L,", "${className}::${prop.name}") // getter write("#L,", "${builderName}::${prop.name}::set") // setter @@ -104,22 +98,32 @@ public class AnnotationRenderer( } private fun renderSchema() { - withBlock("public object #L : #T.#T<#L, #L> {", "}", schemaName, Types.ItemSchema, Types.PartitionKey, className, keyProperty.typeName.getShortName()) { + withBlock("internal object #L : #T.#L<#L, #L> {", "}", schemaName, Types.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { write("override val converter : #1L = #1L", converterName) - write("override val partitionKey: #T<#2L> = #2L(#S)", Types.KeySpec, keyProperty.keySpec, keyProperty.name) + write("override val partitionKey: #1T<#2L> = #1T.#2L(#3S)", Types.KeySpec, keyProperty.keySpec, keyProperty.name) } + blankLine() } - private val Property.keySpec: Type + private val Property.keySpec: String get() = when (typeName.asString()) { - "kotlin.Int" -> Types.KeySpecNumber - "kotlin.String" -> Types.KeySpecString + "kotlin.Int" -> "Number" + "kotlin.String" -> "String" else -> error("Unsupported key type ${typeName.asString()}, expected Int or String") } private fun renderGetTable() { - write("public fun #T.get#2LTable(name: #T): #L.#L<#2L, #L> = #L(name, #L)", - Types.DynamoDbMapper, className, Types.String, Types.Table, Types.PartitionKey, keyProperty.typeName.getShortName(), Types.getTable, schemaName + withDocs { + write("Returns a reference to a table named [name] containing items representing [#L]", className) + } + write("public fun #1T.get#2LTable(name: String): #3T.#4L<#2L, #5L> = #6L(name, #7L)", + Types.DynamoDbMapper, + className, + Types.Table, + "PartitionKey", + keyProperty.typeName.getShortName(), + "getTable", + schemaName ) } } @@ -141,5 +145,3 @@ private data class Property(val name: String, val ddbName: String, val typeName: } } } - - diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt index bf95bed3c96..0cbd61a8a5f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt @@ -4,7 +4,9 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering +import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import com.google.devtools.ksp.processing.KSPLogger import com.google.devtools.ksp.symbol.KSClassDeclaration /** @@ -12,12 +14,14 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration * @param annotations A list of annotated classes */ public class HighLevelRenderer( - private val ctx: RenderContext, - private val annotations: List + private val annotations: List, + private val logger: KSPLogger, + private val codegenFactory: CodeGeneratorFactory ) { public fun render() { annotations.forEach { - val renderCtx = RenderContext(ctx.logger, ctx.codegenFactory, "${it.packageName.asString()}.mapper.schemas") + logger.info("Processing annotation on ${it.simpleName}") + val renderCtx = RenderContext(logger, codegenFactory, "${it.packageName.asString()}.mapper.schemas") val annotation = AnnotationRenderer(it, renderCtx) annotation.render() } From 73514a520d5bc58ce1e42b8102c1294dd6715ae9 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 11:06:05 -0400 Subject: [PATCH 09/59] Small style changes --- .../processor/rendering/AnnotationRenderer.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt index 263d0a56bd2..b7d5cdeb58d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt @@ -55,11 +55,13 @@ public class AnnotationRenderer( withBlock("public fun build(): #L {", "}", className) { properties.forEach { - write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for $className.${it.name}") + write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") } blankLine() withBlock("return #L(", ")", className) { - write("#L", properties.joinToString(", ") { it.name }) + properties.forEach { + write("#L,", it.name) + } } } } From ba04d3e1ecdd8d7e535da98e3498e0b44e315d78 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 11:23:06 -0400 Subject: [PATCH 10/59] ktlint --- .../hll/codegen/core/TemplateEngineTest.kt | 2 +- .../hll/codegen/core/TemplateProcessorTest.kt | 2 +- .../sdk/kotlin/hll/codegen/util/StringsTest.kt | 2 +- .../processor/MapperProcessor.kt | 12 ++++-------- .../processor/rendering/AnnotationRenderer.kt | 11 ++++++----- .../processor/rendering/HighLevelRenderer.kt | 2 +- .../codegen/HighLevelOpsProcessor.kt | 2 +- .../dynamodbmapper/codegen/model/Structure.kt | 2 +- .../codegen/rendering/HighLevelRenderer.kt | 4 ++-- .../codegen/rendering/OperationRenderer.kt | 2 +- .../rendering/OperationsTypeRenderer.kt | 2 +- .../tests/processor/data/UserTest.kt | 18 +++++++++--------- 12 files changed, 29 insertions(+), 32 deletions(-) diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt index c585b81d70f..c853b989f7f 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt @@ -53,4 +53,4 @@ class TemplateEngineTest { test("n/a", "This should fail: #L #L #1L #L", "a", "b", "c") } } -} \ No newline at end of file +} diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt index 1e94fd0c254..ffc793866f7 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt @@ -58,4 +58,4 @@ class TemplateProcessorTest { assertContains(imports, ImportDirective(elderberry)) assertContains(imports, ImportDirective(fig)) } -} \ No newline at end of file +} diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt index 571dd32882d..c2f85036c6d 100644 --- a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt +++ b/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt @@ -23,4 +23,4 @@ class StringsTest { fun testQuote() { assertEquals("\"This \\t is a \\\"test\\\"!\"", "This \t is a \"test\"!".quote()) } -} \ No newline at end of file +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt index e5924b7db0b..33af2d3c143 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt @@ -5,17 +5,11 @@ package aws.sdk.kotlin.hll.dynamodbmapper.processor import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory -import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbItem -import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey import aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering.HighLevelRenderer -import com.google.devtools.ksp.KspExperimental -import com.google.devtools.ksp.getAnnotationsByType -import com.google.devtools.ksp.isAnnotationPresent import com.google.devtools.ksp.processing.* import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.validate -import java.awt.image.renderable.RenderContext private val annotationName = DynamoDbItem::class.qualifiedName!! @@ -26,7 +20,9 @@ public class MapperProcessor(private val environment: SymbolProcessorEnvironment private val codeGeneratorFactory = CodeGeneratorFactory(codeGenerator, logger) override fun process(resolver: Resolver): List { - if (invoked) { return listOf() } + if (invoked) { + return listOf() + } invoked = true logger.info("Searching for symbols annotated with $annotationName") @@ -174,4 +170,4 @@ public class MapperProcessor(private val environment: SymbolProcessorEnvironment // } // } // } -} \ No newline at end of file +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt index b7d5cdeb58d..ca9949a861f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt @@ -20,7 +20,7 @@ import com.google.devtools.ksp.symbol.KSPropertyDeclaration public class AnnotationRenderer( private val classDeclaration: KSClassDeclaration, - private val ctx: RenderContext + private val ctx: RenderContext, ) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema") { private val className = classDeclaration.qualifiedName!!.getShortName() private val builderName = "${className}Builder" @@ -84,8 +84,8 @@ public class AnnotationRenderer( private fun renderAttributeDescriptor(prop: Property) { withBlock("#T(", "),", Types.AttributeDescriptor) { write("#S,", prop.ddbName) // key - write("#L,", "${className}::${prop.name}") // getter - write("#L,", "${builderName}::${prop.name}::set") // setter + write("#L,", "$className::${prop.name}") // getter + write("#L,", "$builderName::${prop.name}::set") // setter write("#T", prop.valueConverter) // converter } } @@ -118,14 +118,15 @@ public class AnnotationRenderer( withDocs { write("Returns a reference to a table named [name] containing items representing [#L]", className) } - write("public fun #1T.get#2LTable(name: String): #3T.#4L<#2L, #5L> = #6L(name, #7L)", + write( + "public fun #1T.get#2LTable(name: String): #3T.#4L<#2L, #5L> = #6L(name, #7L)", Types.DynamoDbMapper, className, Types.Table, "PartitionKey", keyProperty.typeName.getShortName(), "getTable", - schemaName + schemaName, ) } } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt index 0cbd61a8a5f..71bc996b5bb 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt @@ -16,7 +16,7 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration public class HighLevelRenderer( private val annotations: List, private val logger: KSPLogger, - private val codegenFactory: CodeGeneratorFactory + private val codegenFactory: CodeGeneratorFactory, ) { public fun render() { annotations.forEach { diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt index 2c7b086540f..1b6ecab5fc7 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt @@ -6,10 +6,10 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import aws.sdk.kotlin.hll.codegen.util.Pkg import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.toHighLevel import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.HighLevelRenderer -import aws.sdk.kotlin.hll.codegen.util.Pkg import aws.sdk.kotlin.services.dynamodb.DynamoDbClient import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.getDeclaredFunctions diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt index 7d029bbb406..ce12b10cf0d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt @@ -4,8 +4,8 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model -import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.util.plus import aws.smithy.kotlin.runtime.collections.Attributes diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt index 5eb1b511ce7..82958a7cc5b 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt @@ -4,10 +4,10 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.ItemSourceKind -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.rendering.RenderContext +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.ItemSourceKind +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.itemSourceKinds /** diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt index 6cd785638d4..6fc90dfd21e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt @@ -4,12 +4,12 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.DataTypeGenerator import aws.sdk.kotlin.hll.codegen.core.* import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.DataTypeGenerator import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt index e60a81d8755..55ba9f0279b 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt @@ -9,8 +9,8 @@ import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* import aws.sdk.kotlin.hll.codegen.util.lowercaseFirstChar +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* /** * Renders the `*Operations` interface and `*OperationsImpl` class which contain a method for each codegenned diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt index 0edb63a637e..1f4dbc6f847 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt @@ -1,16 +1,16 @@ -///* +// /* // * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // * SPDX-License-Identifier: Apache-2.0 // */ -//package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data +// package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data // -//import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf -//import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter -//import aws.sdk.kotlin.services.dynamodb.model.AttributeValue -//import kotlin.test.Test -//import kotlin.test.assertEquals +// import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf +// import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter +// import aws.sdk.kotlin.services.dynamodb.model.AttributeValue +// import kotlin.test.Test +// import kotlin.test.assertEquals // -//class UserTest { +// class UserTest { // @Test // fun testConversion() { // val user = User(123, "Steve", "Rogers", 84) @@ -30,4 +30,4 @@ // // assertEquals(user, unconverted) // } -//} +// } From dbd737ec02982d958da26d763a07d7a8795c7a7e Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 11:27:01 -0400 Subject: [PATCH 11/59] ktlint --- .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 1 + .../tests/processor/data/UserTest.kt | 66 +++++++++---------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 143fdd35a4a..7e03b1ef3a9 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -116,6 +116,7 @@ object Types { * Creates a [TypeRef] for a generic [Map] with [String] keys * @param value The type of values in the map */ + @Suppress("ktlint:standard:function-naming") fun StringMap(value: Type) = map(String, value) // Low-level types diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt index 1f4dbc6f847..b040a83bc80 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt @@ -1,33 +1,33 @@ -// /* -// * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// * SPDX-License-Identifier: Apache-2.0 -// */ -// package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data -// -// import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf -// import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter -// import aws.sdk.kotlin.services.dynamodb.model.AttributeValue -// import kotlin.test.Test -// import kotlin.test.assertEquals -// -// class UserTest { -// @Test -// fun testConversion() { -// val user = User(123, "Steve", "Rogers", 84) -// val converted = UserConverter.toItem(user) -// -// assertEquals( -// itemOf( -// "id" to AttributeValue.N("123"), -// "fName" to AttributeValue.S("Steve"), -// "lName" to AttributeValue.S("Rogers"), -// "age" to AttributeValue.N("84"), -// ), -// converted, -// ) -// -// val unconverted = UserConverter.fromItem(converted) -// -// assertEquals(user, unconverted) -// } -// } + /* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data + + import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf + import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter + import aws.sdk.kotlin.services.dynamodb.model.AttributeValue + import kotlin.test.Test + import kotlin.test.assertEquals + + class UserTest { + @Test + fun testConversion() { + val user = User(123, "Steve", "Rogers", 84) + val converted = UserConverter.toItem(user) + + assertEquals( + itemOf( + "id" to AttributeValue.N("123"), + "fName" to AttributeValue.S("Steve"), + "lName" to AttributeValue.S("Rogers"), + "age" to AttributeValue.N("84"), + ), + converted, + ) + + val unconverted = UserConverter.fromItem(converted) + + assertEquals(user, unconverted) + } + } From 1da4704e16690684476ad6420bd93933df21b90c Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 11:27:13 -0400 Subject: [PATCH 12/59] ktlint --- .../tests/processor/data/UserTest.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt index b040a83bc80..0f2cbe70fdf 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt @@ -1,16 +1,16 @@ - /* +/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ - package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data +package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data - import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf - import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter - import aws.sdk.kotlin.services.dynamodb.model.AttributeValue - import kotlin.test.Test - import kotlin.test.assertEquals +import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf +import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter +import aws.sdk.kotlin.services.dynamodb.model.AttributeValue +import kotlin.test.Test +import kotlin.test.assertEquals - class UserTest { +class UserTest { @Test fun testConversion() { val user = User(123, "Steve", "Rogers", 84) @@ -30,4 +30,4 @@ assertEquals(user, unconverted) } - } +} From 48455a948f3132966e102c1b8a3e6589d626f9ce Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 12:02:31 -0400 Subject: [PATCH 13/59] Remove unused types --- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 7e03b1ef3a9..e3c126a5290 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -108,7 +108,6 @@ public fun Type.nullable() = when { */ object Types { // Kotlin standard types - val arrayOf = TypeRef("kotlin", "arrayOf") val String = TypeRef("kotlin", "String") val StringNullable = String.nullable() @@ -125,7 +124,6 @@ object Types { // High-level types val DynamoDbMapper = TypeRef(Pkg.Hl.Base, "DynamoDbMapper") - val getTable = TypeRef(Pkg.Hl.Base, "getTable") val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) @@ -137,7 +135,6 @@ object Types { val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") - val PartitionKey = TypeRef(Pkg.Hl.Items, "PartitionKey") val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") From 77f0792bad603275601e79d658600c5108ec7378 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 12:03:28 -0400 Subject: [PATCH 14/59] StringMap -> stringMap --- .../kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 3 +-- .../codegen/model/MemberCodegenBehavior.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index e3c126a5290..08bcfa9f6d1 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -115,8 +115,7 @@ object Types { * Creates a [TypeRef] for a generic [Map] with [String] keys * @param value The type of values in the map */ - @Suppress("ktlint:standard:function-naming") - fun StringMap(value: Type) = map(String, value) + fun stringMap(value: Type) = map(String, value) // Low-level types val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt index cf9ae4af01a..172f4b6c808 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt @@ -88,23 +88,23 @@ private fun llType(name: String) = TypeRef(Pkg.Ll.Model, name) private val unsupportedMembers = listOf( // superseded by ConditionExpression Member("conditionalOperator", llType("ConditionalOperator")), - Member("expected", Types.StringMap(llType("ExpectedAttributeValue"))), + Member("expected", Types.stringMap(llType("ExpectedAttributeValue"))), // superseded by FilterExpression - Member("queryFilter", Types.StringMap(llType("Condition"))), - Member("scanFilter", Types.StringMap(llType("Condition"))), + Member("queryFilter", Types.stringMap(llType("Condition"))), + Member("scanFilter", Types.stringMap(llType("Condition"))), // superseded by KeyConditionExpression - Member("keyConditions", Types.StringMap(llType("Condition"))), + Member("keyConditions", Types.stringMap(llType("Condition"))), // superseded by ProjectionExpression Member("attributesToGet", Type.list(Types.String)), // superseded by UpdateExpression - Member("attributeUpdates", Types.StringMap(llType("AttributeValueUpdate"))), + Member("attributeUpdates", Types.stringMap(llType("AttributeValueUpdate"))), // TODO add support for expressions - Member("expressionAttributeNames", Types.StringMap(Types.String)), + Member("expressionAttributeNames", Types.stringMap(Types.String)), Member("expressionAttributeValues", Types.AttributeMap), Member("conditionExpression", Types.String), Member("projectionExpression", Types.String), From 725a3918f1e8a7edb741549da8ed39d9a2aab537 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 12:05:08 -0400 Subject: [PATCH 15/59] Remove old-form codegen --- .../processor/MapperProcessor.kt | 130 ------------------ 1 file changed, 130 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt index 33af2d3c143..1e96e5c1ada 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt @@ -40,134 +40,4 @@ public class MapperProcessor(private val environment: SymbolProcessorEnvironment return invalid } - -// private inner class ClassVisitor : KSVisitorVoid() { -// override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) { -// val basePackageName = classDeclaration.packageName.asString() -// val packageName = "$basePackageName.mapper.schemas" -// -// val className = classDeclaration.qualifiedName!!.getShortName() -// val builderName = "${className}Builder" -// val converterName = "${className}Converter" -// val schemaName = "${className}Schema" -// -// val props = classDeclaration.getAllProperties().mapNotNull(Property.Companion::from) -// val keyProp = checkNotNull(props.singleOrNull { it.isPk }) { -// "Expected exactly one @DynamoDbPartitionKey annotation on a property" -// } -// -// env.codeGenerator.createNewFile( -// ).use { file -> -// file.bufferedWriter().use { writer -> -// writer.append( -// """ -// |package $packageName -// | -// |import aws.sdk.kotlin.hll.dynamodbmapper.* -// |import aws.sdk.kotlin.hll.dynamodbmapper.items.* -// |import aws.sdk.kotlin.hll.dynamodbmapper.model.* -// |import aws.sdk.kotlin.hll.dynamodbmapper.values.* -// |import $basePackageName.$className -// | -// |public class $builderName { -// ${generateProperties(props)} -// | ${generateBuildMethod(className, props)} -// |} -// | -// |public object $converterName : ItemConverter<$className> by SimpleItemConverter( -// | builderFactory = ::$builderName, -// | build = $builderName::build, -// | descriptors = arrayOf( -// ${generateDescriptors(className, builderName, props)} -// | ), -// |) -// | -// |public object $schemaName : ItemSchema.PartitionKey<$className, ${keyProp.typeName.getShortName()}> { -// | override val converter: $converterName = $converterName -// | override val partitionKey: KeySpec<${keyProp.keySpecType}> = ${generateKeySpec(keyProp)} -// |} -// | -// |public fun DynamoDbMapper.get${className}Table(name: String): Table.PartitionKey<$className, ${keyProp.typeName.getShortName()}> = getTable(name, $schemaName) -// | -// """.trimMargin(), -// ) -// } -// } -// } -// -// private fun generateBuildMethod(className: String, props: Sequence) = -// buildString { -// appendLine("public fun build(): $className {") -// -// props.forEach { prop -> -// appendLine(""" val ${prop.name} = requireNotNull(${prop.name}) { "Missing value for $className.${prop.name}" }""") -// } -// -// appendLine() -// -// append(" return $className(") -// append(props.joinToString(", ") { it.name }) -// appendLine(")") -// -// appendLine(" }") -// }.trimEnd() -// -// private fun generateDescriptors( -// className: String, -// builderName: String, -// props: Sequence, -// ) = buildString { -// props.forEach { prop -> -// val converterType = when (val fqTypeName = prop.typeName.asString()) { -// "aws.smithy.kotlin.runtime.time.Instant" -> "InstantConverter.Default" -// "kotlin.Boolean" -> "BooleanConverter" -// "kotlin.Int" -> "IntConverter" -// "kotlin.String" -> "StringConverter" -// else -> error("Unsupported attribute type $fqTypeName") -// } -// -// append("| AttributeDescriptor(") -// -// // key -// append("\"") -// append(prop.ddbName) -// append("\", ") -// -// // getter -// append(className) -// append("::") -// append(prop.name) -// append(", ") -// -// // setter -// append(builderName) -// append("::") -// append(prop.name) -// append("::set, ") -// -// // converter -// append(converterType) -// -// appendLine("),") -// } -// }.trimEnd() -// -// private fun generateKeySpec(keyProp: Property) = buildString { -// append("KeySpec.") -// append(keyProp.keySpecType) -// append("(\"") -// append(keyProp.name) -// append("\")") -// } -// -// private fun generateProperties(props: Sequence) = buildString { -// props.forEach { prop -> -// append("| public var ") -// append(prop.name) -// append(": ") -// append(prop.typeName.asString()) -// appendLine("? = null") -// } -// } -// } } From 77c326463a626fcb7b42e0f45a1e5f4c16f012d2 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 12:09:09 -0400 Subject: [PATCH 16/59] cleanup --- .../processor/rendering/AnnotationRenderer.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt index ca9949a861f..dc9f3064ae6 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt @@ -18,6 +18,11 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSName import com.google.devtools.ksp.symbol.KSPropertyDeclaration +/** + * Renders the classes and objects required to make a class usable with the DynamoDbMapper such as schemas, builders, and converters. + * @param classDeclaration the [KSClassDeclaration] of the class + * @param ctx the [RenderContext] of the renderer + */ public class AnnotationRenderer( private val classDeclaration: KSClassDeclaration, private val ctx: RenderContext, @@ -33,7 +38,7 @@ public class AnnotationRenderer( } override fun generate() { - imports.add(ImportDirective(classDeclaration.qualifiedName!!.asString())) // Import the class that's getting processed + imports.add(ImportDirective(classDeclaration.qualifiedName!!.asString())) renderBuilder() renderItemConverter() renderSchema() @@ -49,7 +54,7 @@ public class AnnotationRenderer( withBlock("public class #L {", "}", builderName) { properties.forEach { - write("public var #L: #L? = null", it.name, it.typeName.asString().removePrefix("kotlin.")) + write("public var #L: #L? = null", it.name, it.typeName.asString()) } blankLine() From a0134e070c12793450031a84518b320a32b61da0 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 12:10:01 -0400 Subject: [PATCH 17/59] KDocs --- .../kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt index 8d189677464..a2b42658d9f 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt @@ -24,6 +24,9 @@ class ImportDirectives : MutableSet by mutableSetOf() { sortedWith(importComparator).forEach { appendLine(it.formatted) } } + /** + * Add a [type] to this set of [ImportDirectives] + */ public fun add(type: TypeRef) = add(ImportDirective(type)) } From 165e59b6f6a509f5608d71683b7ade607b2f3134 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 12:27:49 -0400 Subject: [PATCH 18/59] apiDump --- hll/codegen/api/codegen.api | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 861fb515cd2..97a12c0e07b 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -163,15 +163,12 @@ public final class aws/sdk/kotlin/hll/codegen/model/TypeVar : aws/sdk/kotlin/hll public final class aws/sdk/kotlin/hll/codegen/model/Types { public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types; - public final fun StringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getArrayOf ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getAttributeDescriptor ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getAttributeMap ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getAttributeValue ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getBooleanConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getDefaultInstantConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getDynamoDbMapper ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getGetTable ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getHReqContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getIntConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; @@ -179,7 +176,6 @@ public final class aws/sdk/kotlin/hll/codegen/model/Types { public final fun getKeySpec ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getMapperContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getOperation ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getPartitionKey ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getSimpleItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getStringConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; @@ -187,6 +183,7 @@ public final class aws/sdk/kotlin/hll/codegen/model/Types { public final fun getTable ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getToItem ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun itemSchema (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun stringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; } public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContext { From 3513113988b525d5b060b0533f3071f8f477c56c Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 17:06:54 -0400 Subject: [PATCH 19/59] Add extra metadata --- hll/build.gradle.kts | 2 ++ hll/codegen/build.gradle.kts | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/hll/build.gradle.kts b/hll/build.gradle.kts index 56d55d50ea7..504b840bba0 100644 --- a/hll/build.gradle.kts +++ b/hll/build.gradle.kts @@ -8,6 +8,8 @@ import aws.sdk.kotlin.gradle.kmp.* import org.jetbrains.kotlin.gradle.dsl.JvmTarget description = "High-level libraries for the AWS SDK for Kotlin" +extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL" +extra["moduleName"] = "aws.sdk.kotlin.hll" // FIXME 🔽🔽🔽 This is all copied from :aws-runtime and should be commonized 🔽🔽🔽 diff --git a/hll/codegen/build.gradle.kts b/hll/codegen/build.gradle.kts index 99f4139e293..78417ffe548 100644 --- a/hll/codegen/build.gradle.kts +++ b/hll/codegen/build.gradle.kts @@ -3,6 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +description = "Common code-generation utilities used by AWS SDK for Kotlin's high level libraries" +extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL :: Codegen" +extra["moduleName"] = "aws.sdk.kotlin.hll.codegen" + plugins { alias(libs.plugins.kotlin.jvm) } From e995954dd23f1ab4985147b171cb302b806fa163 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Mon, 12 Aug 2024 17:08:07 -0400 Subject: [PATCH 20/59] Remove unused function --- .../aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt index a2b42658d9f..cfc0e96b76b 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt @@ -23,11 +23,6 @@ class ImportDirectives : MutableSet by mutableSetOf() { get() = buildString { sortedWith(importComparator).forEach { appendLine(it.formatted) } } - - /** - * Add a [type] to this set of [ImportDirectives] - */ - public fun add(type: TypeRef) = add(ImportDirective(type)) } private val specialPrefixes = setOf( From a1cfc8e408a34ba1f758dbc0f2fd856b582d70c2 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 10:43:31 -0400 Subject: [PATCH 21/59] Pass around a `codeGeneratorName` --- hll/codegen/api/codegen.api | 10 +++++----- .../aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt | 3 +++ .../kotlin/hll/codegen/core/CodeGeneratorFactory.kt | 11 ++++++----- .../sdk/kotlin/hll/codegen/rendering/RendererBase.kt | 7 ++++--- .../processor/rendering/AnnotationRenderer.kt | 2 +- .../codegen/rendering/OperationRenderer.kt | 2 +- .../codegen/rendering/OperationsTypeRenderer.kt | 2 +- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 97a12c0e07b..5ad919c6b28 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -20,12 +20,12 @@ public final class aws/sdk/kotlin/hll/codegen/core/CodeGenerator$DefaultImpls { public final class aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory { public fun (Lcom/google/devtools/ksp/processing/CodeGenerator;Lcom/google/devtools/ksp/processing/KSPLogger;)V - public final fun generator (Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/CodeGenerator; + public final fun generator (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/CodeGenerator; } public final class aws/sdk/kotlin/hll/codegen/core/CodeGeneratorImpl : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;)V - public synthetic fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;Ljava/lang/String;)V + public synthetic fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun blankLine ()V public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V @@ -59,7 +59,6 @@ public final class aws/sdk/kotlin/hll/codegen/core/ImportDirective { public final class aws/sdk/kotlin/hll/codegen/core/ImportDirectives : java/util/Set, kotlin/jvm/internal/markers/KMutableSet { public fun ()V public fun add (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z - public final fun add (Laws/sdk/kotlin/hll/codegen/model/TypeRef;)Z public synthetic fun add (Ljava/lang/Object;)Z public fun addAll (Ljava/util/Collection;)Z public fun clear ()V @@ -214,7 +213,8 @@ public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContextKt { } public abstract class aws/sdk/kotlin/hll/codegen/rendering/RendererBase : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;)V + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Ljava/lang/String;)V + public synthetic fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun blankLine ()V public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt index db7c910a0b8..011bf14cf99 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt @@ -151,6 +151,7 @@ class CodeGeneratorImpl( private val engine: TemplateEngine, private val persistCallback: (String) -> Unit, override val imports: ImportDirectives = ImportDirectives(), + private val codeGeneratorName: String, ) : CodeGenerator { private val builder = StringBuilder() private var indent = "" @@ -187,6 +188,8 @@ class CodeGeneratorImpl( override fun persist() { val content = buildString { + appendLine("// Code generated by $codeGeneratorName. DO NOT EDIT!") + appendLine() appendLine("package $pkg") appendLine() imports.formatted.takeIf { it.isNotBlank() }?.let { appendLine(it) } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt index 63f6ffa25d8..6835886c2d8 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt @@ -19,11 +19,12 @@ class CodeGeneratorFactory(private val ksCodeGenerator: KSCodeGenerator, private /** * Creates a new [CodeGenerator] backed by a [KSCodeGenerator]. The returned generator starts with no imports and * uses a configured [TemplateEngine] with the default set of processors. - * @param name The name of the file which should be created _without_ parent directory or extension (which is always + * @param fileName The name of the file which should be created _without_ parent directory or extension (which is always * **.kt**) * @param pkg The Kotlin package for the generated code (e.g., `aws.sdk.kotlin.hll.dynamodbmapper.operations`) + * @param codeGeneratorName The name of this [CodeGenerator] */ - fun generator(name: String, pkg: String): CodeGenerator { + fun generator(fileName: String, pkg: String, codeGeneratorName: String): CodeGenerator { val imports = ImportDirectives() val processors = listOf( TemplateProcessor.Literal, @@ -33,15 +34,15 @@ class CodeGeneratorFactory(private val ksCodeGenerator: KSCodeGenerator, private val engine = TemplateEngine(processors) val persistCallback: (String) -> Unit = { content -> - logger.info("Checking out code generator for class $pkg.$name") + logger.info("Checking out code generator for class $pkg.$fileName") ksCodeGenerator - .createNewFile(dependencies, pkg, name) // FIXME don't depend on ALL_FILES + .createNewFile(dependencies, pkg, fileName) // FIXME don't depend on ALL_FILES .use { outputStream -> outputStream.writer().use { writer -> writer.append(content) } } } - return CodeGeneratorImpl(pkg, engine, persistCallback, imports) + return CodeGeneratorImpl(pkg, engine, persistCallback, imports, codeGeneratorName) } } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt index 2cf9760c694..1052551b92f 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt @@ -9,13 +9,14 @@ import aws.sdk.kotlin.hll.codegen.core.CodeGenerator /** * The parent class for renderers backed by a [CodeGenerator] * @param ctx The active [RenderContext] - * @param name The name of the file which should be created _without_ parent directory or extension (which is always + * @param fileName The name of the file which should be created _without_ parent directory or extension (which is always * **.kt**) */ abstract class RendererBase( ctx: RenderContext, - name: String, -) : CodeGenerator by ctx.codegenFactory.generator(name, ctx.pkg) { + fileName: String, + rendererName: String = "aws-sdk-kotlin-hll-codegen", +) : CodeGenerator by ctx.codegenFactory.generator(fileName, ctx.pkg, rendererName) { /** * Run this renderer by calling the `abstract` [generate] method and then [persist] */ diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt index dc9f3064ae6..34fcd64056d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt @@ -26,7 +26,7 @@ import com.google.devtools.ksp.symbol.KSPropertyDeclaration public class AnnotationRenderer( private val classDeclaration: KSClassDeclaration, private val ctx: RenderContext, -) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema") { +) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema", "dynamodb-mapper-annotation-processor") { private val className = classDeclaration.qualifiedName!!.getShortName() private val builderName = "${className}Builder" private val converterName = "${className}Converter" diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt index 6fc90dfd21e..3de44c639a6 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt @@ -23,7 +23,7 @@ import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* class OperationRenderer( private val ctx: RenderContext, val operation: Operation, -) : RendererBase(ctx, operation.name) { +) : RendererBase(ctx, operation.name, "dynamodb-mapper-ops-codegen") { val members = operation.request.lowLevel.members.groupBy { m -> m.codegenBehavior.also { ctx.info(" ${m.name} → $it") } } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt index 55ba9f0279b..46ec1a0ab46 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt @@ -27,7 +27,7 @@ class OperationsTypeRenderer( val itemSourceKind: ItemSourceKind, val parentType: Type?, val operations: List, -) : RendererBase(ctx, "${itemSourceKind.name}Operations") { +) : RendererBase(ctx, "${itemSourceKind.name}Operations", "dynamodb-mapper-ops-codegen") { private val entityName = itemSourceKind.name.lowercaseFirstChar private val intfName = "${itemSourceKind.name}Operations" From f5cdd9a4c2b9b4146b27d588f1434d4c688c56ba Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 10:47:27 -0400 Subject: [PATCH 22/59] annotations -> annotatedClasses --- .../kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt | 4 ++-- .../dynamodbmapper/processor/rendering/HighLevelRenderer.kt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt index 1e96e5c1ada..7aa17808072 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt @@ -30,13 +30,13 @@ public class MapperProcessor(private val environment: SymbolProcessorEnvironment val invalid = annotated.filterNot { it.validate() }.toList() logger.info("Found invalid classes $invalid") - val annotations = annotated + val annotatedClasses = annotated .toList() .also { logger.info("Found annotated classes: $it") } .filterIsInstance() .filter { it.validate() } - HighLevelRenderer(annotations, logger, codeGeneratorFactory).render() + HighLevelRenderer(annotatedClasses, logger, codeGeneratorFactory).render() return invalid } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt index 71bc996b5bb..c290bc53c4f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt @@ -11,15 +11,15 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration /** * The parent renderer for all codegen from this package. This class orchestrates the various sub-renderers. - * @param annotations A list of annotated classes + * @param annotatedClasses A list of annotated classes */ public class HighLevelRenderer( - private val annotations: List, + private val annotatedClasses: List, private val logger: KSPLogger, private val codegenFactory: CodeGeneratorFactory, ) { public fun render() { - annotations.forEach { + annotatedClasses.forEach { logger.info("Processing annotation on ${it.simpleName}") val renderCtx = RenderContext(logger, codegenFactory, "${it.packageName.asString()}.mapper.schemas") val annotation = AnnotationRenderer(it, renderCtx) From 54ec0b31cc789463bc162dbf574d6cebe2d7c723 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 11:20:13 -0400 Subject: [PATCH 23/59] rename: AnnotationRenderer -> SchemaRenderer, add common BuilderRenderer, add metadata to annotation processor module --- hll/codegen/api/codegen.api | 5 ++ .../hll/codegen/rendering/BuilderRenderer.kt | 58 +++++++++++++++++++ .../build.gradle.kts | 5 ++ .../processor/rendering/HighLevelRenderer.kt | 2 +- ...nnotationRenderer.kt => SchemaRenderer.kt} | 44 ++++---------- 5 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt rename hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/{AnnotationRenderer.kt => SchemaRenderer.kt} (78%) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 5ad919c6b28..83ff913b5db 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -185,6 +185,11 @@ public final class aws/sdk/kotlin/hll/codegen/model/Types { public final fun stringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; } +public final class aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer { + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RendererBase;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)V + public final fun render ()V +} + public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContext { public fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;)V public final fun component1 ()Lcom/google/devtools/ksp/processing/KSPLogger; diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt new file mode 100644 index 00000000000..b58ddde7f59 --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -0,0 +1,58 @@ +package aws.sdk.kotlin.hll.codegen.rendering + +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSName +import com.google.devtools.ksp.symbol.KSPropertyDeclaration + +/** + * A DSL-style builder renderer. + * @param renderer The base renderer in which the builder will be written + * @param classDeclaration The [KSClassDeclaration] for which a builder will be generated + */ +class BuilderRenderer( + private val renderer: RendererBase, + classDeclaration: KSClassDeclaration, +) { + private val properties = classDeclaration.getAllProperties().mapNotNull(KSClassProperty.Companion::from) + + private val className = classDeclaration.qualifiedName!!.getShortName() + private val builderName = "${className}Builder" + + fun render() { + renderer.withDocs { + renderer.write("A DSL-style builder for instances of [#L]", className) + } + + renderer.withBlock("public class #L {", "}", builderName) { + properties.forEach { + renderer.write("public var #L: #L? = null", it.name, it.typeName.asString()) + } + renderer.blankLine() + + renderer.withBlock("public fun build(): #L {", "}", className) { + properties.forEach { + renderer.write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") + } + renderer.blankLine() + renderer.withBlock("return #L(", ")", className) { + properties.forEach { + renderer.write("#L,", it.name) + } + } + } + } + renderer.blankLine() + } +} + +private data class KSClassProperty(val name: String, val typeName: KSName) { + companion object { + fun from(ksProperty: KSPropertyDeclaration) = ksProperty + .getter + ?.returnType + ?.resolve() + ?.declaration + ?.qualifiedName + ?.let { typeName -> KSClassProperty(ksProperty.simpleName.getShortName(), typeName) } + } +} \ No newline at end of file diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts index ff5a73ee480..168178b66ba 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts @@ -3,6 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +description = "Annotation processor for the DynamoDbMapper, used to code-generate schemas for user classes" +extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL :: DynamoDbMapper :: Annotation Processor" +extra["moduleName"] = "aws.sdk.kotlin.hll.dynamodbmapper.processor" + + kotlin { sourceSets { jvmMain { diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt index c290bc53c4f..bea27aceb4e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt @@ -22,7 +22,7 @@ public class HighLevelRenderer( annotatedClasses.forEach { logger.info("Processing annotation on ${it.simpleName}") val renderCtx = RenderContext(logger, codegenFactory, "${it.packageName.asString()}.mapper.schemas") - val annotation = AnnotationRenderer(it, renderCtx) + val annotation = SchemaRenderer(it, renderCtx) annotation.render() } } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt similarity index 78% rename from hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt index 34fcd64056d..6e36c9fa345 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/AnnotationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt @@ -7,6 +7,7 @@ package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.Types +import aws.sdk.kotlin.hll.codegen.rendering.BuilderRenderer import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute @@ -23,7 +24,7 @@ import com.google.devtools.ksp.symbol.KSPropertyDeclaration * @param classDeclaration the [KSClassDeclaration] of the class * @param ctx the [RenderContext] of the renderer */ -public class AnnotationRenderer( +public class SchemaRenderer( private val classDeclaration: KSClassDeclaration, private val ctx: RenderContext, ) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema", "dynamodb-mapper-annotation-processor") { @@ -32,7 +33,7 @@ public class AnnotationRenderer( private val converterName = "${className}Converter" private val schemaName = "${className}Schema" - private val properties = classDeclaration.getAllProperties().mapNotNull(Property.Companion::from) + private val properties = classDeclaration.getAllProperties().mapNotNull(AnnotatedClassProperty.Companion::from) private val keyProperty = checkNotNull(properties.singleOrNull { it.isPk }) { "Expected exactly one @DynamoDbPartitionKey annotation on a property" } @@ -45,33 +46,8 @@ public class AnnotationRenderer( renderGetTable() } - private fun renderBuilder() { - checkNotNull(properties.singleOrNull { it.isPk }) { "Expected exactly one @DynamoDbPartitionKey annotation on a property" } - - withDocs { - write("A DSL-style builder for instances of [#L]", className) - } - - withBlock("public class #L {", "}", builderName) { - properties.forEach { - write("public var #L: #L? = null", it.name, it.typeName.asString()) - } - blankLine() - - withBlock("public fun build(): #L {", "}", className) { - properties.forEach { - write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") - } - blankLine() - withBlock("return #L(", ")", className) { - properties.forEach { - write("#L,", it.name) - } - } - } - } - blankLine() - } + // TODO Not all classes need builders generated (i.e. the class consists of all public mutable members), add configurability here + private fun renderBuilder() = BuilderRenderer(this, classDeclaration).render() private fun renderItemConverter() { withBlock("internal object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { @@ -86,7 +62,7 @@ public class AnnotationRenderer( blankLine() } - private fun renderAttributeDescriptor(prop: Property) { + private fun renderAttributeDescriptor(prop: AnnotatedClassProperty) { withBlock("#T(", "),", Types.AttributeDescriptor) { write("#S,", prop.ddbName) // key write("#L,", "$className::${prop.name}") // getter @@ -95,7 +71,7 @@ public class AnnotationRenderer( } } - private val Property.valueConverter: Type + private val AnnotatedClassProperty.valueConverter: Type get() = when (typeName.asString()) { "aws.smithy.kotlin.runtime.time.Instant" -> Types.DefaultInstantConverter "kotlin.Boolean" -> Types.BooleanConverter @@ -112,7 +88,7 @@ public class AnnotationRenderer( blankLine() } - private val Property.keySpec: String + private val AnnotatedClassProperty.keySpec: String get() = when (typeName.asString()) { "kotlin.Int" -> "Number" "kotlin.String" -> "String" @@ -136,7 +112,7 @@ public class AnnotationRenderer( } } -private data class Property(val name: String, val ddbName: String, val typeName: KSName, val isPk: Boolean) { +private data class AnnotatedClassProperty(val name: String, val ddbName: String, val typeName: KSName, val isPk: Boolean) { companion object { @OptIn(KspExperimental::class) fun from(ksProperty: KSPropertyDeclaration) = ksProperty @@ -149,7 +125,7 @@ private data class Property(val name: String, val ddbName: String, val typeName: val isPk = ksProperty.isAnnotationPresent(DynamoDbPartitionKey::class) val name = ksProperty.simpleName.getShortName() val ddbName = ksProperty.getAnnotationsByType(DynamoDbAttribute::class).singleOrNull()?.name ?: name - Property(name, ddbName, typeName, isPk) + AnnotatedClassProperty(name, ddbName, typeName, isPk) } } } From c8148fc526a0e92ccf56abe04cde88b404288c7e Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 12:20:48 -0400 Subject: [PATCH 24/59] Promote `internal` objects back to `public` --- .../hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt index 6e36c9fa345..7d1bb43b76e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt @@ -50,7 +50,7 @@ public class SchemaRenderer( private fun renderBuilder() = BuilderRenderer(this, classDeclaration).render() private fun renderItemConverter() { - withBlock("internal object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { + withBlock("public object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { write("builderFactory = ::#L,", builderName) write("build = #L::build,", builderName) withBlock("descriptors = arrayOf(", "),") { @@ -81,7 +81,7 @@ public class SchemaRenderer( } private fun renderSchema() { - withBlock("internal object #L : #T.#L<#L, #L> {", "}", schemaName, Types.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { + withBlock("public object #L : #T.#L<#L, #L> {", "}", schemaName, Types.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { write("override val converter : #1L = #1L", converterName) write("override val partitionKey: #1T<#2L> = #1T.#2L(#3S)", Types.KeySpec, keyProperty.keySpec, keyProperty.name) } From 1176517bb41ecd11a049a3f062f05ad32c2c8b11 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 12:25:49 -0400 Subject: [PATCH 25/59] Check property nullability when rendering build method (specifically `requireNotNull`) --- .../hll/codegen/rendering/BuilderRenderer.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index b58ddde7f59..fd657f2a549 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -3,6 +3,7 @@ package aws.sdk.kotlin.hll.codegen.rendering import com.google.devtools.ksp.symbol.KSClassDeclaration import com.google.devtools.ksp.symbol.KSName import com.google.devtools.ksp.symbol.KSPropertyDeclaration +import com.google.devtools.ksp.symbol.Nullability /** * A DSL-style builder renderer. @@ -31,7 +32,11 @@ class BuilderRenderer( renderer.withBlock("public fun build(): #L {", "}", className) { properties.forEach { - renderer.write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") + if (it.nullable) { + renderer.write("val #1L = #1L", it.name) + } else { + renderer.write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") + } } renderer.blankLine() renderer.withBlock("return #L(", ")", className) { @@ -45,14 +50,16 @@ class BuilderRenderer( } } -private data class KSClassProperty(val name: String, val typeName: KSName) { +private data class KSClassProperty(val name: String, val typeName: KSName, val nullable: Boolean) { companion object { - fun from(ksProperty: KSPropertyDeclaration) = ksProperty - .getter - ?.returnType - ?.resolve() - ?.declaration - ?.qualifiedName - ?.let { typeName -> KSClassProperty(ksProperty.simpleName.getShortName(), typeName) } + fun from(ksProperty: KSPropertyDeclaration): KSClassProperty? { + val type = ksProperty.getter?.returnType?.resolve() ?: return null + + val name = ksProperty.simpleName.getShortName() + val typeName = type.declaration.qualifiedName ?: return null + val nullable = type.nullability != Nullability.NOT_NULL + + return KSClassProperty(name, typeName, nullable) + } } } \ No newline at end of file From aac0fda812959c56ed107c47acff36795909f915 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 12:34:06 -0400 Subject: [PATCH 26/59] Add TODOs --- .../hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt index 7d1bb43b76e..b9f17647c8e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt @@ -77,12 +77,14 @@ public class SchemaRenderer( "kotlin.Boolean" -> Types.BooleanConverter "kotlin.Int" -> Types.IntConverter "kotlin.String" -> Types.StringConverter + // TODO Add additional "standard" item converters else -> error("Unsupported attribute type ${typeName.asString()}") } private fun renderSchema() { withBlock("public object #L : #T.#L<#L, #L> {", "}", schemaName, Types.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { write("override val converter : #1L = #1L", converterName) + // TODO Handle composite keys write("override val partitionKey: #1T<#2L> = #1T.#2L(#3S)", Types.KeySpec, keyProperty.keySpec, keyProperty.name) } blankLine() @@ -92,6 +94,7 @@ public class SchemaRenderer( get() = when (typeName.asString()) { "kotlin.Int" -> "Number" "kotlin.String" -> "String" + // TODO Handle ByteArray else -> error("Unsupported key type ${typeName.asString()}, expected Int or String") } From 3f566a6d6ec348845a71cb5119a4902e70e9debf Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 12:42:16 -0400 Subject: [PATCH 27/59] Replace #L with #T where appropriate --- .../hll/codegen/rendering/BuilderRenderer.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index fd657f2a549..7d22c2f4383 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -1,9 +1,7 @@ package aws.sdk.kotlin.hll.codegen.rendering -import com.google.devtools.ksp.symbol.KSClassDeclaration -import com.google.devtools.ksp.symbol.KSName -import com.google.devtools.ksp.symbol.KSPropertyDeclaration -import com.google.devtools.ksp.symbol.Nullability +import aws.sdk.kotlin.hll.codegen.model.Type +import com.google.devtools.ksp.symbol.* /** * A DSL-style builder renderer. @@ -12,25 +10,27 @@ import com.google.devtools.ksp.symbol.Nullability */ class BuilderRenderer( private val renderer: RendererBase, - classDeclaration: KSClassDeclaration, + private val classDeclaration: KSClassDeclaration, ) { private val properties = classDeclaration.getAllProperties().mapNotNull(KSClassProperty.Companion::from) private val className = classDeclaration.qualifiedName!!.getShortName() - private val builderName = "${className}Builder" + private val classType = Type.from(checkNotNull(classDeclaration.primaryConstructor?.returnType ) { + "Failed to determine class type for $className" + }) fun render() { renderer.withDocs { renderer.write("A DSL-style builder for instances of [#L]", className) } - renderer.withBlock("public class #L {", "}", builderName) { + renderer.withBlock("public class #L {", "}", "${className}Builder") { properties.forEach { renderer.write("public var #L: #L? = null", it.name, it.typeName.asString()) } renderer.blankLine() - renderer.withBlock("public fun build(): #L {", "}", className) { + renderer.withBlock("public fun build(): #T {", "}", classType) { properties.forEach { if (it.nullable) { renderer.write("val #1L = #1L", it.name) @@ -39,7 +39,7 @@ class BuilderRenderer( } } renderer.blankLine() - renderer.withBlock("return #L(", ")", className) { + renderer.withBlock("return #T(", ")", classType) { properties.forEach { renderer.write("#L,", it.name) } @@ -53,7 +53,7 @@ class BuilderRenderer( private data class KSClassProperty(val name: String, val typeName: KSName, val nullable: Boolean) { companion object { fun from(ksProperty: KSPropertyDeclaration): KSClassProperty? { - val type = ksProperty.getter?.returnType?.resolve() ?: return null + val type: KSType = ksProperty.getter?.returnType?.resolve() ?: return null val name = ksProperty.simpleName.getShortName() val typeName = type.declaration.qualifiedName ?: return null From a0f0bfce243e501c5c692fffb6bca4935f5af268 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 12:44:11 -0400 Subject: [PATCH 28/59] ktlint --- .../kotlin/hll/codegen/rendering/BuilderRenderer.kt | 10 ++++++---- .../build.gradle.kts | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index 7d22c2f4383..547189eef37 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -15,9 +15,11 @@ class BuilderRenderer( private val properties = classDeclaration.getAllProperties().mapNotNull(KSClassProperty.Companion::from) private val className = classDeclaration.qualifiedName!!.getShortName() - private val classType = Type.from(checkNotNull(classDeclaration.primaryConstructor?.returnType ) { - "Failed to determine class type for $className" - }) + private val classType = Type.from( + checkNotNull(classDeclaration.primaryConstructor?.returnType) { + "Failed to determine class type for $className" + }, + ) fun render() { renderer.withDocs { @@ -62,4 +64,4 @@ private data class KSClassProperty(val name: String, val typeName: KSName, val n return KSClassProperty(name, typeName, nullable) } } -} \ No newline at end of file +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts index 168178b66ba..e2e7b51e0ce 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts @@ -7,7 +7,6 @@ description = "Annotation processor for the DynamoDbMapper, used to code-generat extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL :: DynamoDbMapper :: Annotation Processor" extra["moduleName"] = "aws.sdk.kotlin.hll.dynamodbmapper.processor" - kotlin { sourceSets { jvmMain { From 832756814b02155a4a0e4f792318c6ea4e623a45 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 12:49:57 -0400 Subject: [PATCH 29/59] Add `RendererBase.use { ... }` --- .../hll/codegen/rendering/BuilderRenderer.kt | 26 +++++++++---------- .../hll/codegen/rendering/RendererBase.kt | 7 +++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index 547189eef37..5e42626097f 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -21,34 +21,34 @@ class BuilderRenderer( }, ) - fun render() { - renderer.withDocs { - renderer.write("A DSL-style builder for instances of [#L]", className) + fun render() = renderer.use { + withDocs { + write("A DSL-style builder for instances of [#L]", className) } - renderer.withBlock("public class #L {", "}", "${className}Builder") { + withBlock("public class #L {", "}", "${className}Builder") { properties.forEach { - renderer.write("public var #L: #L? = null", it.name, it.typeName.asString()) + write("public var #L: #L? = null", it.name, it.typeName.asString()) } - renderer.blankLine() + blankLine() - renderer.withBlock("public fun build(): #T {", "}", classType) { + withBlock("public fun build(): #T {", "}", classType) { properties.forEach { if (it.nullable) { - renderer.write("val #1L = #1L", it.name) + write("val #1L = #1L", it.name) } else { - renderer.write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") + write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") } } - renderer.blankLine() - renderer.withBlock("return #T(", ")", classType) { + blankLine() + withBlock("return #T(", ")", classType) { properties.forEach { - renderer.write("#L,", it.name) + write("#L,", it.name) } } } } - renderer.blankLine() + blankLine() } } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt index 1052551b92f..c7715aa2ec2 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt @@ -27,3 +27,10 @@ abstract class RendererBase( protected abstract fun generate() } + +/** + * Use an instance of [RendererBase] to execute a [block] + */ +fun RendererBase.use(block: RendererBase.() -> Unit) { + block() +} From 48c42060635030a2dc8315580173994dccedd5bd Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 16:01:45 -0400 Subject: [PATCH 30/59] Combine operations and annotation processor codegen into common codegen module --- hll/build.gradle.kts | 3 +- hll/codegen/api/codegen.api | 4 + .../build.gradle.kts | 20 -- ...ols.ksp.processing.SymbolProcessorProvider | 1 - .../api/dynamodb-mapper-codegen.api | 215 ++++++++++++++++++ .../build.gradle.kts | 6 + .../annotations/AnnotationsProcessor.kt} | 6 +- .../AnnotationsProcessorProvider.kt} | 6 +- .../rendering/HighLevelRenderer.kt | 2 +- .../annotations}/rendering/SchemaRenderer.kt | 2 +- .../operations}/HighLevelOpsProcessor.kt | 8 +- .../HighLevelOpsProcessorProvider.kt | 2 +- .../operations}/model/ItemSourceKind.kt | 2 +- .../operations}/model/Member.kt | 2 +- .../model/MemberCodegenBehavior.kt | 2 +- .../operations}/model/ModelAttributes.kt | 2 +- .../operations}/model/Operation.kt | 2 +- .../operations}/model/Structure.kt | 2 +- .../rendering}/DataTypeGenerator.kt | 8 +- .../rendering/HighLevelRenderer.kt | 8 +- .../rendering/OperationRenderer.kt | 6 +- .../rendering/OperationsTypeRenderer.kt | 4 +- ...ols.ksp.processing.SymbolProcessorProvider | 3 + ...ols.ksp.processing.SymbolProcessorProvider | 1 - .../dynamodb-mapper/build.gradle.kts | 4 +- .../build.gradle.kts | 2 +- settings.gradle.kts | 3 +- 27 files changed, 265 insertions(+), 61 deletions(-) delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider create mode 100644 hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen => dynamodb-mapper-codegen}/build.gradle.kts (64%) rename hll/dynamodb-mapper/{dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt} (85%) rename hll/dynamodb-mapper/{dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessorProvider.kt => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt} (63%) rename hll/dynamodb-mapper/{dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations}/rendering/HighLevelRenderer.kt (94%) rename hll/dynamodb-mapper/{dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations}/rendering/SchemaRenderer.kt (98%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/HighLevelOpsProcessor.kt (89%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/HighLevelOpsProcessorProvider.kt (92%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/model/ItemSourceKind.kt (97%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/model/Member.kt (92%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/model/MemberCodegenBehavior.kt (98%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/model/ModelAttributes.kt (93%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/model/Operation.kt (97%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/model/Structure.kt (97%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering}/DataTypeGenerator.kt (93%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/rendering/HighLevelRenderer.kt (80%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/rendering/OperationRenderer.kt (96%) rename hll/dynamodb-mapper/{dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen => dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations}/rendering/OperationsTypeRenderer.kt (96%) create mode 100644 hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/hll/build.gradle.kts b/hll/build.gradle.kts index 504b840bba0..f67d3f5d661 100644 --- a/hll/build.gradle.kts +++ b/hll/build.gradle.kts @@ -87,8 +87,7 @@ apiValidation { val availableSubprojects = subprojects.map { it.name }.toSet() ignoredProjects += listOf( - "dynamodb-mapper-annotation-processor", "dynamodb-mapper-annotation-processor-test", - "dynamodb-mapper-ops-codegen", + "dynamodb-mapper-codegen", ).filter { it in availableSubprojects } // Some projects may not be in the build depending on bootstrapping } diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 83ff913b5db..7c6a3e49874 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -236,6 +236,10 @@ public abstract class aws/sdk/kotlin/hll/codegen/rendering/RendererBase : aws/sd public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V } +public final class aws/sdk/kotlin/hll/codegen/rendering/RendererBaseKt { + public static final fun use (Laws/sdk/kotlin/hll/codegen/rendering/RendererBase;Lkotlin/jvm/functions/Function1;)V +} + public final class aws/sdk/kotlin/hll/codegen/util/AttributesExtKt { public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/smithy/kotlin/runtime/collections/Attributes; public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/Pair;)Laws/smithy/kotlin/runtime/collections/Attributes; diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts deleted file mode 100644 index e2e7b51e0ce..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/build.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -description = "Annotation processor for the DynamoDbMapper, used to code-generate schemas for user classes" -extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL :: DynamoDbMapper :: Annotation Processor" -extra["moduleName"] = "aws.sdk.kotlin.hll.dynamodbmapper.processor" - -kotlin { - sourceSets { - jvmMain { - dependencies { - implementation(project(":hll:codegen")) - implementation(project(":hll:dynamodb-mapper:dynamodb-mapper-annotations")) - implementation(libs.ksp.api) - } - } - } -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider deleted file mode 100644 index 8ddced70565..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider +++ /dev/null @@ -1 +0,0 @@ -aws.sdk.kotlin.hll.dynamodbmapper.processor.MapperProcessorProvider diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api b/hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api new file mode 100644 index 00000000000..d8ffbc07eed --- /dev/null +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api @@ -0,0 +1,215 @@ +public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor : com/google/devtools/ksp/processing/SymbolProcessor { + public fun (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)V + public fun process (Lcom/google/devtools/ksp/processing/Resolver;)Ljava/util/List; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider : com/google/devtools/ksp/processing/SymbolProcessorProvider { + public fun ()V + public fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Laws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor; + public synthetic fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Lcom/google/devtools/ksp/processing/SymbolProcessor; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer { + public fun (Ljava/util/List;Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;)V + public final fun render ()V +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer : aws/sdk/kotlin/hll/codegen/rendering/RendererBase { + public fun (Lcom/google/devtools/ksp/symbol/KSClassDeclaration;Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;)V +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor : com/google/devtools/ksp/processing/SymbolProcessor { + public fun (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)V + public fun process (Lcom/google/devtools/ksp/processing/Resolver;)Ljava/util/List; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider : com/google/devtools/ksp/processing/SymbolProcessorProvider { + public fun ()V + public fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Lcom/google/devtools/ksp/processing/SymbolProcessor; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind : java/lang/Enum { + public static final field Index Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; + public static final field ItemSource Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; + public static final field Table Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; + public static fun getEntries ()Lkotlin/enums/EnumEntries; + public final fun getHoistedFields ()Ljava/util/List; + public final fun getParent ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; + public final fun getSpecType (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun isAbstract ()Z + public static fun valueOf (Ljava/lang/String;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; + public static fun values ()[Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKindKt { + public static final fun getItemSourceKinds (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)Ljava/util/Set; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member { + public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member$Companion; + public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/model/Type;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Laws/sdk/kotlin/hll/codegen/model/Type; + public final fun copy (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member;Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/model/Type;ILjava/lang/Object;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member; + public fun equals (Ljava/lang/Object;)Z + public final fun getName ()Ljava/lang/String; + public final fun getType ()Laws/sdk/kotlin/hll/codegen/model/Type; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member$Companion { + public final fun from (Lcom/google/devtools/ksp/symbol/KSPropertyDeclaration;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member; +} + +public abstract interface class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { + public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Companion; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Companion { + public final fun identifyFor (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Drop : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { + public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Drop; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Hoist : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { + public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Hoist; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapAll : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { + public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapAll; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapKeys : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { + public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapKeys; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$PassThrough : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { + public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$PassThrough; + public fun equals (Ljava/lang/Object;)Z + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehaviorKt { + public static final fun getCodegenBehavior (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes { + public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes; + public final fun getLowLevelOperation ()Laws/smithy/kotlin/runtime/collections/AttributeKey; + public final fun getLowLevelStructure ()Laws/smithy/kotlin/runtime/collections/AttributeKey; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation { + public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation$Companion; + public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;)V + public synthetic fun (Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Ljava/lang/String; + public final fun component2 ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public final fun component3 ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public final fun component4 ()Laws/smithy/kotlin/runtime/collections/Attributes; + public final fun copy (Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;ILjava/lang/Object;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; + public fun equals (Ljava/lang/Object;)Z + public final fun getAttributes ()Laws/smithy/kotlin/runtime/collections/Attributes; + public final fun getMethodName ()Ljava/lang/String; + public final fun getName ()Ljava/lang/String; + public final fun getRequest ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public final fun getResponse ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation$Companion { + public final fun from (Lcom/google/devtools/ksp/symbol/KSFunctionDeclaration;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/OperationKt { + public static final fun getLowLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; + public static final fun toHighLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;Ljava/lang/String;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure { + public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure$Companion; + public fun (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;)V + public synthetic fun (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun component1 ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun component2 ()Ljava/util/List; + public final fun component3 ()Laws/smithy/kotlin/runtime/collections/Attributes; + public final fun copy (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;ILjava/lang/Object;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public fun equals (Ljava/lang/Object;)Z + public final fun getAttributes ()Laws/smithy/kotlin/runtime/collections/Attributes; + public final fun getMembers ()Ljava/util/List; + public final fun getType ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure$Companion { + public final fun from (Lcom/google/devtools/ksp/symbol/KSTypeReference;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/StructureKt { + public static final fun getLowLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public static final fun toHighLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Ljava/lang/String;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Laws/sdk/kotlin/hll/codegen/core/CodeGenerator;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;)V + public fun blankLine ()V + public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun dedent (I)V + public final fun generate ()V + public fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; + public final fun getStructure ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; + public fun indent (I)V + public fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V + public fun persist ()V + public fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V + public fun withDocs (Lkotlin/jvm/functions/Function0;)V + public fun write (Ljava/lang/String;[Ljava/lang/Object;)V + public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer { + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/util/List;)V + public final fun render ()V +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer : aws/sdk/kotlin/hll/codegen/rendering/RendererBase { + public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer$Companion; + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)V + public final fun getMembers ()Ljava/util/Map; + public final fun getOperation ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer$Companion { + public final fun factoryFunctionName (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)Ljava/lang/String; +} + +public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer : aws/sdk/kotlin/hll/codegen/rendering/RendererBase { + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind;Laws/sdk/kotlin/hll/codegen/model/Type;Ljava/util/List;)V + public final fun getInterfaceType ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun getItemSourceKind ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; + public final fun getOperations ()Ljava/util/List; + public final fun getParentType ()Laws/sdk/kotlin/hll/codegen/model/Type; +} + diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts similarity index 64% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts index dcc690d008f..06ca496808a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts @@ -3,6 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +description = "DynamoDbMapper code generation" +extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL :: DynamoDbMapper :: Codegen" +extra["moduleName"] = "aws.sdk.kotlin.hll.dynamodbmapper.codegen" + + plugins { alias(libs.plugins.kotlin.jvm) } @@ -10,6 +15,7 @@ plugins { dependencies { implementation(libs.ksp.api) implementation(project(":hll:codegen")) + implementation(project(":hll:dynamodb-mapper:dynamodb-mapper-annotations")) implementation(project(":services:dynamodb")) testImplementation(libs.junit.jupiter) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt similarity index 85% rename from hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt index 7aa17808072..61e1eb53cc9 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt @@ -2,18 +2,18 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.processor +package aws.sdk.kotlin.hll.dynamodbmapper.annotations import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbItem -import aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering.HighLevelRenderer +import aws.sdk.kotlin.hll.dynamodbmapper.annotations.rendering.HighLevelRenderer import com.google.devtools.ksp.processing.* import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.validate private val annotationName = DynamoDbItem::class.qualifiedName!! -public class MapperProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor { +public class AnnotationsProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor { private var invoked = false private val logger = environment.logger private val codeGenerator = environment.codeGenerator diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessorProvider.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt similarity index 63% rename from hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessorProvider.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt index 4fa71cdf457..0f0143d8982 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/MapperProcessorProvider.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt @@ -2,11 +2,11 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.processor +package aws.sdk.kotlin.hll.dynamodbmapper.annotations import com.google.devtools.ksp.processing.SymbolProcessorEnvironment import com.google.devtools.ksp.processing.SymbolProcessorProvider -public class MapperProcessorProvider : SymbolProcessorProvider { - override fun create(environment: SymbolProcessorEnvironment): MapperProcessor = MapperProcessor(environment) +public class AnnotationsProcessorProvider : SymbolProcessorProvider { + override fun create(environment: SymbolProcessorEnvironment): AnnotationsProcessor = AnnotationsProcessor(environment) } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer.kt similarity index 94% rename from hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer.kt index bea27aceb4e..a724e9f1484 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.codegen.rendering.RenderContext diff --git a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer.kt similarity index 98% rename from hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer.kt index b9f17647c8e..ac6b2408d93 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-annotation-processor/jvm/src/aws/sdk/kotlin/hll/dynamodbmapper/processor/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.processor.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor.kt similarity index 89% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor.kt index 1b6ecab5fc7..a0b4dbd474c 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor.kt @@ -2,14 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen +package aws.sdk.kotlin.hll.dynamodbmapper.operations import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.util.Pkg -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.toHighLevel -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering.HighLevelRenderer +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Operation +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.toHighLevel +import aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering.HighLevelRenderer import aws.sdk.kotlin.services.dynamodb.DynamoDbClient import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.getDeclaredFunctions diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessorProvider.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessorProvider.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider.kt index 3d965f7d77d..11b060181c6 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/HighLevelOpsProcessorProvider.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen +package aws.sdk.kotlin.hll.dynamodbmapper.operations import com.google.devtools.ksp.processing.SymbolProcessor import com.google.devtools.ksp.processing.SymbolProcessorEnvironment diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind.kt similarity index 97% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind.kt index 7d305442b6a..72c1bf8bbfc 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ItemSourceKind.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +package aws.sdk.kotlin.hll.dynamodbmapper.operations.model import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member.kt index 8cdcd3660e4..ea49d754c69 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Member.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +package aws.sdk.kotlin.hll.dynamodbmapper.operations.model import aws.sdk.kotlin.hll.codegen.model.Type import com.google.devtools.ksp.symbol.KSPropertyDeclaration diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior.kt similarity index 98% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior.kt index 172f4b6c808..75178b091ea 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +package aws.sdk.kotlin.hll.dynamodbmapper.operations.model import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ModelAttributes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes.kt similarity index 93% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ModelAttributes.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes.kt index 55bbdaf1f5d..a3315905b41 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/ModelAttributes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +package aws.sdk.kotlin.hll.dynamodbmapper.operations.model import aws.smithy.kotlin.runtime.collections.AttributeKey diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation.kt similarity index 97% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation.kt index 29f548d8e4c..a038c0c077e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Operation.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +package aws.sdk.kotlin.hll.dynamodbmapper.operations.model import aws.sdk.kotlin.hll.codegen.util.capitalizeFirstChar import aws.sdk.kotlin.hll.codegen.util.plus diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure.kt similarity index 97% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure.kt index ce12b10cf0d..985a6bfa01f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/Structure.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model +package aws.sdk.kotlin.hll.dynamodbmapper.operations.model import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator.kt similarity index 93% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator.kt index 94ae3efbcfb..a5f1ff46b8c 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/core/DataTypeGenerator.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator.kt @@ -2,16 +2,16 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.core +package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGenerator import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.rendering.RenderContext -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Member -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Structure +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.* +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Member +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Structure /** * Generates immutable data types from a [Structure] into an underlying [CodeGenerator]. These data types consist of a diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer.kt similarity index 80% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer.kt index 82958a7cc5b..08d98d04959 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer.kt @@ -2,13 +2,13 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.rendering.RenderContext -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.ItemSourceKind -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.Operation -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.itemSourceKinds +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.ItemSourceKind +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Operation +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.itemSourceKinds /** * The parent renderer for all codegen from this package. This class orchestrates the various sub-renderers. diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer.kt similarity index 96% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer.kt index 3de44c639a6..070d9d2d144 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer.kt @@ -2,15 +2,15 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering import aws.sdk.kotlin.hll.codegen.core.* import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.core.DataTypeGenerator -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* +import aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering.DataTypeGenerator +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer.kt similarity index 96% rename from hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer.kt index 46ec1a0ab46..656b93d201e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef @@ -10,7 +10,7 @@ import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.util.lowercaseFirstChar -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.* +import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.* /** * Renders the `*Operations` interface and `*OperationsImpl` class which contain a method for each codegenned diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider new file mode 100644 index 00000000000..444d472b7e0 --- /dev/null +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -0,0 +1,3 @@ +aws.sdk.kotlin.hll.dynamodbmapper.operations.HighLevelOpsProcessorProvider +aws.sdk.kotlin.hll.dynamodbmapper.annotations.AnnotationsProcessorProvider + diff --git a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider deleted file mode 100644 index 15972df9b3f..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-ops-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider +++ /dev/null @@ -1 +0,0 @@ -aws.sdk.kotlin.hll.dynamodbmapper.codegen.HighLevelOpsProcessorProvider diff --git a/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts index 9a51b2f87cd..f655d5cc0da 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts @@ -63,7 +63,7 @@ ksp { if (project.NATIVE_ENABLED) { // Configure KSP for commonMain source generation; https://github.com/google/ksp/issues/963#issuecomment-1894144639 - dependencies.kspCommonMainMetadata(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen")) + dependencies.kspCommonMainMetadata(project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) kotlin.sourceSets.commonMain { tasks.withType { @@ -76,7 +76,7 @@ if (project.NATIVE_ENABLED) { // hack follows in narrative, minimally-opinionated comments. // Start by invoking the JVM-only KSP configuration - dependencies.kspJvm(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen")) + dependencies.kspJvm(project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) // Then we need to move the generated source from jvm to common. Gradle lacks a move task so we roll our own! val moveGenSrc by tasks.registering { diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts index bb38d584747..72397d459d0 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts @@ -22,5 +22,5 @@ dependencies { listOf( "kspCommonMainMetadata", "kspJvm", // FIXME Generating common code is hard for KSP: https://github.com/google/ksp/issues/567 - ).forEach { configuration -> add(configuration, project(":hll:dynamodb-mapper:dynamodb-mapper-annotation-processor")) } + ).forEach { configuration -> add(configuration, project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) } } diff --git a/settings.gradle.kts b/settings.gradle.kts index e6aa6c43e03..955d2b3752f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -62,9 +62,8 @@ file("services").listFiles().forEach { if ("dynamodb".isBootstrappedService) { include(":hll:dynamodb-mapper") include(":hll:dynamodb-mapper:dynamodb-mapper") - include(":hll:dynamodb-mapper:dynamodb-mapper-annotation-processor") + include(":hll:dynamodb-mapper:dynamodb-mapper-codegen") include(":hll:dynamodb-mapper:dynamodb-mapper-annotations") - include(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen") include(":hll:dynamodb-mapper:tests:dynamodb-mapper-annotation-processor-test") } else { logger.warn(":services:dynamodb is not bootstrapped, skipping :hll:dynamodb-mapper and subprojects") From 7ea934e810aa69956eb5e4ec336fccc0fd0318c3 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 16:46:16 -0400 Subject: [PATCH 31/59] Temporarily disable annotation-processor-test --- .../build.gradle.kts | 12 ++-- .../tests/processor/data/UserTest.kt | 66 +++++++++---------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts index 72397d459d0..bb9f63b4fad 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts @@ -18,9 +18,9 @@ kotlin { } } -dependencies { - listOf( - "kspCommonMainMetadata", - "kspJvm", // FIXME Generating common code is hard for KSP: https://github.com/google/ksp/issues/567 - ).forEach { configuration -> add(configuration, project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) } -} +//dependencies { +// listOf( +// "kspCommonMainMetadata", +// "kspJvm", // FIXME Generating common code is hard for KSP: https://github.com/google/ksp/issues/567 +// ).forEach { configuration -> add(configuration, project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) } +//} diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt index 0f2cbe70fdf..0edb63a637e 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt @@ -1,33 +1,33 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data - -import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf -import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter -import aws.sdk.kotlin.services.dynamodb.model.AttributeValue -import kotlin.test.Test -import kotlin.test.assertEquals - -class UserTest { - @Test - fun testConversion() { - val user = User(123, "Steve", "Rogers", 84) - val converted = UserConverter.toItem(user) - - assertEquals( - itemOf( - "id" to AttributeValue.N("123"), - "fName" to AttributeValue.S("Steve"), - "lName" to AttributeValue.S("Rogers"), - "age" to AttributeValue.N("84"), - ), - converted, - ) - - val unconverted = UserConverter.fromItem(converted) - - assertEquals(user, unconverted) - } -} +///* +// * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// * SPDX-License-Identifier: Apache-2.0 +// */ +//package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data +// +//import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf +//import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter +//import aws.sdk.kotlin.services.dynamodb.model.AttributeValue +//import kotlin.test.Test +//import kotlin.test.assertEquals +// +//class UserTest { +// @Test +// fun testConversion() { +// val user = User(123, "Steve", "Rogers", 84) +// val converted = UserConverter.toItem(user) +// +// assertEquals( +// itemOf( +// "id" to AttributeValue.N("123"), +// "fName" to AttributeValue.S("Steve"), +// "lName" to AttributeValue.S("Rogers"), +// "age" to AttributeValue.N("84"), +// ), +// converted, +// ) +// +// val unconverted = UserConverter.fromItem(converted) +// +// assertEquals(user, unconverted) +// } +//} From 171e47a0101d6256d35e988496e37abb0fa56b61 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 13 Aug 2024 17:50:43 -0400 Subject: [PATCH 32/59] Configure `excludeProcessor` --- .../build.gradle.kts | 17 +++-- .../tests/processor/data/UserTest.kt | 66 +++++++++---------- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts index bb9f63b4fad..0dc6b1d58af 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts @@ -18,9 +18,14 @@ kotlin { } } -//dependencies { -// listOf( -// "kspCommonMainMetadata", -// "kspJvm", // FIXME Generating common code is hard for KSP: https://github.com/google/ksp/issues/567 -// ).forEach { configuration -> add(configuration, project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) } -//} +dependencies { + listOf( + "kspCommonMainMetadata", + "kspJvm", // FIXME Generating common code is hard for KSP: https://github.com/google/ksp/issues/567 + ).forEach { configuration -> add(configuration, project(":hll:dynamodb-mapper:dynamodb-mapper-codegen")) } +} + +ksp { + // annotation-processor-test does not need the ops-codegen processor loaded + excludeProcessor("aws.sdk.kotlin.hll.dynamodbmapper.operations.HighLevelOpsProcessorProvider") +} diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt index 0edb63a637e..0f2cbe70fdf 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/common/test/aws/sdk/kotlin/hll/dynamodbmapper/tests/processor/data/UserTest.kt @@ -1,33 +1,33 @@ -///* -// * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// * SPDX-License-Identifier: Apache-2.0 -// */ -//package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data -// -//import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf -//import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter -//import aws.sdk.kotlin.services.dynamodb.model.AttributeValue -//import kotlin.test.Test -//import kotlin.test.assertEquals -// -//class UserTest { -// @Test -// fun testConversion() { -// val user = User(123, "Steve", "Rogers", 84) -// val converted = UserConverter.toItem(user) -// -// assertEquals( -// itemOf( -// "id" to AttributeValue.N("123"), -// "fName" to AttributeValue.S("Steve"), -// "lName" to AttributeValue.S("Rogers"), -// "age" to AttributeValue.N("84"), -// ), -// converted, -// ) -// -// val unconverted = UserConverter.fromItem(converted) -// -// assertEquals(user, unconverted) -// } -//} +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data + +import aws.sdk.kotlin.hll.dynamodbmapper.model.itemOf +import aws.sdk.kotlin.hll.dynamodbmapper.tests.processor.data.mapper.schemas.UserConverter +import aws.sdk.kotlin.services.dynamodb.model.AttributeValue +import kotlin.test.Test +import kotlin.test.assertEquals + +class UserTest { + @Test + fun testConversion() { + val user = User(123, "Steve", "Rogers", 84) + val converted = UserConverter.toItem(user) + + assertEquals( + itemOf( + "id" to AttributeValue.N("123"), + "fName" to AttributeValue.S("Steve"), + "lName" to AttributeValue.S("Rogers"), + "age" to AttributeValue.N("84"), + ), + converted, + ) + + val unconverted = UserConverter.fromItem(converted) + + assertEquals(user, unconverted) + } +} From 47499cbdc70218e9a0c0a74fe627f1ec9eabc448 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 09:55:33 -0400 Subject: [PATCH 33/59] Relocate to dynamodbmapper.codegen.* package --- .../{ => codegen}/annotations/AnnotationsProcessor.kt | 4 ++-- .../annotations/AnnotationsProcessorProvider.kt | 2 +- .../annotations/rendering/HighLevelRenderer.kt | 2 +- .../{ => codegen}/annotations/rendering/SchemaRenderer.kt | 2 +- .../{ => codegen}/operations/HighLevelOpsProcessor.kt | 8 ++++---- .../operations/HighLevelOpsProcessorProvider.kt | 2 +- .../{ => codegen}/operations/model/ItemSourceKind.kt | 2 +- .../{ => codegen}/operations/model/Member.kt | 2 +- .../operations/model/MemberCodegenBehavior.kt | 2 +- .../{ => codegen}/operations/model/ModelAttributes.kt | 2 +- .../{ => codegen}/operations/model/Operation.kt | 2 +- .../{ => codegen}/operations/model/Structure.kt | 4 ++-- .../operations/rendering/DataTypeGenerator.kt | 7 +++---- .../operations/rendering/HighLevelRenderer.kt | 8 ++++---- .../operations/rendering/OperationRenderer.kt | 5 ++--- .../operations/rendering/OperationsTypeRenderer.kt | 6 ++++-- ...google.devtools.ksp.processing.SymbolProcessorProvider | 4 ++-- .../build.gradle.kts | 2 +- 18 files changed, 33 insertions(+), 33 deletions(-) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/annotations/AnnotationsProcessor.kt (90%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/annotations/AnnotationsProcessorProvider.kt (87%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/annotations/rendering/HighLevelRenderer.kt (93%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/annotations/rendering/SchemaRenderer.kt (98%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/HighLevelOpsProcessor.kt (88%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/HighLevelOpsProcessorProvider.kt (91%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/model/ItemSourceKind.kt (96%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/model/Member.kt (91%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/model/MemberCodegenBehavior.kt (98%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/model/ModelAttributes.kt (92%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/model/Operation.kt (97%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/model/Structure.kt (95%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/rendering/DataTypeGenerator.kt (93%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/rendering/HighLevelRenderer.kt (78%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/rendering/OperationRenderer.kt (96%) rename hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/{ => codegen}/operations/rendering/OperationsTypeRenderer.kt (92%) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt similarity index 90% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt index 61e1eb53cc9..8d152b44cd4 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt @@ -2,11 +2,11 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.annotations +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbItem -import aws.sdk.kotlin.hll.dynamodbmapper.annotations.rendering.HighLevelRenderer +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering.HighLevelRenderer import com.google.devtools.ksp.processing.* import com.google.devtools.ksp.symbol.* import com.google.devtools.ksp.validate diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt similarity index 87% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt index 0f0143d8982..01a46415e7e 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.annotations +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations import com.google.devtools.ksp.processing.SymbolProcessorEnvironment import com.google.devtools.ksp.processing.SymbolProcessorProvider diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt similarity index 93% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt index a724e9f1484..dc72b347d43 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.annotations.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.codegen.rendering.RenderContext diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt similarity index 98% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index ac6b2408d93..488b3da0d46 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.annotations.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt similarity index 88% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt index a0b4dbd474c..19eec2ec84f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt @@ -2,14 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations import aws.sdk.kotlin.hll.codegen.core.CodeGeneratorFactory import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.util.Pkg -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Operation -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.toHighLevel -import aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering.HighLevelRenderer +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Operation +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.toHighLevel +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering.HighLevelRenderer import aws.sdk.kotlin.services.dynamodb.DynamoDbClient import com.google.devtools.ksp.getClassDeclarationByName import com.google.devtools.ksp.getDeclaredFunctions diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessorProvider.kt similarity index 91% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessorProvider.kt index 11b060181c6..1b3b9611d44 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessorProvider.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations import com.google.devtools.ksp.processing.SymbolProcessor import com.google.devtools.ksp.processing.SymbolProcessorEnvironment diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/ItemSourceKind.kt similarity index 96% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/ItemSourceKind.kt index 72c1bf8bbfc..5e6675b715f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/ItemSourceKind.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.model +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Member.kt similarity index 91% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Member.kt index ea49d754c69..704cf3f1c8d 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Member.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.model +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model import aws.sdk.kotlin.hll.codegen.model.Type import com.google.devtools.ksp.symbol.KSPropertyDeclaration diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt similarity index 98% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt index 75178b091ea..bfdb2953837 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.model +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/ModelAttributes.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/ModelAttributes.kt index a3315905b41..289f38edc92 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/ModelAttributes.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.model +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model import aws.smithy.kotlin.runtime.collections.AttributeKey diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Operation.kt similarity index 97% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Operation.kt index a038c0c077e..50737536822 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Operation.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.model +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model import aws.sdk.kotlin.hll.codegen.util.capitalizeFirstChar import aws.sdk.kotlin.hll.codegen.util.plus diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt similarity index 95% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt index 985a6bfa01f..849e8569300 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.model +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef @@ -34,7 +34,7 @@ data class Structure( type = Type.from(ksTypeRef), members = (ksTypeRef.resolve().declaration as KSClassDeclaration) .getDeclaredProperties() - .map(Member::from) + .map(Member.Companion::from) .toList(), ) } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt similarity index 93% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt index a5f1ff46b8c..c3f46db8a32 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt @@ -2,16 +2,15 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGenerator import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.rendering.RenderContext -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.* -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Member -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Structure +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Member +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Structure /** * Generates immutable data types from a [Structure] into an underlying [CodeGenerator]. These data types consist of a diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/HighLevelRenderer.kt similarity index 78% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/HighLevelRenderer.kt index 08d98d04959..b8ea097d7cb 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/HighLevelRenderer.kt @@ -2,13 +2,13 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.rendering.RenderContext -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.ItemSourceKind -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.Operation -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.itemSourceKinds +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.ItemSourceKind +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Operation +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.itemSourceKinds /** * The parent renderer for all codegen from this package. This class orchestrates the various sub-renderers. diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt similarity index 96% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt index 070d9d2d144..a6fcb300a35 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt @@ -2,15 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.core.* import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info -import aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering.DataTypeGenerator -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.* +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt similarity index 92% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer.kt rename to hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt index 656b93d201e..71c8863adc3 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.operations.rendering +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef @@ -10,7 +10,9 @@ import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.util.lowercaseFirstChar -import aws.sdk.kotlin.hll.dynamodbmapper.operations.model.* +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.ItemSourceKind +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Operation +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.itemSourceKinds /** * Renders the `*Operations` interface and `*OperationsImpl` class which contain a method for each codegenned diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider index 444d472b7e0..59a8692f0a6 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider @@ -1,3 +1,3 @@ -aws.sdk.kotlin.hll.dynamodbmapper.operations.HighLevelOpsProcessorProvider -aws.sdk.kotlin.hll.dynamodbmapper.annotations.AnnotationsProcessorProvider +aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.HighLevelOpsProcessorProvider +aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.AnnotationsProcessorProvider diff --git a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts index 0dc6b1d58af..6b5a4a097a7 100644 --- a/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts +++ b/hll/dynamodb-mapper/tests/dynamodb-mapper-annotation-processor-test/build.gradle.kts @@ -27,5 +27,5 @@ dependencies { ksp { // annotation-processor-test does not need the ops-codegen processor loaded - excludeProcessor("aws.sdk.kotlin.hll.dynamodbmapper.operations.HighLevelOpsProcessorProvider") + excludeProcessor("aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.HighLevelOpsProcessorProvider") } From 3ea7b6f7e6199a3014168fee333a2ec847b60a8a Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 10:09:02 -0400 Subject: [PATCH 34/59] Break out Types and DynamoDbMapperTypes --- hll/codegen/api/codegen.api | 29 ++------ .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 69 +------------------ .../aws/sdk/kotlin/hll/codegen/model/Types.kt | 37 ++++++++++ .../annotations/rendering/SchemaRenderer.kt | 22 +++--- .../codegen/model/DynamoDbMapperTypes.kt | 38 ++++++++++ .../operations/model/MemberCodegenBehavior.kt | 30 ++++---- .../operations/rendering/OperationRenderer.kt | 13 ++-- 7 files changed, 116 insertions(+), 122 deletions(-) create mode 100644 hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt create mode 100644 hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 7c6a3e49874..1aff5ed4bb2 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -117,10 +117,6 @@ public abstract interface class aws/sdk/kotlin/hll/codegen/model/Type { public final class aws/sdk/kotlin/hll/codegen/model/Type$Companion { public final fun from (Lcom/google/devtools/ksp/symbol/KSTypeReference;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun kotlin (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun list (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun map (Laws/sdk/kotlin/hll/codegen/model/Type;Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun stringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; } public final class aws/sdk/kotlin/hll/codegen/model/TypeKt { @@ -162,26 +158,15 @@ public final class aws/sdk/kotlin/hll/codegen/model/TypeVar : aws/sdk/kotlin/hll public final class aws/sdk/kotlin/hll/codegen/model/Types { public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types; - public final fun getAttributeDescriptor ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getAttributeMap ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getAttributeValue ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getBooleanConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getDefaultInstantConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getDynamoDbMapper ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getHReqContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getIntConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getItemSchema ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getKeySpec ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getMapperContextImpl ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getOperation ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getSimpleItemConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; +} + +public final class aws/sdk/kotlin/hll/codegen/model/Types$Kotlin { + public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types$Kotlin; public final fun getString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getStringConverter ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getStringNullable ()Laws/sdk/kotlin/hll/codegen/model/Type; - public final fun getTable ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getToItem ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun itemSchema (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun kotlin (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun list (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun map (Laws/sdk/kotlin/hll/codegen/model/Type;Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun stringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; } diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 08bcfa9f6d1..18e6a56bbb8 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -4,8 +4,6 @@ */ package aws.sdk.kotlin.hll.codegen.model -import aws.sdk.kotlin.hll.codegen.model.Type.Companion.map -import aws.sdk.kotlin.hll.codegen.util.Pkg import com.google.devtools.ksp.symbol.KSTypeReference /** @@ -26,30 +24,6 @@ sealed interface Type { nullable = resolved.isMarkedNullable, ) } - - /** - * Creates a [TypeRef] for a generic [List] - * @param element The type of elements in the list - */ - fun list(element: Type) = TypeRef(Pkg.Kotlin.Collections, "List", listOf(element)) - - /** - * Creates a [TypeRef] for a named Kotlin type (e.g., `String`) - */ - fun kotlin(name: String) = TypeRef(Pkg.Kotlin.Base, name) - - /** - * Creates a [TypeRef] for a generic [Map] - * @param key The type of keys in the map - * @param value The type of values in the map - */ - fun map(key: Type, value: Type) = TypeRef(Pkg.Kotlin.Collections, "Map", listOf(key, value)) - - /** - * Creates a [TypeRef] for a generic [Map] with [String] keys - * @param value The type of values in the map - */ - fun stringMap(value: Type) = map(Types.String, value) } /** @@ -101,45 +75,4 @@ public fun Type.nullable() = when { this is TypeRef -> copy(nullable = true) this is TypeVar -> copy(nullable = true) else -> error("Unknown Type ${this::class}") // Should be unreachable, only here to make compiler happy -} - -/** - * A container/factory object for various [Type] instances - */ -object Types { - // Kotlin standard types - val String = TypeRef("kotlin", "String") - val StringNullable = String.nullable() - - /** - * Creates a [TypeRef] for a generic [Map] with [String] keys - * @param value The type of values in the map - */ - fun stringMap(value: Type) = map(String, value) - - // Low-level types - val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") - val AttributeMap = Type.map(String, AttributeValue) - - // High-level types - val DynamoDbMapper = TypeRef(Pkg.Hl.Base, "DynamoDbMapper") - - val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") - fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) - val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") - val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") - - val Table = TypeRef(Pkg.Hl.Model, "Table") - val toItem = TypeRef(Pkg.Hl.Model, "toItem") - - val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") - val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") - val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") - val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") - val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") - - val DefaultInstantConverter = TypeRef(Pkg.Hl.Values, "InstantConverter.Default") - val BooleanConverter = TypeRef(Pkg.Hl.Values, "BooleanConverter") - val IntConverter = TypeRef(Pkg.Hl.Values, "IntConverter") - val StringConverter = TypeRef(Pkg.Hl.Values, "StringConverter") -} +} \ No newline at end of file diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt new file mode 100644 index 00000000000..662d4ef070c --- /dev/null +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt @@ -0,0 +1,37 @@ +package aws.sdk.kotlin.hll.codegen.model + +import aws.sdk.kotlin.hll.codegen.util.Pkg + +/** + * A container object for various [Type] instances + */ +object Types { + object Kotlin { + val String = TypeRef("kotlin", "String") + val StringNullable = String.nullable() + + /** + * Creates a [TypeRef] for a generic [List] + * @param element The type of elements in the list + */ + fun list(element: Type) = TypeRef(Pkg.Kotlin.Collections, "List", listOf(element)) + + /** + * Creates a [TypeRef] for a named Kotlin type (e.g., `String`) + */ + fun kotlin(name: String) = TypeRef(Pkg.Kotlin.Base, name) + + /** + * Creates a [TypeRef] for a generic [Map] + * @param key The type of keys in the map + * @param value The type of values in the map + */ + fun map(key: Type, value: Type) = TypeRef(Pkg.Kotlin.Collections, "Map", listOf(key, value)) + + /** + * Creates a [TypeRef] for a generic [Map] with [String] keys + * @param value The type of values in the map + */ + fun stringMap(value: Type) = map(String, value) + } +} \ No newline at end of file diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 488b3da0d46..e018a5ad1cc 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -6,12 +6,12 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type -import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.BuilderRenderer import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.DynamoDbMapperTypes import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.isAnnotationPresent @@ -50,7 +50,7 @@ public class SchemaRenderer( private fun renderBuilder() = BuilderRenderer(this, classDeclaration).render() private fun renderItemConverter() { - withBlock("public object #L : #T<#L> by #T(", ")", converterName, Types.ItemConverter, className, Types.SimpleItemConverter) { + withBlock("public object #L : #T<#L> by #T(", ")", converterName, DynamoDbMapperTypes.ItemConverter, className, DynamoDbMapperTypes.SimpleItemConverter) { write("builderFactory = ::#L,", builderName) write("build = #L::build,", builderName) withBlock("descriptors = arrayOf(", "),") { @@ -63,7 +63,7 @@ public class SchemaRenderer( } private fun renderAttributeDescriptor(prop: AnnotatedClassProperty) { - withBlock("#T(", "),", Types.AttributeDescriptor) { + withBlock("#T(", "),", DynamoDbMapperTypes.AttributeDescriptor) { write("#S,", prop.ddbName) // key write("#L,", "$className::${prop.name}") // getter write("#L,", "$builderName::${prop.name}::set") // setter @@ -73,19 +73,19 @@ public class SchemaRenderer( private val AnnotatedClassProperty.valueConverter: Type get() = when (typeName.asString()) { - "aws.smithy.kotlin.runtime.time.Instant" -> Types.DefaultInstantConverter - "kotlin.Boolean" -> Types.BooleanConverter - "kotlin.Int" -> Types.IntConverter - "kotlin.String" -> Types.StringConverter + "aws.smithy.kotlin.runtime.time.Instant" -> DynamoDbMapperTypes.DefaultInstantConverter + "kotlin.Boolean" -> DynamoDbMapperTypes.BooleanConverter + "kotlin.Int" -> DynamoDbMapperTypes.IntConverter + "kotlin.String" -> DynamoDbMapperTypes.StringConverter // TODO Add additional "standard" item converters else -> error("Unsupported attribute type ${typeName.asString()}") } private fun renderSchema() { - withBlock("public object #L : #T.#L<#L, #L> {", "}", schemaName, Types.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { + withBlock("public object #L : #T.#L<#L, #L> {", "}", schemaName, DynamoDbMapperTypes.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { write("override val converter : #1L = #1L", converterName) // TODO Handle composite keys - write("override val partitionKey: #1T<#2L> = #1T.#2L(#3S)", Types.KeySpec, keyProperty.keySpec, keyProperty.name) + write("override val partitionKey: #1T<#2L> = #1T.#2L(#3S)", DynamoDbMapperTypes.KeySpec, keyProperty.keySpec, keyProperty.name) } blankLine() } @@ -104,9 +104,9 @@ public class SchemaRenderer( } write( "public fun #1T.get#2LTable(name: String): #3T.#4L<#2L, #5L> = #6L(name, #7L)", - Types.DynamoDbMapper, + DynamoDbMapperTypes.DynamoDbMapper, className, - Types.Table, + DynamoDbMapperTypes.Table, "PartitionKey", keyProperty.typeName.getShortName(), "getTable", diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt new file mode 100644 index 00000000000..cdf339af27e --- /dev/null +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt @@ -0,0 +1,38 @@ +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model + +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.model.Types +import aws.sdk.kotlin.hll.codegen.util.Pkg + +/** + * A container object for various DynamoDbMapper [Type] instances + */ +object DynamoDbMapperTypes { + // Low-level types + val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") + val AttributeMap = Types.Kotlin.map(Types.Kotlin.String, AttributeValue) + + // High-level types + val DynamoDbMapper = TypeRef(Pkg.Hl.Base, "DynamoDbMapper") + + val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") + fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) + val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") + val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") + + val Table = TypeRef(Pkg.Hl.Model, "Table") + val toItem = TypeRef(Pkg.Hl.Model, "toItem") + + val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") + val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") + val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") + val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") + val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") + + val DefaultInstantConverter = TypeRef(Pkg.Hl.Values, "InstantConverter.Default") + val BooleanConverter = TypeRef(Pkg.Hl.Values, "BooleanConverter") + val IntConverter = TypeRef(Pkg.Hl.Values, "IntConverter") + val StringConverter = TypeRef(Pkg.Hl.Values, "StringConverter") +} \ No newline at end of file diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt index bfdb2953837..bd8382cebb0 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt @@ -4,13 +4,13 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model -import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.model.nullable import aws.sdk.kotlin.hll.codegen.util.Pkg +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.DynamoDbMapperTypes -private val attrMapTypes = setOf(Types.AttributeMap, Types.AttributeMap.nullable()) +private val attrMapTypes = setOf(DynamoDbMapperTypes.AttributeMap, DynamoDbMapperTypes.AttributeMap.nullable()) /** * Describes a behavior to apply for a given [Member] in a low-level structure when generating code for an equivalent @@ -78,37 +78,37 @@ val Member.codegenBehavior: MemberCodegenBehavior } private val Member.isTableName: Boolean - get() = name == "tableName" && type == Types.StringNullable + get() = name == "tableName" && type == Types.Kotlin.StringNullable private val Member.isIndexName: Boolean - get() = name == "indexName" && type == Types.StringNullable + get() = name == "indexName" && type == Types.Kotlin.StringNullable private fun llType(name: String) = TypeRef(Pkg.Ll.Model, name) private val unsupportedMembers = listOf( // superseded by ConditionExpression Member("conditionalOperator", llType("ConditionalOperator")), - Member("expected", Types.stringMap(llType("ExpectedAttributeValue"))), + Member("expected", Types.Kotlin.stringMap(llType("ExpectedAttributeValue"))), // superseded by FilterExpression - Member("queryFilter", Types.stringMap(llType("Condition"))), - Member("scanFilter", Types.stringMap(llType("Condition"))), + Member("queryFilter", Types.Kotlin.stringMap(llType("Condition"))), + Member("scanFilter", Types.Kotlin.stringMap(llType("Condition"))), // superseded by KeyConditionExpression - Member("keyConditions", Types.stringMap(llType("Condition"))), + Member("keyConditions", Types.Kotlin.stringMap(llType("Condition"))), // superseded by ProjectionExpression - Member("attributesToGet", Type.list(Types.String)), + Member("attributesToGet", Types.Kotlin.list(Types.Kotlin.String)), // superseded by UpdateExpression - Member("attributeUpdates", Types.stringMap(llType("AttributeValueUpdate"))), + Member("attributeUpdates", Types.Kotlin.stringMap(llType("AttributeValueUpdate"))), // TODO add support for expressions - Member("expressionAttributeNames", Types.stringMap(Types.String)), - Member("expressionAttributeValues", Types.AttributeMap), - Member("conditionExpression", Types.String), - Member("projectionExpression", Types.String), - Member("updateExpression", Types.String), + Member("expressionAttributeNames", Types.Kotlin.stringMap(Types.Kotlin.String)), + Member("expressionAttributeValues", DynamoDbMapperTypes.AttributeMap), + Member("conditionExpression", Types.Kotlin.String), + Member("projectionExpression", Types.Kotlin.String), + Member("updateExpression", Types.Kotlin.String), ).map { member -> if (member.type is TypeRef) { member.copy(type = member.type.nullable()) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt index a6fcb300a35..d14af86c388 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt @@ -9,6 +9,7 @@ import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.DynamoDbMapperTypes import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) @@ -49,13 +50,13 @@ class OperationRenderer( ")", factoryName, itemSourceKind.getSpecType("T"), - Types.Operation, + DynamoDbMapperTypes.Operation, ) { write( "initialize = { highLevelReq: #T -> #T(highLevelReq, spec.schema, #T(spec, #S)) },", operation.request.type, - Types.HReqContextImpl, - Types.MapperContextImpl, + DynamoDbMapperTypes.HReqContextImpl, + DynamoDbMapperTypes.MapperContextImpl, operation.name, ) @@ -85,7 +86,7 @@ class OperationRenderer( openBlock("private fun #T.convert(", operation.request.type) members(MemberCodegenBehavior.Hoist) { write("#L: #T, ", name, type) } - write("schema: #T,", Types.itemSchema("T")) + write("schema: #T,", DynamoDbMapperTypes.itemSchema("T")) closeAndOpenBlock(") = #L {", operation.request.lowLevelName) members(MemberCodegenBehavior.PassThrough) { write("#1L = this@convert.#1L", name) } members(MemberCodegenBehavior.MapKeys) { @@ -113,13 +114,13 @@ class OperationRenderer( "private fun #L.convert(schema: #T) = #T(", ")", operation.response.lowLevelName, - Types.itemSchema("T"), + DynamoDbMapperTypes.itemSchema("T"), operation.response.type, ) { members(MemberCodegenBehavior.PassThrough) { write("#1L = this@convert.#1L,", name) } members(MemberCodegenBehavior.MapKeys, MemberCodegenBehavior.MapAll) { - write("#1L = this@convert.#1L?.#2T()?.let(schema.converter::fromItem),", name, Types.toItem) + write("#1L = this@convert.#1L?.#2T()?.let(schema.converter::fromItem),", name, DynamoDbMapperTypes.toItem) } } } From 599c9b16ab44f0c3489fdbbdc6d8384ea11d45a1 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 10:10:15 -0400 Subject: [PATCH 35/59] ktlint --- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 2 +- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt | 2 +- hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts | 1 - .../hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt | 2 +- .../codegen/operations/rendering/OperationRenderer.kt | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 18e6a56bbb8..30b92199071 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -75,4 +75,4 @@ public fun Type.nullable() = when { this is TypeRef -> copy(nullable = true) this is TypeVar -> copy(nullable = true) else -> error("Unknown Type ${this::class}") // Should be unreachable, only here to make compiler happy -} \ No newline at end of file +} diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt index 662d4ef070c..43b0a611ab2 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt @@ -34,4 +34,4 @@ object Types { */ fun stringMap(value: Type) = map(String, value) } -} \ No newline at end of file +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts index 06ca496808a..ce2fc54758f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts @@ -7,7 +7,6 @@ description = "DynamoDbMapper code generation" extra["displayName"] = "AWS :: SDK :: Kotlin :: HLL :: DynamoDbMapper :: Codegen" extra["moduleName"] = "aws.sdk.kotlin.hll.dynamodbmapper.codegen" - plugins { alias(libs.plugins.kotlin.jvm) } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt index cdf339af27e..16d9449c509 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt @@ -35,4 +35,4 @@ object DynamoDbMapperTypes { val BooleanConverter = TypeRef(Pkg.Hl.Values, "BooleanConverter") val IntConverter = TypeRef(Pkg.Hl.Values, "IntConverter") val StringConverter = TypeRef(Pkg.Hl.Values, "StringConverter") -} \ No newline at end of file +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt index d14af86c388..509d1aefa6a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt @@ -5,7 +5,6 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.core.* -import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info From addb7c7bd217aef639dc7b388698006b1a06cc0c Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 11:25:34 -0400 Subject: [PATCH 36/59] Handle auto-import of nested types --- .../hll/codegen/core/TemplateProcessor.kt | 4 ++-- .../annotations/rendering/SchemaRenderer.kt | 24 ++++++++++++------- .../codegen/model/DynamoDbMapperTypes.kt | 7 +++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt index 42c5fb4f1fe..f763c092af3 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt @@ -72,10 +72,10 @@ private open class TypeProcessor { private class ImportingTypeProcessor(private val pkg: String, private val imports: ImportDirectives) : TypeProcessor() { override fun format(type: Type): String = buildString { if (type is TypeRef && type.pkg != pkg) { - val existingImport = imports[type.shortName] + val existingImport = imports[type.shortName.substringBefore(".")] if (existingImport == null) { - imports += ImportDirective(type) + imports += ImportDirective(type.copy(shortName = type.shortName.substringBefore("."))) } else if (existingImport.fullName != type.fullName) { append(type.pkg) append('.') diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index e018a5ad1cc..f5442f7306a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -6,6 +6,7 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.rendering.BuilderRenderer import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase @@ -29,6 +30,12 @@ public class SchemaRenderer( private val ctx: RenderContext, ) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema", "dynamodb-mapper-annotation-processor") { private val className = classDeclaration.qualifiedName!!.getShortName() + private val classType = Type.from( + checkNotNull(classDeclaration.primaryConstructor?.returnType) { + "Failed to determine class type for $className" + }, + ) + private val builderName = "${className}Builder" private val converterName = "${className}Converter" private val schemaName = "${className}Schema" @@ -102,20 +109,20 @@ public class SchemaRenderer( withDocs { write("Returns a reference to a table named [name] containing items representing [#L]", className) } + + val fnName = "get${className}Table" write( - "public fun #1T.get#2LTable(name: String): #3T.#4L<#2L, #5L> = #6L(name, #7L)", + "public fun #T.#L(name: String): #T = #L(name, #L)", DynamoDbMapperTypes.DynamoDbMapper, - className, - DynamoDbMapperTypes.Table, - "PartitionKey", - keyProperty.typeName.getShortName(), + fnName, + DynamoDbMapperTypes.tablePartitionKey(classType, keyProperty.typeRef), "getTable", - schemaName, + schemaName ) } } -private data class AnnotatedClassProperty(val name: String, val ddbName: String, val typeName: KSName, val isPk: Boolean) { +private data class AnnotatedClassProperty(val name: String, val typeRef: TypeRef, val ddbName: String, val typeName: KSName, val isPk: Boolean) { companion object { @OptIn(KspExperimental::class) fun from(ksProperty: KSPropertyDeclaration) = ksProperty @@ -127,8 +134,9 @@ private data class AnnotatedClassProperty(val name: String, val ddbName: String, ?.let { typeName -> val isPk = ksProperty.isAnnotationPresent(DynamoDbPartitionKey::class) val name = ksProperty.simpleName.getShortName() + val typeRef = Type.from(checkNotNull(ksProperty.type) { "Failed to determine class type for $name" }) val ddbName = ksProperty.getAnnotationsByType(DynamoDbAttribute::class).singleOrNull()?.name ?: name - AnnotatedClassProperty(name, ddbName, typeName, isPk) + AnnotatedClassProperty(name, typeRef, ddbName, typeName, isPk) } } } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt index 16d9449c509..3279da930bd 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt @@ -22,7 +22,12 @@ object DynamoDbMapperTypes { val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") - val Table = TypeRef(Pkg.Hl.Model, "Table") + + fun tablePartitionKey(objectType: TypeRef, partitionKeyType: TypeRef) = TypeRef( + Pkg.Hl.Model, + "Table.PartitionKey", + genericArgs = listOf(objectType, partitionKeyType) + ) val toItem = TypeRef(Pkg.Hl.Model, "toItem") val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") From 69b7c5fb3fbb53d042b8099f136a4e25e88a5896 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 11:25:50 -0400 Subject: [PATCH 37/59] ktlint --- .../codegen/annotations/rendering/SchemaRenderer.kt | 2 +- .../hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index f5442f7306a..19d8bfbab77 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -117,7 +117,7 @@ public class SchemaRenderer( fnName, DynamoDbMapperTypes.tablePartitionKey(classType, keyProperty.typeRef), "getTable", - schemaName + schemaName, ) } } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt index 3279da930bd..d27b6361cdc 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt @@ -22,11 +22,10 @@ object DynamoDbMapperTypes { val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") - fun tablePartitionKey(objectType: TypeRef, partitionKeyType: TypeRef) = TypeRef( Pkg.Hl.Model, "Table.PartitionKey", - genericArgs = listOf(objectType, partitionKeyType) + genericArgs = listOf(objectType, partitionKeyType), ) val toItem = TypeRef(Pkg.Hl.Model, "toItem") From f010bb58b93ed44893caa41d16eef3746d420cd2 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 12:36:12 -0400 Subject: [PATCH 38/59] Fix typo in KDocs --- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 30b92199071..a37805f1f90 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -44,7 +44,7 @@ sealed interface Type { * representing [kotlin.collections.List] would have a single generic argument, which may either be a concrete [TypeRef] * itself (e.g., `List`) or a generic [TypeVar] (e.g., `List`). * @param pkg The Kotlin package for this type - * @param shortName The short name (i.e., not include the kotlin package) for this type + * @param shortName The short name (i.e., not including the kotlin package) for this type * @param genericArgs Zero or more [Type] generic arguments to this type * @param nullable Indicates whether instances of this type allow nullable references */ From 42aebb2fe10fd8bd499561977ee07a944d69552b Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 12:45:53 -0400 Subject: [PATCH 39/59] Replace more #L with #T --- hll/codegen/api/codegen.api | 1 + .../aws/sdk/kotlin/hll/codegen/model/Types.kt | 1 + .../annotations/rendering/SchemaRenderer.kt | 21 +++++++++++++------ .../codegen/model/DynamoDbMapperTypes.kt | 9 ++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 1aff5ed4bb2..043c7e55f0f 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -162,6 +162,7 @@ public final class aws/sdk/kotlin/hll/codegen/model/Types { public final class aws/sdk/kotlin/hll/codegen/model/Types$Kotlin { public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types$Kotlin; + public final fun getNumber ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun getStringNullable ()Laws/sdk/kotlin/hll/codegen/model/Type; public final fun kotlin (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt index 43b0a611ab2..198b3d08df2 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt @@ -8,6 +8,7 @@ import aws.sdk.kotlin.hll.codegen.util.Pkg object Types { object Kotlin { val String = TypeRef("kotlin", "String") + val Number = TypeRef("kotlin", "Number") val StringNullable = String.nullable() /** diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 19d8bfbab77..1e14e5f3fcd 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -7,6 +7,7 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.rendering.BuilderRenderer import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase @@ -57,7 +58,7 @@ public class SchemaRenderer( private fun renderBuilder() = BuilderRenderer(this, classDeclaration).render() private fun renderItemConverter() { - withBlock("public object #L : #T<#L> by #T(", ")", converterName, DynamoDbMapperTypes.ItemConverter, className, DynamoDbMapperTypes.SimpleItemConverter) { + withBlock("public object #L : #T by #T(", ")", converterName, DynamoDbMapperTypes.itemConverter(classType), DynamoDbMapperTypes.SimpleItemConverter) { write("builderFactory = ::#L,", builderName) write("build = #L::build,", builderName) withBlock("descriptors = arrayOf(", "),") { @@ -89,18 +90,26 @@ public class SchemaRenderer( } private fun renderSchema() { - withBlock("public object #L : #T.#L<#L, #L> {", "}", schemaName, DynamoDbMapperTypes.ItemSchema, "PartitionKey", className, keyProperty.typeName.getShortName()) { + withBlock("public object #L : #T {", "}", schemaName, DynamoDbMapperTypes.itemSchemaPartitionKey(classType, keyProperty.typeRef)) { write("override val converter : #1L = #1L", converterName) // TODO Handle composite keys - write("override val partitionKey: #1T<#2L> = #1T.#2L(#3S)", DynamoDbMapperTypes.KeySpec, keyProperty.keySpec, keyProperty.name) + write("override val partitionKey: #T = #T(#S)", DynamoDbMapperTypes.keySpec(keyProperty.keySpec), keyProperty.keySpecType, keyProperty.name) } blankLine() } - private val AnnotatedClassProperty.keySpec: String + private val AnnotatedClassProperty.keySpec: TypeRef get() = when (typeName.asString()) { - "kotlin.Int" -> "Number" - "kotlin.String" -> "String" + "kotlin.Int" -> Types.Kotlin.Number + "kotlin.String" -> Types.Kotlin.String + // TODO Handle ByteArray + else -> error("Unsupported key type ${typeName.asString()}, expected Int or String") + } + + private val AnnotatedClassProperty.keySpecType: TypeRef + get() = when (typeName.asString()) { + "kotlin.Int" -> DynamoDbMapperTypes.KeySpecNumber + "kotlin.String" -> DynamoDbMapperTypes.KeySpecString // TODO Handle ByteArray else -> error("Unsupported key type ${typeName.asString()}, expected Int or String") } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt index d27b6361cdc..02b82b05f55 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt @@ -19,20 +19,25 @@ object DynamoDbMapperTypes { val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) + fun itemSchemaPartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemSchema.PartitionKey", listOf(objectType, keyType)) val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") - fun tablePartitionKey(objectType: TypeRef, partitionKeyType: TypeRef) = TypeRef( + fun tablePartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef( Pkg.Hl.Model, "Table.PartitionKey", - genericArgs = listOf(objectType, partitionKeyType), + genericArgs = listOf(objectType, keyType), ) val toItem = TypeRef(Pkg.Hl.Model, "toItem") val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") + fun keySpec(keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "KeySpec", genericArgs = listOf(keyType)) + val KeySpecNumber = TypeRef(Pkg.Hl.Items, "KeySpec.Number") + val KeySpecString = TypeRef(Pkg.Hl.Items, "KeySpec.String") val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") + fun itemConverter(objectType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemConverter", genericArgs = listOf(objectType)) val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") val DefaultInstantConverter = TypeRef(Pkg.Hl.Values, "InstantConverter.Default") From 1788f2ae8012f6a90facd4bb1fdb7bef0f6cd5e7 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 12:48:42 -0400 Subject: [PATCH 40/59] Replace more #L with #T --- .../sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index 5e42626097f..034e322ef67 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -1,6 +1,7 @@ package aws.sdk.kotlin.hll.codegen.rendering import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef import com.google.devtools.ksp.symbol.* /** @@ -28,7 +29,7 @@ class BuilderRenderer( withBlock("public class #L {", "}", "${className}Builder") { properties.forEach { - write("public var #L: #L? = null", it.name, it.typeName.asString()) + write("public var #L: #T? = null", it.name, it.typeRef) } blankLine() @@ -52,16 +53,17 @@ class BuilderRenderer( } } -private data class KSClassProperty(val name: String, val typeName: KSName, val nullable: Boolean) { +private data class KSClassProperty(val name: String, val typeRef: TypeRef, val typeName: KSName, val nullable: Boolean) { companion object { fun from(ksProperty: KSPropertyDeclaration): KSClassProperty? { val type: KSType = ksProperty.getter?.returnType?.resolve() ?: return null val name = ksProperty.simpleName.getShortName() + val typeRef = Type.from(checkNotNull(ksProperty.type) { "Failed to determine class type for $name" }) val typeName = type.declaration.qualifiedName ?: return null val nullable = type.nullability != Nullability.NOT_NULL - return KSClassProperty(name, typeName, nullable) + return KSClassProperty(name, typeRef, typeName, nullable) } } } From 5a39f82f8c47a7deed29b3e712221a9c27b15920 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 12:48:59 -0400 Subject: [PATCH 41/59] Don't explicitly import types from the `kotlin` namespace --- .../kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt index f763c092af3..cc80bf883c8 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt @@ -71,7 +71,7 @@ private open class TypeProcessor { private class ImportingTypeProcessor(private val pkg: String, private val imports: ImportDirectives) : TypeProcessor() { override fun format(type: Type): String = buildString { - if (type is TypeRef && type.pkg != pkg) { + if (type is TypeRef && type.pkg != pkg && type.pkg != "kotlin") { val existingImport = imports[type.shortName.substringBefore(".")] if (existingImport == null) { From e63b9e16fc3146ff787971cea285d2ec24ca8bab Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 12:51:42 -0400 Subject: [PATCH 42/59] Remove explicit import on user class --- .../codegen/annotations/rendering/SchemaRenderer.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 1e14e5f3fcd..4d68b91d339 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -47,7 +47,6 @@ public class SchemaRenderer( } override fun generate() { - imports.add(ImportDirective(classDeclaration.qualifiedName!!.asString())) renderBuilder() renderItemConverter() renderSchema() From b68fa5ede4d31749c2f1a3fb890cf076b0367d87 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 14 Aug 2024 12:53:11 -0400 Subject: [PATCH 43/59] ktlint --- .../codegen/annotations/rendering/SchemaRenderer.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 4d68b91d339..ac5505b8269 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -4,7 +4,6 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering -import aws.sdk.kotlin.hll.codegen.core.ImportDirective import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Types From 5d698ca12b8a1e2d27ed94598d370d7c74ce5f23 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 09:51:07 -0400 Subject: [PATCH 44/59] Use `kotlin` function --- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt index 198b3d08df2..adeec1700db 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt @@ -7,8 +7,8 @@ import aws.sdk.kotlin.hll.codegen.util.Pkg */ object Types { object Kotlin { - val String = TypeRef("kotlin", "String") - val Number = TypeRef("kotlin", "Number") + val String = kotlin( "String") + val Number = kotlin("Number") val StringNullable = String.nullable() /** From 5c2915e99c2db2d7a8b7b377061862ad8c7cdc32 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 10:00:11 -0400 Subject: [PATCH 45/59] Add two new Type.from methods --- .../aws/sdk/kotlin/hll/codegen/model/Type.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index a37805f1f90..c8507a871b2 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -4,6 +4,8 @@ */ package aws.sdk.kotlin.hll.codegen.model +import com.google.devtools.ksp.symbol.KSClassDeclaration +import com.google.devtools.ksp.symbol.KSType import com.google.devtools.ksp.symbol.KSTypeReference /** @@ -11,17 +13,26 @@ import com.google.devtools.ksp.symbol.KSTypeReference */ sealed interface Type { companion object { + /** + * Derives a [TypeRef] from a [KSClassDeclaration] + */ + fun from(ksClassDeclaration: KSClassDeclaration): TypeRef = from(ksClassDeclaration.asStarProjectedType()) + /** * Derives a [TypeRef] from a [KSTypeReference] */ - fun from(ksTypeRef: KSTypeReference): TypeRef { - val resolved = ksTypeRef.resolve() - val name = resolved.declaration.qualifiedName!! + fun from(ksTypeRef: KSTypeReference): TypeRef = from(ksTypeRef.resolve()) + + /** + * Derives a [TypeRef] from a [KSType] + */ + fun from(ksType: KSType): TypeRef { + val name = ksType.declaration.qualifiedName!! return TypeRef( pkg = name.getQualifier(), shortName = name.getShortName(), - genericArgs = resolved.arguments.map { from(it.type!!) }, - nullable = resolved.isMarkedNullable, + genericArgs = ksType.arguments.map { from(it.type!!) }, + nullable = ksType.isMarkedNullable, ) } } From 98b59fbd0f01d4dc59e77db4075f75583eef2754 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 10:06:44 -0400 Subject: [PATCH 46/59] Use #T in builder docs --- .../sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index 034e322ef67..15299f0c7e0 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -16,15 +16,11 @@ class BuilderRenderer( private val properties = classDeclaration.getAllProperties().mapNotNull(KSClassProperty.Companion::from) private val className = classDeclaration.qualifiedName!!.getShortName() - private val classType = Type.from( - checkNotNull(classDeclaration.primaryConstructor?.returnType) { - "Failed to determine class type for $className" - }, - ) + private val classType = Type.from(classDeclaration) fun render() = renderer.use { withDocs { - write("A DSL-style builder for instances of [#L]", className) + write("A DSL-style builder for instances of [#T]", classType) } withBlock("public class #L {", "}", "${className}Builder") { From c97152031b5afd2b47169a14dbd6d4711c064784 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 10:06:54 -0400 Subject: [PATCH 47/59] classType = Type.from(classDeclaration) --- .../codegen/annotations/rendering/SchemaRenderer.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index ac5505b8269..91b808534b4 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -30,11 +30,7 @@ public class SchemaRenderer( private val ctx: RenderContext, ) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema", "dynamodb-mapper-annotation-processor") { private val className = classDeclaration.qualifiedName!!.getShortName() - private val classType = Type.from( - checkNotNull(classDeclaration.primaryConstructor?.returnType) { - "Failed to determine class type for $className" - }, - ) + private val classType = Type.from(classDeclaration) private val builderName = "${className}Builder" private val converterName = "${className}Converter" From 881a7a81e81559090f0250fa4da790dbb133a15d Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 10:07:00 -0400 Subject: [PATCH 48/59] apiDump --- hll/codegen/api/codegen.api | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index 043c7e55f0f..de993ebfea4 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -116,6 +116,8 @@ public abstract interface class aws/sdk/kotlin/hll/codegen/model/Type { } public final class aws/sdk/kotlin/hll/codegen/model/Type$Companion { + public final fun from (Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; + public final fun from (Lcom/google/devtools/ksp/symbol/KSType;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; public final fun from (Lcom/google/devtools/ksp/symbol/KSTypeReference;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; } From f4f399a9dede031de164104b6291e216a2a726a1 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 10:16:18 -0400 Subject: [PATCH 49/59] Move `rendererName` to `renderCtx` --- hll/codegen/api/codegen.api | 12 +++++++----- .../kotlin/hll/codegen/rendering/RenderContext.kt | 2 +- .../sdk/kotlin/hll/codegen/rendering/RendererBase.kt | 3 +-- .../annotations/rendering/HighLevelRenderer.kt | 2 +- .../codegen/annotations/rendering/SchemaRenderer.kt | 2 +- .../codegen/operations/HighLevelOpsProcessor.kt | 2 +- .../operations/rendering/OperationRenderer.kt | 2 +- .../operations/rendering/OperationsTypeRenderer.kt | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api index de993ebfea4..99d9ac31776 100644 --- a/hll/codegen/api/codegen.api +++ b/hll/codegen/api/codegen.api @@ -179,16 +179,19 @@ public final class aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer { } public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContext { - public fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;)V + public fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;)V + public synthetic fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Lcom/google/devtools/ksp/processing/KSPLogger; public final fun component2 ()Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory; public final fun component3 ()Ljava/lang/String; - public final fun copy (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; + public final fun component4 ()Ljava/lang/String; + public final fun copy (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; + public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; public fun equals (Ljava/lang/Object;)Z public final fun getCodegenFactory ()Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory; public final fun getLogger ()Lcom/google/devtools/ksp/processing/KSPLogger; public final fun getPkg ()Ljava/lang/String; + public final fun getRendererName ()Ljava/lang/String; public fun hashCode ()I public fun toString ()Ljava/lang/String; } @@ -206,8 +209,7 @@ public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContextKt { } public abstract class aws/sdk/kotlin/hll/codegen/rendering/RendererBase : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;)V public fun blankLine ()V public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt index fe7d30e3a3d..dc6ff2cccb3 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt @@ -15,7 +15,7 @@ import com.google.devtools.ksp.symbol.KSNode * @param codegenFactory A factory that creates code generator instances for specific files * @param pkg The Kotlin package for the generated code (e.g., `aws.sdk.kotlin.hll.dynamodbmapper.operations`) */ -data class RenderContext(val logger: KSPLogger, val codegenFactory: CodeGeneratorFactory, val pkg: String) +data class RenderContext(val logger: KSPLogger, val codegenFactory: CodeGeneratorFactory, val pkg: String, val rendererName: String = "aws-sdk-kotlin-hll-codegen") fun RenderContext.logging(message: String, symbol: KSNode? = null) = logger.logging(message, symbol) fun RenderContext.info(message: String, symbol: KSNode? = null) = logger.info(message, symbol) diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt index c7715aa2ec2..5d758f9269d 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt @@ -15,8 +15,7 @@ import aws.sdk.kotlin.hll.codegen.core.CodeGenerator abstract class RendererBase( ctx: RenderContext, fileName: String, - rendererName: String = "aws-sdk-kotlin-hll-codegen", -) : CodeGenerator by ctx.codegenFactory.generator(fileName, ctx.pkg, rendererName) { +) : CodeGenerator by ctx.codegenFactory.generator(fileName, ctx.pkg, ctx.rendererName) { /** * Run this renderer by calling the `abstract` [generate] method and then [persist] */ diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt index dc72b347d43..0a104081d61 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt @@ -21,7 +21,7 @@ public class HighLevelRenderer( public fun render() { annotatedClasses.forEach { logger.info("Processing annotation on ${it.simpleName}") - val renderCtx = RenderContext(logger, codegenFactory, "${it.packageName.asString()}.mapper.schemas") + val renderCtx = RenderContext(logger, codegenFactory, "${it.packageName.asString()}.mapper.schemas", "dynamodb-mapper-annotation-processor") val annotation = SchemaRenderer(it, renderCtx) annotation.render() } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 91b808534b4..f2925e7e27f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -28,7 +28,7 @@ import com.google.devtools.ksp.symbol.KSPropertyDeclaration public class SchemaRenderer( private val classDeclaration: KSClassDeclaration, private val ctx: RenderContext, -) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema", "dynamodb-mapper-annotation-processor") { +) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema") { private val className = classDeclaration.qualifiedName!!.getShortName() private val classType = Type.from(classDeclaration) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt index 19eec2ec84f..83c5aab8db8 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/HighLevelOpsProcessor.kt @@ -37,7 +37,7 @@ class HighLevelOpsProcessor(environment: SymbolProcessorEnvironment) : SymbolPro val operations = getOperations(resolver) val codegenFactory = CodeGeneratorFactory(codeGenerator, logger) - val ctx = RenderContext(logger, codegenFactory, pkg) + val ctx = RenderContext(logger, codegenFactory, pkg, "dynamodb-mapper-ops-codegen") HighLevelRenderer(ctx, operations).render() } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt index 509d1aefa6a..b70917bae8c 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt @@ -22,7 +22,7 @@ import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.* class OperationRenderer( private val ctx: RenderContext, val operation: Operation, -) : RendererBase(ctx, operation.name, "dynamodb-mapper-ops-codegen") { +) : RendererBase(ctx, operation.name) { val members = operation.request.lowLevel.members.groupBy { m -> m.codegenBehavior.also { ctx.info(" ${m.name} → $it") } } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt index 71c8863adc3..0f05ad1607f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationsTypeRenderer.kt @@ -29,7 +29,7 @@ class OperationsTypeRenderer( val itemSourceKind: ItemSourceKind, val parentType: Type?, val operations: List, -) : RendererBase(ctx, "${itemSourceKind.name}Operations", "dynamodb-mapper-ops-codegen") { +) : RendererBase(ctx, "${itemSourceKind.name}Operations") { private val entityName = itemSourceKind.name.lowercaseFirstChar private val intfName = "${itemSourceKind.name}Operations" From 9c63c4784c38c4cd717587640f942f80bbfdd24b Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 11:02:35 -0400 Subject: [PATCH 50/59] Add single-line `docs(...)` function and fix API validation settings --- hll/build.gradle.kts | 1 + hll/codegen/api/codegen.api | 270 ------------------ .../kotlin/hll/codegen/core/CodeGenerator.kt | 9 + .../hll/codegen/rendering/BuilderRenderer.kt | 8 +- .../hll/codegen/rendering/RendererBase.kt | 7 - .../api/dynamodb-mapper-codegen.api | 215 -------------- .../annotations/rendering/SchemaRenderer.kt | 4 +- 7 files changed, 14 insertions(+), 500 deletions(-) delete mode 100644 hll/codegen/api/codegen.api delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api diff --git a/hll/build.gradle.kts b/hll/build.gradle.kts index f67d3f5d661..c408f063a25 100644 --- a/hll/build.gradle.kts +++ b/hll/build.gradle.kts @@ -87,6 +87,7 @@ apiValidation { val availableSubprojects = subprojects.map { it.name }.toSet() ignoredProjects += listOf( + "codegen", "dynamodb-mapper-annotation-processor-test", "dynamodb-mapper-codegen", ).filter { it in availableSubprojects } // Some projects may not be in the build depending on bootstrapping diff --git a/hll/codegen/api/codegen.api b/hll/codegen/api/codegen.api deleted file mode 100644 index 99d9ac31776..00000000000 --- a/hll/codegen/api/codegen.api +++ /dev/null @@ -1,270 +0,0 @@ -public abstract interface class aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public abstract fun blankLine ()V - public abstract fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public abstract fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public abstract fun dedent (I)V - public abstract fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; - public abstract fun indent (I)V - public abstract fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public abstract fun persist ()V - public abstract fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V - public abstract fun withDocs (Lkotlin/jvm/functions/Function0;)V - public abstract fun write (Ljava/lang/String;[Ljava/lang/Object;)V - public abstract fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V -} - -public final class aws/sdk/kotlin/hll/codegen/core/CodeGenerator$DefaultImpls { - public static synthetic fun dedent$default (Laws/sdk/kotlin/hll/codegen/core/CodeGenerator;IILjava/lang/Object;)V - public static synthetic fun indent$default (Laws/sdk/kotlin/hll/codegen/core/CodeGenerator;IILjava/lang/Object;)V -} - -public final class aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory { - public fun (Lcom/google/devtools/ksp/processing/CodeGenerator;Lcom/google/devtools/ksp/processing/KSPLogger;)V - public final fun generator (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/CodeGenerator; -} - -public final class aws/sdk/kotlin/hll/codegen/core/CodeGeneratorImpl : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;Ljava/lang/String;)V - public synthetic fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/TemplateEngine;Lkotlin/jvm/functions/Function1;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public fun blankLine ()V - public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun dedent (I)V - public fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; - public fun indent (I)V - public fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun persist ()V - public fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V - public fun withDocs (Lkotlin/jvm/functions/Function0;)V - public fun write (Ljava/lang/String;[Ljava/lang/Object;)V - public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V -} - -public final class aws/sdk/kotlin/hll/codegen/core/ImportDirective { - public fun (Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Ljava/lang/String; - public final fun component2 ()Ljava/lang/String; - public final fun copy (Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; - public fun equals (Ljava/lang/Object;)Z - public final fun getAlias ()Ljava/lang/String; - public final fun getFormatted ()Ljava/lang/String; - public final fun getFullName ()Ljava/lang/String; - public final fun getShortName ()Ljava/lang/String; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/core/ImportDirectives : java/util/Set, kotlin/jvm/internal/markers/KMutableSet { - public fun ()V - public fun add (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z - public synthetic fun add (Ljava/lang/Object;)Z - public fun addAll (Ljava/util/Collection;)Z - public fun clear ()V - public fun contains (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z - public final fun contains (Ljava/lang/Object;)Z - public fun containsAll (Ljava/util/Collection;)Z - public final fun get (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; - public final fun getFormatted ()Ljava/lang/String; - public fun getSize ()I - public fun isEmpty ()Z - public fun iterator ()Ljava/util/Iterator; - public fun remove (Laws/sdk/kotlin/hll/codegen/core/ImportDirective;)Z - public final fun remove (Ljava/lang/Object;)Z - public fun removeAll (Ljava/util/Collection;)Z - public fun retainAll (Ljava/util/Collection;)Z - public final fun size ()I - public fun toArray ()[Ljava/lang/Object; - public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object; -} - -public final class aws/sdk/kotlin/hll/codegen/core/ImportDirectivesKt { - public static final fun ImportDirective (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; - public static synthetic fun ImportDirective$default (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/core/ImportDirective; -} - -public final class aws/sdk/kotlin/hll/codegen/core/TemplateEngine { - public fun (Ljava/util/List;)V - public final fun process (Ljava/lang/String;Ljava/util/List;)Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/core/TemplateProcessor { - public static final field Companion Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor$Companion; - public fun (CLkotlin/jvm/functions/Function1;)V - public final fun component1 ()C - public final fun component2 ()Lkotlin/jvm/functions/Function1; - public final fun copy (CLkotlin/jvm/functions/Function1;)Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor;CLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; - public fun equals (Ljava/lang/Object;)Z - public final fun getHandler ()Lkotlin/jvm/functions/Function1; - public final fun getKey ()C - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/core/TemplateProcessor$Companion { - public final fun forType (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/core/ImportDirectives;)Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; - public final fun getLiteral ()Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; - public final fun getQuotedString ()Laws/sdk/kotlin/hll/codegen/core/TemplateProcessor; -} - -public abstract interface class aws/sdk/kotlin/hll/codegen/model/Type { - public static final field Companion Laws/sdk/kotlin/hll/codegen/model/Type$Companion; - public abstract fun getNullable ()Z - public abstract fun getShortName ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/model/Type$Companion { - public final fun from (Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun from (Lcom/google/devtools/ksp/symbol/KSType;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun from (Lcom/google/devtools/ksp/symbol/KSTypeReference;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; -} - -public final class aws/sdk/kotlin/hll/codegen/model/TypeKt { - public static final fun nullable (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/Type; -} - -public final class aws/sdk/kotlin/hll/codegen/model/TypeRef : aws/sdk/kotlin/hll/codegen/model/Type { - public fun (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)V - public synthetic fun (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Ljava/lang/String; - public final fun component2 ()Ljava/lang/String; - public final fun component3 ()Ljava/util/List; - public final fun component4 ()Z - public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;Z)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;ZILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public fun equals (Ljava/lang/Object;)Z - public final fun getFullName ()Ljava/lang/String; - public final fun getGenericArgs ()Ljava/util/List; - public fun getNullable ()Z - public final fun getPkg ()Ljava/lang/String; - public fun getShortName ()Ljava/lang/String; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/model/TypeVar : aws/sdk/kotlin/hll/codegen/model/Type { - public fun (Ljava/lang/String;Z)V - public synthetic fun (Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Ljava/lang/String; - public final fun component2 ()Z - public final fun copy (Ljava/lang/String;Z)Laws/sdk/kotlin/hll/codegen/model/TypeVar; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/model/TypeVar;Ljava/lang/String;ZILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/model/TypeVar; - public fun equals (Ljava/lang/Object;)Z - public fun getNullable ()Z - public fun getShortName ()Ljava/lang/String; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/model/Types { - public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types; -} - -public final class aws/sdk/kotlin/hll/codegen/model/Types$Kotlin { - public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/model/Types$Kotlin; - public final fun getNumber ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getString ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getStringNullable ()Laws/sdk/kotlin/hll/codegen/model/Type; - public final fun kotlin (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun list (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun map (Laws/sdk/kotlin/hll/codegen/model/Type;Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun stringMap (Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; -} - -public final class aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RendererBase;Lcom/google/devtools/ksp/symbol/KSClassDeclaration;)V - public final fun render ()V -} - -public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContext { - public fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;)V - public synthetic fun (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Lcom/google/devtools/ksp/processing/KSPLogger; - public final fun component2 ()Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory; - public final fun component3 ()Ljava/lang/String; - public final fun component4 ()Ljava/lang/String; - public final fun copy (Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Laws/sdk/kotlin/hll/codegen/rendering/RenderContext; - public fun equals (Ljava/lang/Object;)Z - public final fun getCodegenFactory ()Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory; - public final fun getLogger ()Lcom/google/devtools/ksp/processing/KSPLogger; - public final fun getPkg ()Ljava/lang/String; - public final fun getRendererName ()Ljava/lang/String; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/rendering/RenderContextKt { - public static final fun error (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V - public static synthetic fun error$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V - public static final fun exception (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/Throwable;)V - public static final fun info (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V - public static synthetic fun info$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V - public static final fun logging (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V - public static synthetic fun logging$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V - public static final fun warn (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;)V - public static synthetic fun warn$default (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;Lcom/google/devtools/ksp/symbol/KSNode;ILjava/lang/Object;)V -} - -public abstract class aws/sdk/kotlin/hll/codegen/rendering/RendererBase : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/lang/String;)V - public fun blankLine ()V - public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun dedent (I)V - protected abstract fun generate ()V - public fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; - public fun indent (I)V - public fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun persist ()V - public final fun render ()V - public fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V - public fun withDocs (Lkotlin/jvm/functions/Function0;)V - public fun write (Ljava/lang/String;[Ljava/lang/Object;)V - public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V -} - -public final class aws/sdk/kotlin/hll/codegen/rendering/RendererBaseKt { - public static final fun use (Laws/sdk/kotlin/hll/codegen/rendering/RendererBase;Lkotlin/jvm/functions/Function1;)V -} - -public final class aws/sdk/kotlin/hll/codegen/util/AttributesExtKt { - public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/smithy/kotlin/runtime/collections/Attributes; - public static final fun plus (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/Pair;)Laws/smithy/kotlin/runtime/collections/Attributes; -} - -public final class aws/sdk/kotlin/hll/codegen/util/Pkg { - public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg; -} - -public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Hl { - public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg$Hl; - public final fun getBase ()Ljava/lang/String; - public final fun getItems ()Ljava/lang/String; - public final fun getModel ()Ljava/lang/String; - public final fun getOps ()Ljava/lang/String; - public final fun getPipelineImpl ()Ljava/lang/String; - public final fun getValues ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Kotlin { - public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg$Kotlin; - public final fun getBase ()Ljava/lang/String; - public final fun getCollections ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/util/Pkg$Ll { - public static final field INSTANCE Laws/sdk/kotlin/hll/codegen/util/Pkg$Ll; - public final fun getBase ()Ljava/lang/String; - public final fun getModel ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/codegen/util/StringsKt { - public static final fun escape (Ljava/lang/String;)Ljava/lang/String; - public static final fun getCapitalizeFirstChar (Ljava/lang/String;)Ljava/lang/String; - public static final fun getLowercaseFirstChar (Ljava/lang/String;)Ljava/lang/String; - public static final fun quote (Ljava/lang/String;)Ljava/lang/String; -} - diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt index 011bf14cf99..346599e6c73 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt @@ -105,6 +105,13 @@ interface CodeGenerator { */ fun withDocs(block: () -> Unit) + /** + * Writes a single line of documentation, wrapping it with KDoc-style comment tokens. + * @param template The templated string of documentation to write + * @param args The arguments to the templated string, if any + */ + fun docs(template: String, vararg args: Any) + /** * Writes a line of text, including a terminating newline (i.e., `\n`) * @param template The string template or literal to append @@ -212,6 +219,8 @@ class CodeGeneratorImpl( write(" */") } + override fun docs(template: String, vararg args: Any) = withDocs { write(template, *args) } + override fun write(template: String, vararg args: Any) { writeInline(template, *args) builder.append('\n') diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index 15299f0c7e0..e8ee2c4b1e7 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -16,12 +16,10 @@ class BuilderRenderer( private val properties = classDeclaration.getAllProperties().mapNotNull(KSClassProperty.Companion::from) private val className = classDeclaration.qualifiedName!!.getShortName() - private val classType = Type.from(classDeclaration) + private val classType: TypeRef = Type.from(classDeclaration) - fun render() = renderer.use { - withDocs { - write("A DSL-style builder for instances of [#T]", classType) - } + fun render() = renderer.apply { + docs("A DSL-style builder for instances of [#T]", classType) withBlock("public class #L {", "}", "${className}Builder") { properties.forEach { diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt index 5d758f9269d..566f278f9c4 100644 --- a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt +++ b/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt @@ -26,10 +26,3 @@ abstract class RendererBase( protected abstract fun generate() } - -/** - * Use an instance of [RendererBase] to execute a [block] - */ -fun RendererBase.use(block: RendererBase.() -> Unit) { - block() -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api b/hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api deleted file mode 100644 index d8ffbc07eed..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/api/dynamodb-mapper-codegen.api +++ /dev/null @@ -1,215 +0,0 @@ -public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor : com/google/devtools/ksp/processing/SymbolProcessor { - public fun (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)V - public fun process (Lcom/google/devtools/ksp/processing/Resolver;)Ljava/util/List; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessorProvider : com/google/devtools/ksp/processing/SymbolProcessorProvider { - public fun ()V - public fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Laws/sdk/kotlin/hll/dynamodbmapper/annotations/AnnotationsProcessor; - public synthetic fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Lcom/google/devtools/ksp/processing/SymbolProcessor; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/HighLevelRenderer { - public fun (Ljava/util/List;Lcom/google/devtools/ksp/processing/KSPLogger;Laws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory;)V - public final fun render ()V -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/annotations/rendering/SchemaRenderer : aws/sdk/kotlin/hll/codegen/rendering/RendererBase { - public fun (Lcom/google/devtools/ksp/symbol/KSClassDeclaration;Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;)V -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessor : com/google/devtools/ksp/processing/SymbolProcessor { - public fun (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)V - public fun process (Lcom/google/devtools/ksp/processing/Resolver;)Ljava/util/List; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/HighLevelOpsProcessorProvider : com/google/devtools/ksp/processing/SymbolProcessorProvider { - public fun ()V - public fun create (Lcom/google/devtools/ksp/processing/SymbolProcessorEnvironment;)Lcom/google/devtools/ksp/processing/SymbolProcessor; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind : java/lang/Enum { - public static final field Index Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; - public static final field ItemSource Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; - public static final field Table Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; - public static fun getEntries ()Lkotlin/enums/EnumEntries; - public final fun getHoistedFields ()Ljava/util/List; - public final fun getParent ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; - public final fun getSpecType (Ljava/lang/String;)Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun isAbstract ()Z - public static fun valueOf (Ljava/lang/String;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; - public static fun values ()[Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKindKt { - public static final fun getItemSourceKinds (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)Ljava/util/Set; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member { - public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member$Companion; - public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/model/Type;)V - public final fun component1 ()Ljava/lang/String; - public final fun component2 ()Laws/sdk/kotlin/hll/codegen/model/Type; - public final fun copy (Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/model/Type;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member;Ljava/lang/String;Laws/sdk/kotlin/hll/codegen/model/Type;ILjava/lang/Object;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member; - public fun equals (Ljava/lang/Object;)Z - public final fun getName ()Ljava/lang/String; - public final fun getType ()Laws/sdk/kotlin/hll/codegen/model/Type; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member$Companion { - public final fun from (Lcom/google/devtools/ksp/symbol/KSPropertyDeclaration;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member; -} - -public abstract interface class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { - public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Companion; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Companion { - public final fun identifyFor (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Drop : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { - public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Drop; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Hoist : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { - public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$Hoist; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapAll : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { - public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapAll; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapKeys : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { - public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$MapKeys; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$PassThrough : aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior { - public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior$PassThrough; - public fun equals (Ljava/lang/Object;)Z - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehaviorKt { - public static final fun getCodegenBehavior (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Member;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/MemberCodegenBehavior; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes { - public static final field INSTANCE Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ModelAttributes; - public final fun getLowLevelOperation ()Laws/smithy/kotlin/runtime/collections/AttributeKey; - public final fun getLowLevelStructure ()Laws/smithy/kotlin/runtime/collections/AttributeKey; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation { - public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation$Companion; - public fun (Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;)V - public synthetic fun (Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Ljava/lang/String; - public final fun component2 ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public final fun component3 ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public final fun component4 ()Laws/smithy/kotlin/runtime/collections/Attributes; - public final fun copy (Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;Ljava/lang/String;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/smithy/kotlin/runtime/collections/Attributes;ILjava/lang/Object;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; - public fun equals (Ljava/lang/Object;)Z - public final fun getAttributes ()Laws/smithy/kotlin/runtime/collections/Attributes; - public final fun getMethodName ()Ljava/lang/String; - public final fun getName ()Ljava/lang/String; - public final fun getRequest ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public final fun getResponse ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation$Companion { - public final fun from (Lcom/google/devtools/ksp/symbol/KSFunctionDeclaration;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/OperationKt { - public static final fun getLowLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; - public static final fun toHighLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;Ljava/lang/String;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure { - public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure$Companion; - public fun (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;)V - public synthetic fun (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun component1 ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun component2 ()Ljava/util/List; - public final fun component3 ()Laws/smithy/kotlin/runtime/collections/Attributes; - public final fun copy (Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public static synthetic fun copy$default (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Laws/sdk/kotlin/hll/codegen/model/TypeRef;Ljava/util/List;Laws/smithy/kotlin/runtime/collections/Attributes;ILjava/lang/Object;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public fun equals (Ljava/lang/Object;)Z - public final fun getAttributes ()Laws/smithy/kotlin/runtime/collections/Attributes; - public final fun getMembers ()Ljava/util/List; - public final fun getType ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public fun hashCode ()I - public fun toString ()Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure$Companion { - public final fun from (Lcom/google/devtools/ksp/symbol/KSTypeReference;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/model/StructureKt { - public static final fun getLowLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public static final fun toHighLevel (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;Ljava/lang/String;)Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/DataTypeGenerator : aws/sdk/kotlin/hll/codegen/core/CodeGenerator { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Laws/sdk/kotlin/hll/codegen/core/CodeGenerator;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure;)V - public fun blankLine ()V - public fun closeAndOpenBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun closeBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun dedent (I)V - public final fun generate ()V - public fun getImports ()Laws/sdk/kotlin/hll/codegen/core/ImportDirectives; - public final fun getStructure ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Structure; - public fun indent (I)V - public fun openBlock (Ljava/lang/String;[Ljava/lang/Object;)V - public fun persist ()V - public fun withBlock (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;Lkotlin/jvm/functions/Function0;)V - public fun withDocs (Lkotlin/jvm/functions/Function0;)V - public fun write (Ljava/lang/String;[Ljava/lang/Object;)V - public fun writeInline (Ljava/lang/String;[Ljava/lang/Object;)V -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/HighLevelRenderer { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Ljava/util/List;)V - public final fun render ()V -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer : aws/sdk/kotlin/hll/codegen/rendering/RendererBase { - public static final field Companion Laws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer$Companion; - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)V - public final fun getMembers ()Ljava/util/Map; - public final fun getOperation ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationRenderer$Companion { - public final fun factoryFunctionName (Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/Operation;)Ljava/lang/String; -} - -public final class aws/sdk/kotlin/hll/dynamodbmapper/operations/rendering/OperationsTypeRenderer : aws/sdk/kotlin/hll/codegen/rendering/RendererBase { - public fun (Laws/sdk/kotlin/hll/codegen/rendering/RenderContext;Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind;Laws/sdk/kotlin/hll/codegen/model/Type;Ljava/util/List;)V - public final fun getInterfaceType ()Laws/sdk/kotlin/hll/codegen/model/TypeRef; - public final fun getItemSourceKind ()Laws/sdk/kotlin/hll/dynamodbmapper/operations/model/ItemSourceKind; - public final fun getOperations ()Ljava/util/List; - public final fun getParentType ()Laws/sdk/kotlin/hll/codegen/model/Type; -} - diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index f2925e7e27f..1fc14c8e6b3 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -109,9 +109,7 @@ public class SchemaRenderer( } private fun renderGetTable() { - withDocs { - write("Returns a reference to a table named [name] containing items representing [#L]", className) - } + docs("Returns a reference to a table named [name] containing items representing [#T]", classType) val fnName = "get${className}Table" write( From d3e3aeb8cb1ae5b253652e7df44accd25ec10ea5 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 11:09:48 -0400 Subject: [PATCH 51/59] Further nesting of types and rename to `MapperTypes` --- .../annotations/rendering/SchemaRenderer.kt | 26 ++++----- .../codegen/model/DynamoDbMapperTypes.kt | 47 ---------------- .../codegen/model/MapperTypes.kt | 55 +++++++++++++++++++ .../operations/model/MemberCodegenBehavior.kt | 6 +- .../operations/rendering/OperationRenderer.kt | 14 ++--- 5 files changed, 78 insertions(+), 70 deletions(-) delete mode 100644 hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt create mode 100644 hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 1fc14c8e6b3..6b62510668c 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -12,7 +12,7 @@ import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbAttribute import aws.sdk.kotlin.hll.dynamodbmapper.DynamoDbPartitionKey -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.DynamoDbMapperTypes +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.MapperTypes import com.google.devtools.ksp.KspExperimental import com.google.devtools.ksp.getAnnotationsByType import com.google.devtools.ksp.isAnnotationPresent @@ -52,7 +52,7 @@ public class SchemaRenderer( private fun renderBuilder() = BuilderRenderer(this, classDeclaration).render() private fun renderItemConverter() { - withBlock("public object #L : #T by #T(", ")", converterName, DynamoDbMapperTypes.itemConverter(classType), DynamoDbMapperTypes.SimpleItemConverter) { + withBlock("public object #L : #T by #T(", ")", converterName, MapperTypes.Items.itemConverter(classType), MapperTypes.Items.SimpleItemConverter) { write("builderFactory = ::#L,", builderName) write("build = #L::build,", builderName) withBlock("descriptors = arrayOf(", "),") { @@ -65,7 +65,7 @@ public class SchemaRenderer( } private fun renderAttributeDescriptor(prop: AnnotatedClassProperty) { - withBlock("#T(", "),", DynamoDbMapperTypes.AttributeDescriptor) { + withBlock("#T(", "),", MapperTypes.Items.AttributeDescriptor) { write("#S,", prop.ddbName) // key write("#L,", "$className::${prop.name}") // getter write("#L,", "$builderName::${prop.name}::set") // setter @@ -75,19 +75,19 @@ public class SchemaRenderer( private val AnnotatedClassProperty.valueConverter: Type get() = when (typeName.asString()) { - "aws.smithy.kotlin.runtime.time.Instant" -> DynamoDbMapperTypes.DefaultInstantConverter - "kotlin.Boolean" -> DynamoDbMapperTypes.BooleanConverter - "kotlin.Int" -> DynamoDbMapperTypes.IntConverter - "kotlin.String" -> DynamoDbMapperTypes.StringConverter + "aws.smithy.kotlin.runtime.time.Instant" -> MapperTypes.Values.DefaultInstantConverter + "kotlin.Boolean" -> MapperTypes.Values.BooleanConverter + "kotlin.Int" -> MapperTypes.Values.IntConverter + "kotlin.String" -> MapperTypes.Values.StringConverter // TODO Add additional "standard" item converters else -> error("Unsupported attribute type ${typeName.asString()}") } private fun renderSchema() { - withBlock("public object #L : #T {", "}", schemaName, DynamoDbMapperTypes.itemSchemaPartitionKey(classType, keyProperty.typeRef)) { + withBlock("public object #L : #T {", "}", schemaName, MapperTypes.Items.itemSchemaPartitionKey(classType, keyProperty.typeRef)) { write("override val converter : #1L = #1L", converterName) // TODO Handle composite keys - write("override val partitionKey: #T = #T(#S)", DynamoDbMapperTypes.keySpec(keyProperty.keySpec), keyProperty.keySpecType, keyProperty.name) + write("override val partitionKey: #T = #T(#S)", MapperTypes.Items.keySpec(keyProperty.keySpec), keyProperty.keySpecType, keyProperty.name) } blankLine() } @@ -102,8 +102,8 @@ public class SchemaRenderer( private val AnnotatedClassProperty.keySpecType: TypeRef get() = when (typeName.asString()) { - "kotlin.Int" -> DynamoDbMapperTypes.KeySpecNumber - "kotlin.String" -> DynamoDbMapperTypes.KeySpecString + "kotlin.Int" -> MapperTypes.Items.KeySpecNumber + "kotlin.String" -> MapperTypes.Items.KeySpecString // TODO Handle ByteArray else -> error("Unsupported key type ${typeName.asString()}, expected Int or String") } @@ -114,9 +114,9 @@ public class SchemaRenderer( val fnName = "get${className}Table" write( "public fun #T.#L(name: String): #T = #L(name, #L)", - DynamoDbMapperTypes.DynamoDbMapper, + MapperTypes.DynamoDbMapper, fnName, - DynamoDbMapperTypes.tablePartitionKey(classType, keyProperty.typeRef), + MapperTypes.Model.tablePartitionKey(classType, keyProperty.typeRef), "getTable", schemaName, ) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt deleted file mode 100644 index 02b82b05f55..00000000000 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/DynamoDbMapperTypes.kt +++ /dev/null @@ -1,47 +0,0 @@ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model - -import aws.sdk.kotlin.hll.codegen.model.Type -import aws.sdk.kotlin.hll.codegen.model.TypeRef -import aws.sdk.kotlin.hll.codegen.model.TypeVar -import aws.sdk.kotlin.hll.codegen.model.Types -import aws.sdk.kotlin.hll.codegen.util.Pkg - -/** - * A container object for various DynamoDbMapper [Type] instances - */ -object DynamoDbMapperTypes { - // Low-level types - val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") - val AttributeMap = Types.Kotlin.map(Types.Kotlin.String, AttributeValue) - - // High-level types - val DynamoDbMapper = TypeRef(Pkg.Hl.Base, "DynamoDbMapper") - - val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") - fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) - fun itemSchemaPartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemSchema.PartitionKey", listOf(objectType, keyType)) - val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") - val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") - - fun tablePartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef( - Pkg.Hl.Model, - "Table.PartitionKey", - genericArgs = listOf(objectType, keyType), - ) - val toItem = TypeRef(Pkg.Hl.Model, "toItem") - - val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") - fun keySpec(keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "KeySpec", genericArgs = listOf(keyType)) - val KeySpecNumber = TypeRef(Pkg.Hl.Items, "KeySpec.Number") - val KeySpecString = TypeRef(Pkg.Hl.Items, "KeySpec.String") - val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") - val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") - val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") - fun itemConverter(objectType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemConverter", genericArgs = listOf(objectType)) - val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") - - val DefaultInstantConverter = TypeRef(Pkg.Hl.Values, "InstantConverter.Default") - val BooleanConverter = TypeRef(Pkg.Hl.Values, "BooleanConverter") - val IntConverter = TypeRef(Pkg.Hl.Values, "IntConverter") - val StringConverter = TypeRef(Pkg.Hl.Values, "StringConverter") -} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt new file mode 100644 index 00000000000..d5d19a7707f --- /dev/null +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt @@ -0,0 +1,55 @@ +package aws.sdk.kotlin.hll.dynamodbmapper.codegen.model + +import aws.sdk.kotlin.hll.codegen.model.Type +import aws.sdk.kotlin.hll.codegen.model.TypeRef +import aws.sdk.kotlin.hll.codegen.model.TypeVar +import aws.sdk.kotlin.hll.codegen.model.Types +import aws.sdk.kotlin.hll.codegen.util.Pkg + +/** + * A container object for various DynamoDbMapper [Type] instances + */ +object MapperTypes { + // Low-level types + val AttributeValue = TypeRef(Pkg.Ll.Model, "AttributeValue") + val AttributeMap = Types.Kotlin.map(Types.Kotlin.String, AttributeValue) + + // High-level types + val DynamoDbMapper = TypeRef(Pkg.Hl.Base, "DynamoDbMapper") + + object Items { + fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) + fun itemSchemaPartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemSchema.PartitionKey", listOf(objectType, keyType)) + val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") + fun keySpec(keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "KeySpec", genericArgs = listOf(keyType)) + val KeySpecNumber = TypeRef(Pkg.Hl.Items, "KeySpec.Number") + val KeySpecString = TypeRef(Pkg.Hl.Items, "KeySpec.String") + val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") + val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") + val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") + fun itemConverter(objectType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemConverter", genericArgs = listOf(objectType)) + val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") + } + + object Model { + fun tablePartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef( + Pkg.Hl.Model, + "Table.PartitionKey", + genericArgs = listOf(objectType, keyType), + ) + val toItem = TypeRef(Pkg.Hl.Model, "toItem") + } + + object Values { + val DefaultInstantConverter = TypeRef(Pkg.Hl.Values, "InstantConverter.Default") + val BooleanConverter = TypeRef(Pkg.Hl.Values, "BooleanConverter") + val IntConverter = TypeRef(Pkg.Hl.Values, "IntConverter") + val StringConverter = TypeRef(Pkg.Hl.Values, "StringConverter") + } + + object PipelineImpl { + val HReqContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "HReqContextImpl") + val MapperContextImpl = TypeRef(Pkg.Hl.PipelineImpl, "MapperContextImpl") + val Operation = TypeRef(Pkg.Hl.PipelineImpl, "Operation") + } +} diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt index bd8382cebb0..c437dae059b 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt @@ -8,9 +8,9 @@ import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.model.nullable import aws.sdk.kotlin.hll.codegen.util.Pkg -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.DynamoDbMapperTypes +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.MapperTypes -private val attrMapTypes = setOf(DynamoDbMapperTypes.AttributeMap, DynamoDbMapperTypes.AttributeMap.nullable()) +private val attrMapTypes = setOf(MapperTypes.AttributeMap, MapperTypes.AttributeMap.nullable()) /** * Describes a behavior to apply for a given [Member] in a low-level structure when generating code for an equivalent @@ -105,7 +105,7 @@ private val unsupportedMembers = listOf( // TODO add support for expressions Member("expressionAttributeNames", Types.Kotlin.stringMap(Types.Kotlin.String)), - Member("expressionAttributeValues", DynamoDbMapperTypes.AttributeMap), + Member("expressionAttributeValues", MapperTypes.AttributeMap), Member("conditionExpression", Types.Kotlin.String), Member("projectionExpression", Types.Kotlin.String), Member("updateExpression", Types.Kotlin.String), diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt index b70917bae8c..c59714d3a28 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt @@ -8,7 +8,7 @@ import aws.sdk.kotlin.hll.codegen.core.* import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.DynamoDbMapperTypes +import aws.sdk.kotlin.hll.dynamodbmapper.codegen.model.MapperTypes import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.* // FIXME handle paginated operations differently (e.g., don't map pagination parameters, provide only Flow API) @@ -49,13 +49,13 @@ class OperationRenderer( ")", factoryName, itemSourceKind.getSpecType("T"), - DynamoDbMapperTypes.Operation, + MapperTypes.PipelineImpl.Operation, ) { write( "initialize = { highLevelReq: #T -> #T(highLevelReq, spec.schema, #T(spec, #S)) },", operation.request.type, - DynamoDbMapperTypes.HReqContextImpl, - DynamoDbMapperTypes.MapperContextImpl, + MapperTypes.PipelineImpl.HReqContextImpl, + MapperTypes.PipelineImpl.MapperContextImpl, operation.name, ) @@ -85,7 +85,7 @@ class OperationRenderer( openBlock("private fun #T.convert(", operation.request.type) members(MemberCodegenBehavior.Hoist) { write("#L: #T, ", name, type) } - write("schema: #T,", DynamoDbMapperTypes.itemSchema("T")) + write("schema: #T,", MapperTypes.Items.itemSchema("T")) closeAndOpenBlock(") = #L {", operation.request.lowLevelName) members(MemberCodegenBehavior.PassThrough) { write("#1L = this@convert.#1L", name) } members(MemberCodegenBehavior.MapKeys) { @@ -113,13 +113,13 @@ class OperationRenderer( "private fun #L.convert(schema: #T) = #T(", ")", operation.response.lowLevelName, - DynamoDbMapperTypes.itemSchema("T"), + MapperTypes.Items.itemSchema("T"), operation.response.type, ) { members(MemberCodegenBehavior.PassThrough) { write("#1L = this@convert.#1L,", name) } members(MemberCodegenBehavior.MapKeys, MemberCodegenBehavior.MapAll) { - write("#1L = this@convert.#1L?.#2T()?.let(schema.converter::fromItem),", name, DynamoDbMapperTypes.toItem) + write("#1L = this@convert.#1L?.#2T()?.let(schema.converter::fromItem),", name, MapperTypes.Model.toItem) } } } From 1da7f9afa52d24bfac730e9fe776d2d7859ebb48 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 11:10:10 -0400 Subject: [PATCH 52/59] Remove unused types --- .../sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt index d5d19a7707f..429ca345b3a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/model/MapperTypes.kt @@ -20,13 +20,10 @@ object MapperTypes { object Items { fun itemSchema(typeVar: String) = TypeRef(Pkg.Hl.Items, "ItemSchema", listOf(TypeVar(typeVar))) fun itemSchemaPartitionKey(objectType: TypeRef, keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemSchema.PartitionKey", listOf(objectType, keyType)) - val KeySpec = TypeRef(Pkg.Hl.Items, "KeySpec") fun keySpec(keyType: TypeRef) = TypeRef(Pkg.Hl.Items, "KeySpec", genericArgs = listOf(keyType)) val KeySpecNumber = TypeRef(Pkg.Hl.Items, "KeySpec.Number") val KeySpecString = TypeRef(Pkg.Hl.Items, "KeySpec.String") - val ItemSchema = TypeRef(Pkg.Hl.Items, "ItemSchema") val AttributeDescriptor = TypeRef(Pkg.Hl.Items, "AttributeDescriptor") - val ItemConverter = TypeRef(Pkg.Hl.Items, "ItemConverter") fun itemConverter(objectType: TypeRef) = TypeRef(Pkg.Hl.Items, "ItemConverter", genericArgs = listOf(objectType)) val SimpleItemConverter = TypeRef(Pkg.Hl.Items, "SimpleItemConverter") } From 345fd8e9a08faa146a0c31f9cdbb70ad30b48b28 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 11:13:18 -0400 Subject: [PATCH 53/59] exclude annotation processor in ops-codegen --- hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts index f655d5cc0da..ecb3b10eb7a 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts @@ -58,6 +58,8 @@ ksp { "scan", ) arg("op-allowlist", allowlist.joinToString(";")) + + excludeProcessor("aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.AnnotationsProcessor") } if (project.NATIVE_ENABLED) { From fbd7ba1a8accb210fe886e59fd5fc793c32c6057 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 11:15:18 -0400 Subject: [PATCH 54/59] rename module `codegen` to `hll-codegen` --- hll/{codegen => hll-codegen}/build.gradle.kts | 0 .../main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt | 0 .../aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt | 0 .../kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt | 0 .../main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt | 0 .../kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt | 0 .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 0 .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt | 0 .../aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt | 0 .../kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt | 0 .../kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt | 0 .../main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt | 0 .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt | 0 .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt | 0 .../kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt | 0 .../aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt | 0 .../test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename hll/{codegen => hll-codegen}/build.gradle.kts (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt (100%) rename hll/{codegen => hll-codegen}/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt (100%) rename hll/{codegen => hll-codegen}/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt (100%) rename hll/{codegen => hll-codegen}/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt (100%) rename hll/{codegen => hll-codegen}/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt (100%) diff --git a/hll/codegen/build.gradle.kts b/hll/hll-codegen/build.gradle.kts similarity index 100% rename from hll/codegen/build.gradle.kts rename to hll/hll-codegen/build.gradle.kts diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGenerator.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/CodeGeneratorFactory.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/ImportDirectives.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngine.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RenderContext.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/RendererBase.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/AttributesExt.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Pkg.kt diff --git a/hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt similarity index 100% rename from hll/codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/util/Strings.kt diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt b/hll/hll-codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt similarity index 100% rename from hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt rename to hll/hll-codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateEngineTest.kt diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt b/hll/hll-codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt similarity index 100% rename from hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt rename to hll/hll-codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessorTest.kt diff --git a/hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt b/hll/hll-codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt similarity index 100% rename from hll/codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt rename to hll/hll-codegen/src/test/kotlin/aws/sdk/kotlin/hll/codegen/util/StringsTest.kt From 930fb530129b7e2873458cb55d9573d7b0130bc4 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 11:23:15 -0400 Subject: [PATCH 55/59] rename module `codegen` to `hll-codegen` --- hll/build.gradle.kts | 2 +- hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts | 2 +- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt | 2 +- settings.gradle.kts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hll/build.gradle.kts b/hll/build.gradle.kts index c408f063a25..f95d45f5cdd 100644 --- a/hll/build.gradle.kts +++ b/hll/build.gradle.kts @@ -87,7 +87,7 @@ apiValidation { val availableSubprojects = subprojects.map { it.name }.toSet() ignoredProjects += listOf( - "codegen", + "hll-codegen", "dynamodb-mapper-annotation-processor-test", "dynamodb-mapper-codegen", ).filter { it in availableSubprojects } // Some projects may not be in the build depending on bootstrapping diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts b/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts index ce2fc54758f..03359aece14 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/build.gradle.kts @@ -13,7 +13,7 @@ plugins { dependencies { implementation(libs.ksp.api) - implementation(project(":hll:codegen")) + implementation(project(":hll:hll-codegen")) implementation(project(":hll:dynamodb-mapper:dynamodb-mapper-annotations")) implementation(project(":services:dynamodb")) diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt index adeec1700db..8b823cf5872 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Types.kt @@ -7,7 +7,7 @@ import aws.sdk.kotlin.hll.codegen.util.Pkg */ object Types { object Kotlin { - val String = kotlin( "String") + val String = kotlin("String") val Number = kotlin("Number") val StringNullable = String.nullable() diff --git a/settings.gradle.kts b/settings.gradle.kts index 955d2b3752f..b9e3bedf097 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -40,7 +40,7 @@ include(":aws-runtime:aws-config") include(":aws-runtime:aws-endpoint") include(":aws-runtime:aws-http") include(":hll") -include(":hll:codegen") +include(":hll:hll-codegen") include(":services") include(":tests") include(":tests:codegen:event-stream") From 3513aa65d6cbae39aa985a03cc6e32f0cf50110c Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 12:15:14 -0400 Subject: [PATCH 56/59] Add `type.baseName` --- .../aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt | 4 ++-- .../main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt index cc80bf883c8..0b5a4589e1d 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/core/TemplateProcessor.kt @@ -72,10 +72,10 @@ private open class TypeProcessor { private class ImportingTypeProcessor(private val pkg: String, private val imports: ImportDirectives) : TypeProcessor() { override fun format(type: Type): String = buildString { if (type is TypeRef && type.pkg != pkg && type.pkg != "kotlin") { - val existingImport = imports[type.shortName.substringBefore(".")] + val existingImport = imports[type.baseName] if (existingImport == null) { - imports += ImportDirective(type.copy(shortName = type.shortName.substringBefore("."))) + imports += ImportDirective("${type.pkg}.${type.baseName}") } else if (existingImport.fullName != type.fullName) { append(type.pkg) append('.') diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index c8507a871b2..5dd92245244 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -69,6 +69,12 @@ data class TypeRef( * The full name of this type, including the Kotlin package */ val fullName: String = "$pkg.$shortName" + + /** + * The base name of this type. In most cases, this will be the same as the short name, but for nested types, this + * will only include the top-level name. For example, the base name of a type Foo.Bar.Baz is Foo. + */ + val baseName: String = shortName.substringBefore(".") } /** From 1ca559c8f085dd8741292f4c9f8f69beb714e634 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 12:26:37 -0400 Subject: [PATCH 57/59] Move [Member] to shared codegen module and clean up BuilderRenderer --- .../annotations/rendering/SchemaRenderer.kt | 8 +++- .../operations/model/MemberCodegenBehavior.kt | 1 + .../codegen/operations/model/Structure.kt | 1 + .../operations/rendering/DataTypeGenerator.kt | 2 +- .../operations/rendering/OperationRenderer.kt | 1 + .../sdk/kotlin/hll/codegen}/model/Member.kt | 2 +- .../hll/codegen/rendering/BuilderRenderer.kt | 37 ++++++------------- 7 files changed, 22 insertions(+), 30 deletions(-) rename hll/{dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations => hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen}/model/Member.kt (91%) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 6b62510668c..33157b5c8d2 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations.rendering +import aws.sdk.kotlin.hll.codegen.model.Member import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Types @@ -48,8 +49,11 @@ public class SchemaRenderer( renderGetTable() } - // TODO Not all classes need builders generated (i.e. the class consists of all public mutable members), add configurability here - private fun renderBuilder() = BuilderRenderer(this, classDeclaration).render() + private fun renderBuilder() { + // TODO Not all classes need builders generated (i.e. the class consists of all public mutable members), add configurability here + val members = classDeclaration.getAllProperties().map(Member.Companion::from).toSet() + BuilderRenderer(this, classType, members).render() + } private fun renderItemConverter() { withBlock("public object #L : #T by #T(", ")", converterName, MapperTypes.Items.itemConverter(classType), MapperTypes.Items.SimpleItemConverter) { diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt index c437dae059b..69e279c4103 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/MemberCodegenBehavior.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model +import aws.sdk.kotlin.hll.codegen.model.Member import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.Types import aws.sdk.kotlin.hll.codegen.model.nullable diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt index 849e8569300..dd4e3e12481 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Structure.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model +import aws.sdk.kotlin.hll.codegen.model.Member import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt index c3f46db8a32..b310a7db075 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/DataTypeGenerator.kt @@ -5,11 +5,11 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.core.CodeGenerator +import aws.sdk.kotlin.hll.codegen.model.Member import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import aws.sdk.kotlin.hll.codegen.model.TypeVar import aws.sdk.kotlin.hll.codegen.rendering.RenderContext -import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Member import aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model.Structure /** diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt index c59714d3a28..24e199996ab 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/rendering/OperationRenderer.kt @@ -5,6 +5,7 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.rendering import aws.sdk.kotlin.hll.codegen.core.* +import aws.sdk.kotlin.hll.codegen.model.Member import aws.sdk.kotlin.hll.codegen.rendering.RenderContext import aws.sdk.kotlin.hll.codegen.rendering.RendererBase import aws.sdk.kotlin.hll.codegen.rendering.info diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Member.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt similarity index 91% rename from hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Member.kt rename to hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt index 704cf3f1c8d..1023dbb1ec4 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/operations/model/Member.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.hll.dynamodbmapper.codegen.operations.model +package aws.sdk.kotlin.hll.codegen.model import aws.sdk.kotlin.hll.codegen.model.Type import com.google.devtools.ksp.symbol.KSPropertyDeclaration diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index e8ee2c4b1e7..8b11fe3cbb9 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -1,5 +1,6 @@ package aws.sdk.kotlin.hll.codegen.rendering +import aws.sdk.kotlin.hll.codegen.model.Member import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import com.google.devtools.ksp.symbol.* @@ -7,29 +8,28 @@ import com.google.devtools.ksp.symbol.* /** * A DSL-style builder renderer. * @param renderer The base renderer in which the builder will be written - * @param classDeclaration The [KSClassDeclaration] for which a builder will be generated + * @param classType The [TypeRef] representing the class for which a builder will be generated + * @param members The [Set] of members of [classType] which will be included in the builder */ class BuilderRenderer( private val renderer: RendererBase, - private val classDeclaration: KSClassDeclaration, + private val classType: TypeRef, + private val members: Set ) { - private val properties = classDeclaration.getAllProperties().mapNotNull(KSClassProperty.Companion::from) - - private val className = classDeclaration.qualifiedName!!.getShortName() - private val classType: TypeRef = Type.from(classDeclaration) + private val className = classType.shortName fun render() = renderer.apply { docs("A DSL-style builder for instances of [#T]", classType) withBlock("public class #L {", "}", "${className}Builder") { - properties.forEach { - write("public var #L: #T? = null", it.name, it.typeRef) + members.forEach { + write("public var #L: #T? = null", it.name, it.type) } blankLine() withBlock("public fun build(): #T {", "}", classType) { - properties.forEach { - if (it.nullable) { + members.forEach { + if (it.type.nullable) { write("val #1L = #1L", it.name) } else { write("val #1L = requireNotNull(#1L) { #2S }", it.name, "Missing value for ${it.name}") @@ -37,7 +37,7 @@ class BuilderRenderer( } blankLine() withBlock("return #T(", ")", classType) { - properties.forEach { + members.forEach { write("#L,", it.name) } } @@ -46,18 +46,3 @@ class BuilderRenderer( blankLine() } } - -private data class KSClassProperty(val name: String, val typeRef: TypeRef, val typeName: KSName, val nullable: Boolean) { - companion object { - fun from(ksProperty: KSPropertyDeclaration): KSClassProperty? { - val type: KSType = ksProperty.getter?.returnType?.resolve() ?: return null - - val name = ksProperty.simpleName.getShortName() - val typeRef = Type.from(checkNotNull(ksProperty.type) { "Failed to determine class type for $name" }) - val typeName = type.declaration.qualifiedName ?: return null - val nullable = type.nullability != Nullability.NOT_NULL - - return KSClassProperty(name, typeRef, typeName, nullable) - } - } -} From a1b54b6d1bbcaaa7de67db6f94259384a649ac2f Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 12:28:27 -0400 Subject: [PATCH 58/59] ktlint --- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt | 1 - .../aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt index 1023dbb1ec4..ec2b6dfa374 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Member.kt @@ -4,7 +4,6 @@ */ package aws.sdk.kotlin.hll.codegen.model -import aws.sdk.kotlin.hll.codegen.model.Type import com.google.devtools.ksp.symbol.KSPropertyDeclaration /** diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt index 8b11fe3cbb9..3fb3870922f 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/rendering/BuilderRenderer.kt @@ -1,7 +1,6 @@ package aws.sdk.kotlin.hll.codegen.rendering import aws.sdk.kotlin.hll.codegen.model.Member -import aws.sdk.kotlin.hll.codegen.model.Type import aws.sdk.kotlin.hll.codegen.model.TypeRef import com.google.devtools.ksp.symbol.* @@ -14,7 +13,7 @@ import com.google.devtools.ksp.symbol.* class BuilderRenderer( private val renderer: RendererBase, private val classType: TypeRef, - private val members: Set + private val members: Set, ) { private val className = classType.shortName From a5d6c9df0f6df1842ecc6cc6812f74d4b0cf2457 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 16 Aug 2024 12:31:15 -0400 Subject: [PATCH 59/59] Remove unnecessary visibility modifiers --- .../codegen/annotations/AnnotationsProcessor.kt | 2 +- .../codegen/annotations/AnnotationsProcessorProvider.kt | 2 +- .../codegen/annotations/rendering/HighLevelRenderer.kt | 4 ++-- .../codegen/annotations/rendering/SchemaRenderer.kt | 2 +- .../src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt index 8d152b44cd4..665e902de2f 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessor.kt @@ -13,7 +13,7 @@ import com.google.devtools.ksp.validate private val annotationName = DynamoDbItem::class.qualifiedName!! -public class AnnotationsProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor { +class AnnotationsProcessor(private val environment: SymbolProcessorEnvironment) : SymbolProcessor { private var invoked = false private val logger = environment.logger private val codeGenerator = environment.codeGenerator diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt index 01a46415e7e..1ba9242ab9b 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/AnnotationsProcessorProvider.kt @@ -7,6 +7,6 @@ package aws.sdk.kotlin.hll.dynamodbmapper.codegen.annotations import com.google.devtools.ksp.processing.SymbolProcessorEnvironment import com.google.devtools.ksp.processing.SymbolProcessorProvider -public class AnnotationsProcessorProvider : SymbolProcessorProvider { +class AnnotationsProcessorProvider : SymbolProcessorProvider { override fun create(environment: SymbolProcessorEnvironment): AnnotationsProcessor = AnnotationsProcessor(environment) } diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt index 0a104081d61..ea2bfd2b949 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/HighLevelRenderer.kt @@ -13,12 +13,12 @@ import com.google.devtools.ksp.symbol.KSClassDeclaration * The parent renderer for all codegen from this package. This class orchestrates the various sub-renderers. * @param annotatedClasses A list of annotated classes */ -public class HighLevelRenderer( +class HighLevelRenderer( private val annotatedClasses: List, private val logger: KSPLogger, private val codegenFactory: CodeGeneratorFactory, ) { - public fun render() { + fun render() { annotatedClasses.forEach { logger.info("Processing annotation on ${it.simpleName}") val renderCtx = RenderContext(logger, codegenFactory, "${it.packageName.asString()}.mapper.schemas", "dynamodb-mapper-annotation-processor") diff --git a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt index 33157b5c8d2..e491e508341 100644 --- a/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt +++ b/hll/dynamodb-mapper/dynamodb-mapper-codegen/src/main/kotlin/aws/sdk/kotlin/hll/dynamodbmapper/codegen/annotations/rendering/SchemaRenderer.kt @@ -26,7 +26,7 @@ import com.google.devtools.ksp.symbol.KSPropertyDeclaration * @param classDeclaration the [KSClassDeclaration] of the class * @param ctx the [RenderContext] of the renderer */ -public class SchemaRenderer( +class SchemaRenderer( private val classDeclaration: KSClassDeclaration, private val ctx: RenderContext, ) : RendererBase(ctx, "${classDeclaration.qualifiedName!!.getShortName()}Schema") { diff --git a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt index 5dd92245244..a4d28b5005d 100644 --- a/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt +++ b/hll/hll-codegen/src/main/kotlin/aws/sdk/kotlin/hll/codegen/model/Type.kt @@ -87,7 +87,7 @@ data class TypeVar(override val shortName: String, override val nullable: Boolea /** * Derives a nullable [Type] equivalent for this type */ -public fun Type.nullable() = when { +fun Type.nullable() = when { nullable -> this this is TypeRef -> copy(nullable = true) this is TypeVar -> copy(nullable = true)