TrailingCommaPostFormatProcessor: should reset user data after invocation
#KT-37870 Fixed
This commit is contained in:
@@ -50,7 +50,6 @@ private class TrailingCommaPostFormatVisitor(val settings: CodeStyleSettings) :
|
|||||||
|
|
||||||
private fun processCommaOwner(parent: KtElement) {
|
private fun processCommaOwner(parent: KtElement) {
|
||||||
if (!postFormatIsEnable(parent)) return
|
if (!postFormatIsEnable(parent)) return
|
||||||
parent.putUserData(IS_INSIDE, true)
|
|
||||||
|
|
||||||
val lastElement = trailingCommaOrLastElement(parent) ?: return
|
val lastElement = trailingCommaOrLastElement(parent) ?: return
|
||||||
val elementType = getElementType(lastElement)
|
val elementType = getElementType(lastElement)
|
||||||
@@ -76,11 +75,13 @@ private class TrailingCommaPostFormatVisitor(val settings: CodeStyleSettings) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePsi(element: KtElement, block: () -> Unit) {
|
private fun updatePsi(element: KtElement, block: () -> Unit) {
|
||||||
|
element.putUserData(IS_INSIDE, true)
|
||||||
val oldLength = element.parent.textLength
|
val oldLength = element.parent.textLength
|
||||||
block()
|
block()
|
||||||
|
|
||||||
val resultElement = CodeStyleManager.getInstance(element.project).reformat(element)
|
val resultElement = CodeStyleManager.getInstance(element.project).reformat(element)
|
||||||
myPostProcessor.updateResultRange(oldLength, resultElement.parent.textLength)
|
myPostProcessor.updateResultRange(oldLength, resultElement.parent.textLength)
|
||||||
|
element.putUserData(IS_INSIDE, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun correctCommaPosition(parent: KtElement) {
|
private fun correctCommaPosition(parent: KtElement) {
|
||||||
@@ -109,7 +110,7 @@ private class TrailingCommaPostFormatVisitor(val settings: CodeStyleSettings) :
|
|||||||
companion object {
|
companion object {
|
||||||
private val LOG = Logger.getInstance(TrailingCommaVisitor::class.java)
|
private val LOG = Logger.getInstance(TrailingCommaVisitor::class.java)
|
||||||
private val IS_INSIDE = Key.create<Boolean>("TrailingCommaPostFormat")
|
private val IS_INSIDE = Key.create<Boolean>("TrailingCommaPostFormat")
|
||||||
private fun postFormatIsEnable(source: PsiElement): Boolean = source.getUserData(IS_INSIDE)?.not() ?: true
|
private fun postFormatIsEnable(source: PsiElement): Boolean = source.getUserData(IS_INSIDE) != true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user