Add modifiers on the same line even after annotation #KT-26492 Fixed
This commit is contained in:
@@ -88,14 +88,20 @@ internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywo
|
|||||||
|
|
||||||
fun placeAfter(child: PsiElement): Boolean {
|
fun placeAfter(child: PsiElement): Boolean {
|
||||||
if (child is PsiWhiteSpace) return false
|
if (child is PsiWhiteSpace) return false
|
||||||
if (child is KtAnnotation) return true // place modifiers after annotations
|
if (child is KtAnnotation || child is KtAnnotationEntry) return true // place modifiers after annotations
|
||||||
val elementType = child.node!!.elementType
|
val elementType = child.node!!.elementType
|
||||||
val order = MODIFIERS_ORDER.indexOf(elementType)
|
val order = MODIFIERS_ORDER.indexOf(elementType)
|
||||||
return newModifierOrder > order
|
return newModifierOrder > order
|
||||||
}
|
}
|
||||||
|
|
||||||
val lastChild = modifierList.lastChild
|
val lastChild = modifierList.lastChild
|
||||||
val anchor = lastChild?.siblings(forward = false)?.firstOrNull(::placeAfter)
|
val anchor = lastChild?.siblings(forward = false)?.firstOrNull(::placeAfter).let {
|
||||||
|
when {
|
||||||
|
it?.nextSibling is PsiWhiteSpace && (it is KtAnnotation || it is KtAnnotationEntry) -> it.nextSibling
|
||||||
|
it == null && modifierList.firstChild is PsiWhiteSpace -> modifierList.firstChild
|
||||||
|
else -> it
|
||||||
|
}
|
||||||
|
}
|
||||||
modifierList.addAfter(newModifier, anchor)
|
modifierList.addAfter(newModifier, anchor)
|
||||||
|
|
||||||
if (anchor == lastChild) { // add line break if needed, otherwise visibility keyword may appear on previous line
|
if (anchor == lastChild) { // add line break if needed, otherwise visibility keyword may appear on previous line
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
@Ann
|
||||||
|
annotation <caret>class My
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
annotation class Ann
|
||||||
|
|
||||||
|
@Ann
|
||||||
|
private annotation class My
|
||||||
+1
-2
@@ -1,5 +1,4 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
// Ann: to be implemented
|
// Ann: to be implemented
|
||||||
actual
|
actual annotation class Ann
|
||||||
annotation class Ann
|
|
||||||
@@ -3508,6 +3508,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/changeVisibility/private"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/changeVisibility/private"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("annotated.kt")
|
||||||
|
public void testAnnotated() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/changeVisibility/private/annotated.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("hasModifier1.kt")
|
@TestMetadata("hasModifier1.kt")
|
||||||
public void testHasModifier1() throws Exception {
|
public void testHasModifier1() throws Exception {
|
||||||
runTest("idea/testData/intentions/changeVisibility/private/hasModifier1.kt");
|
runTest("idea/testData/intentions/changeVisibility/private/hasModifier1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user