Skip to content
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

Merged

Conversation

pranjalvachaspati-toast

This replaces enough stuff with kotlinpoet code that all the imports are resolved and tests pass.

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
Copy link
Owner

@andrewparmet andrewparmet left a 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?

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())
Copy link
Owner

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.

name = f.fieldTypeNames.getValue(ff.name),
read = deserializeString(ff, ctx, false)
)
"${f.name}.${f.fieldTypeNames.getValue(ff.fieldName)}(${deserializeString(ff, ctx, false)})"
Copy link
Owner

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.)

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")
Copy link
Owner

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?

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.

@pranjalvachaspati-toast
Copy link
Author

I went ahead and removed the stringtemplate dependency from the gradle files as well.

}
}
f.repeated -> {
val map = mutableMapOf(
Copy link
Owner

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?

@andrewparmet andrewparmet merged commit f9afebb into andrewparmet:kotlinpoet Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants