From 419f6c80de333aac242fd085e5240b38f806d1d5 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Wed, 29 May 2019 14:08:51 +0300 Subject: [PATCH] New J2K: filter out noinspection comments in resulted code --- nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt b/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt index f5d8739b20c..5caf0231b8d 100644 --- a/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt +++ b/nj2k/src/org/jetbrains/kotlin/nj2k/NewCodeBuilder.kt @@ -46,6 +46,10 @@ class NewCodeBuilder(context: NewJ2kConverterContext) { inner class Visitor : JKVisitorWithCommentsPrinting { private val printedTokens = mutableSetOf() + //TODO move to ast transformation phase + private fun JKNonCodeElement.shouldBeDropped(): Boolean = + this is JKCommentElement && text.startsWith("//noinspection") + private fun JKNonCodeElement.createText() = if (this !in printedTokens) { printedTokens += this @@ -54,7 +58,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) { private fun List.createText(): String { - val text = joinToString("") { token -> token.createText() } + val text = filterNot { it.shouldBeDropped() }.joinToString("") { token -> token.createText() } val needNewLine = text.lastIndexOf('\n') < text.lastIndexOf("//") return text + "\n".takeIf { needNewLine }.orEmpty() }