New J2K: filter out noinspection comments in resulted code
This commit is contained in:
@@ -46,6 +46,10 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
inner class Visitor : JKVisitorWithCommentsPrinting {
|
inner class Visitor : JKVisitorWithCommentsPrinting {
|
||||||
private val printedTokens = mutableSetOf<JKNonCodeElement>()
|
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() =
|
private fun JKNonCodeElement.createText() =
|
||||||
if (this !in printedTokens) {
|
if (this !in printedTokens) {
|
||||||
printedTokens += this
|
printedTokens += this
|
||||||
@@ -54,7 +58,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
|
|
||||||
private fun List<JKNonCodeElement>.createText(): String {
|
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("//")
|
val needNewLine = text.lastIndexOf('\n') < text.lastIndexOf("//")
|
||||||
return text + "\n".takeIf { needNewLine }.orEmpty()
|
return text + "\n".takeIf { needNewLine }.orEmpty()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user