Add modifiers on the same line even after annotation #KT-26492 Fixed

This commit is contained in:
Mikhail Glukhikh
2018-08-30 14:37:16 +03:00
parent 4dd95e5640
commit 53e7778078
5 changed files with 22 additions and 4 deletions
@@ -88,14 +88,20 @@ internal fun addModifier(modifierList: KtModifierList, modifier: KtModifierKeywo
fun placeAfter(child: PsiElement): Boolean {
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 order = MODIFIERS_ORDER.indexOf(elementType)
return newModifierOrder > order
}
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)
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,5 +1,4 @@
package kotlin
// Ann: to be implemented
actual
annotation class Ann
actual 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);
}
@TestMetadata("annotated.kt")
public void testAnnotated() throws Exception {
runTest("idea/testData/intentions/changeVisibility/private/annotated.kt");
}
@TestMetadata("hasModifier1.kt")
public void testHasModifier1() throws Exception {
runTest("idea/testData/intentions/changeVisibility/private/hasModifier1.kt");