-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove importresolver package #5
Remove importresolver package #5
Conversation
This is part of the KotlinPoet migration; really we're just moving the codegen to format strings in Kotlin since the generated code for each of these functions is small and the main complexity is in the conditionals. Also, KotlinPoet doesn't really support writing code blocks in a way that would be useful here.
…into remove-renderers # Conflicts: # protokt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/MessageAnnotator.kt # protokt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/PropertyAnnotator.kt # protokt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/template/Renderers.kt # protokt-codegen/src/main/resources/renderers.stg
…into convert-to-types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice to eliminate StringTemplate. Can the dependency be removed entirely now?
protokt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/DslAnnotator.kt
Outdated
Show resolved
Hide resolved
protokt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/MessageSizeAnnotator.kt
Outdated
Show resolved
Hide resolved
this.map -> CodeBlock.of("emptyMap()") | ||
this.repeated -> CodeBlock.of("emptyList()") | ||
type == FieldType.MESSAGE -> CodeBlock.of("null") | ||
type == FieldType.ENUM -> CodeBlock.of("%T.from(0)", this.typePClass.toTypeName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One day I’d like to get the default value of the enum here as a literal.
...okt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/DeserializerAnnotator.kt
Outdated
Show resolved
Hide resolved
...okt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/DeserializerAnnotator.kt
Outdated
Show resolved
Hide resolved
...okt-codegen/src/main/kotlin/com/toasttab/protokt/codegen/annotators/DeserializerAnnotator.kt
Outdated
Show resolved
Hide resolved
name = f.fieldTypeNames.getValue(ff.name), | ||
read = deserializeString(ff, ctx, false) | ||
) | ||
"${f.name}.${f.fieldTypeNames.getValue(ff.fieldName)}(${deserializeString(ff, ctx, false)})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes. (I know this came straight from StringTemplate.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, there are a few messy templates in here that should probably be cleaned up and kotlinpoet-ified.
override val ktRepresentation: KClass<*>? = null | ||
override val ktRepresentation: KClass<*>? = null, | ||
override val isGeneratedType: Boolean = false, | ||
override val defaultValue: CodeBlock = CodeBlock.of("null") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it ended up nice to not bind these models to a particular code generator implementation - can this be implemented with a when()
statement in the annotator(s) that needs it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved this to an extension function in impl/DefaultValues.kt, since we need this in a few places. Let me know if you had something different in mind.
I went ahead and removed the stringtemplate dependency from the gradle files as well. |
} | ||
} | ||
f.repeated -> { | ||
val map = mutableMapOf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be declared in line as non-mutable maps?
This replaces enough stuff with kotlinpoet code that all the imports are resolved and tests pass.