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

AnnotationSpec.Builder with TypeName #460

Closed
shaishavgandhi05 opened this Issue Sep 4, 2018 · 4 comments

Comments

2 participants
@shaishavgandhi05
Contributor

shaishavgandhi05 commented Sep 4, 2018

I noticed that in it's private constructor, AnnotationSpec accepts a TypeName. However, it's builder doesn't accept a TypeName but instead needs a ClassName which extends TypeName. I believe JavaPoet also has something similar. Why not just expose TypeName in the builder?

My use-case:
I have a project which already generates Java code via JavaPoet. I'm trying to make the API kotlin friendly by generating extension functions, which means I'm usually interoping between JavaPoet and KotlinPoet. So when I'm converting JavaAnnotationSpec to KotlinAnnotationSpec(renamed via typealias), I could have done

javaAnnotation.map { KotlinAnnotationSpec.builder(it.type) }

instead of having to construct the KotlinClassName again and feed it to the KotlinAnnotationSpec.builder

@JakeWharton

This comment has been minimized.

Show comment
Hide comment
@JakeWharton

JakeWharton Sep 4, 2018

Collaborator

The type system is used to prevent accidentally passing a parameterized type or a wildcard or a type variable.

Collaborator

JakeWharton commented Sep 4, 2018

The type system is used to prevent accidentally passing a parameterized type or a wildcard or a type variable.

@shaishavgandhi05

This comment has been minimized.

Show comment
Hide comment
@shaishavgandhi05

shaishavgandhi05 Sep 4, 2018

Contributor

That makes sense! Is there a reason why the AnnotationSpec.Builder and AnnotationSpec doesn't internally use ClassName itself? Especially since Parameterized types/wildcards/lambdas etc wouldn't count as valid annotations and those seem like the classes that extend TypeName (from an initial glance)

Contributor

shaishavgandhi05 commented Sep 4, 2018

That makes sense! Is there a reason why the AnnotationSpec.Builder and AnnotationSpec doesn't internally use ClassName itself? Especially since Parameterized types/wildcards/lambdas etc wouldn't count as valid annotations and those seem like the classes that extend TypeName (from an initial glance)

@JakeWharton

This comment has been minimized.

Show comment
Hide comment
@JakeWharton

JakeWharton Sep 4, 2018

Collaborator

None that I can think of. I believe it was pointed out to be a mistake in JavaPoet actually. We should correct it here prior to 1.0.

Collaborator

JakeWharton commented Sep 4, 2018

None that I can think of. I believe it was pointed out to be a mistake in JavaPoet actually. We should correct it here prior to 1.0.

@shaishavgandhi05

This comment has been minimized.

Show comment
Hide comment
@shaishavgandhi05

shaishavgandhi05 Sep 4, 2018

Contributor

Cool! Happy to send a PR!

Contributor

shaishavgandhi05 commented Sep 4, 2018

Cool! Happy to send a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment