Implement option for wrapping class annotations

This commit is contained in:
Dmitry Jemerov
2017-06-22 19:49:59 +02:00
parent 6c62b60147
commit a379a814ba
10 changed files with 34 additions and 12 deletions
@@ -30,10 +30,7 @@ import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
import org.jetbrains.kotlin.kdoc.parser.KDocElementTypes
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.psi.KtBlockExpression
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtSuperTypeListEntry
import org.jetbrains.kotlin.psi.*
import java.util.*
private val QUALIFIED_OPERATION = TokenSet.create(DOT, SAFE_ACCESS)
@@ -353,15 +350,22 @@ abstract class KotlinCommonBlock(
}
elementType === KtNodeTypes.MODIFIER_LIST ->
when (node.treeParent.elementType) {
KtNodeTypes.VALUE_PARAMETER ->
when (node.treeParent.psi) {
is KtParameter ->
return getWrappingStrategyForItemList(commonSettings.PARAMETER_ANNOTATION_WRAP,
KtNodeTypes.ANNOTATION_ENTRY,
!node.treeParent.isFirstParameter())
is KtClassOrObject ->
return getWrappingStrategyForItemList(commonSettings.CLASS_ANNOTATION_WRAP,
KtNodeTypes.ANNOTATION_ENTRY)
}
elementType === KtNodeTypes.VALUE_PARAMETER ->
return wrapAfterAnnotation(commonSettings.PARAMETER_ANNOTATION_WRAP)
node.psi is KtClassOrObject ->
return wrapAfterAnnotation(commonSettings.CLASS_ANNOTATION_WRAP)
}
return WrappingStrategy.NoWrapping
@@ -30,7 +30,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide
override fun getCodeSample(settingsType: LanguageCodeStyleSettingsProvider.SettingsType): String = when (settingsType) {
LanguageCodeStyleSettingsProvider.SettingsType.WRAPPING_AND_BRACES_SETTINGS ->
"""
public class ThisIsASampleClass : Comparable<*>, Appendable {
@Deprecated("Foo") public class ThisIsASampleClass : Comparable<*>, Appendable {
val test =
12
@@ -236,6 +236,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide
"CALL_PARAMETERS_WRAP",
"METHOD_PARAMETERS_WRAP",
"EXTENDS_LIST_WRAP",
"CLASS_ANNOTATION_WRAP",
"PARAMETER_ANNOTATION_WRAP",
"METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE",
"METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE",
@@ -0,0 +1,4 @@
@Deprecated("Foo")
@Deprecated("Bar")
class Foo {
}
+2
View File
@@ -0,0 +1,2 @@
@Deprecated("Foo") @Deprecated("Bar") class Foo {
}
@@ -7,4 +7,5 @@ annotation class Foo
annotation class Bar
@Bar class C {}
@Bar
class C {}
@@ -7,4 +7,5 @@ annotation class Foo
annotation class Bar(val p: Int)
@Bar(1) class C {}
@Bar(1)
class C {}
@@ -7,4 +7,5 @@ annotation class Foo(val p: Int)
annotation class Bar(val p: Int, val s: String)
@Bar(1, "") class C {}
@Bar(1, "")
class C {}
@@ -7,4 +7,5 @@ annotation class Foo(val p: Int)
annotation class Bar(val p: Int, val s: String)
@Bar(p = 1, s = "") class C
@Bar(p = 1, s = "")
class C
@@ -5,4 +5,5 @@ annotation class OldAnnotation(val p: Int = 0)
annotation class NewAnnotation(val p: Int = 0, val newP: String = "")
@NewAnnotation class C
@NewAnnotation
class C
@@ -152,6 +152,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
doTest(fileName);
}
@TestMetadata("ClassAnnotationWrapping.after.kt")
public void testClassAnnotationWrapping() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ClassAnnotationWrapping.after.kt");
doTest(fileName);
}
@TestMetadata("ClassInBody.after.kt")
public void testClassInBody() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ClassInBody.after.kt");