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

Extract interface for constructs that can hold a TypeSpec and their builders #1723

Merged
merged 1 commit into from
Nov 16, 2023

Conversation

drawers
Copy link
Contributor

@drawers drawers commented Nov 16, 2023

Part of #1553

package com.squareup.kotlinpoet

/** A spec which can contain other [TypeSpec] */
public interface TypeSpecHolder {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name follows convention in the project OriginatingElementsHolder

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But differs from Annotatable. Honestly I've been mulling this change because I couldn't think of an -able name. Probably should have gone with AnnotationHolder...


public interface Builder<out T : Builder<T>> {

public fun addType(typeSpec: TypeSpec): T
Copy link
Contributor Author

@drawers drawers Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we haven't provided a default implementation for addType, this interface is less like a trait than Documentable and Annotatable.

It also doesn't achieve a mutable property val typeSpecs: MutableList<TypeSpec> like Documentable and Annotatable

Copy link
Collaborator

@JakeWharton JakeWharton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@JakeWharton JakeWharton merged commit 7a57880 into square:main Nov 16, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants