-
Notifications
You must be signed in to change notification settings - Fork 686
Escape /* and */ in KDocs #6805
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| package com.apollographql.apollo.compiler.codegen.kotlin.helpers | ||
|
|
||
| import com.apollographql.apollo.compiler.internal.applyIf | ||
| import com.apollographql.apollo.compiler.codegen.kotlin.KotlinResolver | ||
| import com.apollographql.apollo.compiler.codegen.kotlin.KotlinSymbols | ||
| import com.apollographql.apollo.compiler.internal.applyIf | ||
| import com.apollographql.apollo.compiler.ir.IrEnum | ||
| import com.squareup.kotlinpoet.Annotatable | ||
| import com.squareup.kotlinpoet.AnnotationSpec | ||
|
|
@@ -18,33 +18,39 @@ internal fun TypeSpec.Builder.maybeAddDescription(description: String?): TypeSpe | |
| return this | ||
| } | ||
|
|
||
| return addKdoc("%L", description.replace(' ', '♢')) | ||
| return addKdoc("%L", description.sanitized()) | ||
| } | ||
|
|
||
| internal fun PropertySpec.Builder.maybeAddDescription(description: String?): PropertySpec.Builder { | ||
| if (description.isNullOrBlank()) { | ||
| return this | ||
| } | ||
|
|
||
| return addKdoc("%L", description.replace(' ', '♢')) | ||
| return addKdoc("%L", description.sanitized()) | ||
| } | ||
|
|
||
| internal fun ParameterSpec.Builder.maybeAddDescription(description: String?): ParameterSpec.Builder { | ||
| if (description.isNullOrBlank()) { | ||
| return this | ||
| } | ||
|
|
||
| return addKdoc("%L", description.replace(' ', '♢')) | ||
| return addKdoc("%L", description.sanitized()) | ||
| } | ||
|
|
||
| internal fun FunSpec.Builder.maybeAddDescription(description: String?): FunSpec.Builder { | ||
| if (description.isNullOrBlank()) { | ||
| return this | ||
| } | ||
|
|
||
| return addKdoc("%L", description.replace(' ', '♢')) | ||
| return addKdoc("%L", description.sanitized()) | ||
| } | ||
|
|
||
| private fun String.sanitized(): String { | ||
| return replace(' ', '♢') | ||
| // See https://github.com/square/kotlinpoet/issues/887 | ||
| .replace("/*", "/*") | ||
| .replace("*/", "*/") | ||
|
Comment on lines
+51
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means code blocks containing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No actually I checked, and that's rendered correctly in the IDE and in the generated KDoc
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this string: Is rendered as this codeblock: Then how does one displays
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this? /**
* generates some foo!
* example:
*
* ```kotlin
* /* this is how you do it! */
* val foo = doFoo()
* ```
*/
fun doFoo() = TODO()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine by me, especially if the current state is to generate non-compiling code but probably means the "good" fix needs to be in Kotlin somewhere?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I've just opened https://youtrack.jetbrains.com/issue/KT-83005/ |
||
| } | ||
|
|
||
| internal fun TypeSpec.Builder.maybeAddDeprecation(deprecationReason: String?): TypeSpec.Builder { | ||
| if (deprecationReason == null) { | ||
|
|
@@ -120,7 +126,7 @@ internal fun requiresOptInAnnotation(annotation: ClassName): AnnotationSpec { | |
| .build() | ||
| } | ||
|
|
||
| internal fun <T: Annotatable.Builder<*>> T.maybeAddOptIn( | ||
| internal fun <T : Annotatable.Builder<*>> T.maybeAddOptIn( | ||
| resolver: KotlinResolver, | ||
| enumValues: List<IrEnum.Value>, | ||
| ): T = applyIf(enumValues.any { it.optInFeature != null }) { | ||
|
|
@@ -132,10 +138,10 @@ internal fun <T: Annotatable.Builder<*>> T.maybeAddOptIn( | |
| * Add suppressions for generated code. | ||
| * This is code the user has no control over and it should not generate warnings | ||
| */ | ||
| internal fun <T: Annotatable.Builder<*>> T.addSuppressions( | ||
| internal fun <T : Annotatable.Builder<*>> T.addSuppressions( | ||
| deprecation: Boolean = false, | ||
| optInUsage: Boolean = false, | ||
| unusedParameter: Boolean = false | ||
| unusedParameter: Boolean = false, | ||
| ): T = apply { | ||
| if (!deprecation && !optInUsage && !unusedParameter) { | ||
| return@apply | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| query TestQuery { | ||
| someType { | ||
| someField | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


Uh oh!
There was an error while loading. Please reload this page.