New J2K: filter out noinspection comments in resulted code

This commit is contained in:
Ilya Kirillov
2019-05-29 14:08:51 +03:00
parent e04c984e48
commit 419f6c80de
@@ -46,6 +46,10 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
inner class Visitor : JKVisitorWithCommentsPrinting {
private val printedTokens = mutableSetOf<JKNonCodeElement>()
//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<JKNonCodeElement>.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()
}