Fixed formatting of doc-comments for parameters
This commit is contained in:
@@ -29,11 +29,7 @@ import com.intellij.formatting.ASTBlock
|
|||||||
import org.jetbrains.jet.plugin.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
|
import org.jetbrains.jet.plugin.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
|
||||||
import com.intellij.formatting.SpacingBuilder
|
import com.intellij.formatting.SpacingBuilder
|
||||||
import com.intellij.formatting.SpacingBuilder.RuleBuilder
|
import com.intellij.formatting.SpacingBuilder.RuleBuilder
|
||||||
import com.intellij.formatting.DependentSpacingRule
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
import com.intellij.formatting.DependentSpacingRule.Trigger
|
|
||||||
import com.intellij.formatting.DependentSpacingRule.Anchor
|
|
||||||
import com.intellij.openapi.util.TextRange
|
|
||||||
import com.intellij.formatting.DependantSpacingImpl
|
|
||||||
|
|
||||||
val MODIFIERS_LIST_ENTRIES = TokenSet.orSet(TokenSet.create(ANNOTATION_ENTRY, ANNOTATION), MODIFIER_KEYWORDS)
|
val MODIFIERS_LIST_ENTRIES = TokenSet.orSet(TokenSet.create(ANNOTATION_ENTRY, ANNOTATION), MODIFIER_KEYWORDS)
|
||||||
|
|
||||||
@@ -63,6 +59,17 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
|
|||||||
|
|
||||||
inPosition(left = ENUM_ENTRY, right = ENUM_ENTRY).emptyLinesIfLineBreakInLeft(
|
inPosition(left = ENUM_ENTRY, right = ENUM_ENTRY).emptyLinesIfLineBreakInLeft(
|
||||||
emptyLines = 0, numSpacesOtherwise = 1, numberOfLineFeedsOtherwise = 0)
|
emptyLines = 0, numSpacesOtherwise = 1, numberOfLineFeedsOtherwise = 0)
|
||||||
|
|
||||||
|
val parameterWithDocCommentRule = {
|
||||||
|
(parent: ASTBlock, left: ASTBlock, right: ASTBlock) ->
|
||||||
|
if (right.getNode().getFirstChildNode().getElementType() == JetTokens.DOC_COMMENT) {
|
||||||
|
Spacing.createSpacing(0, 0, 1, true, settings.KEEP_BLANK_LINES_IN_DECLARATIONS)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inPosition(parent = VALUE_PARAMETER_LIST, right = VALUE_PARAMETER).customRule(parameterWithDocCommentRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
simple {
|
simple {
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
class A(
|
||||||
|
/**
|
||||||
|
* Doc comment
|
||||||
|
*/
|
||||||
|
public val p1: Int,
|
||||||
|
/** Doc comment */
|
||||||
|
public val p2: Int,
|
||||||
|
/**
|
||||||
|
* Doc
|
||||||
|
*/
|
||||||
|
val p2: String)
|
||||||
|
|
||||||
|
class B(
|
||||||
|
/** Doc1 */
|
||||||
|
val v: Int,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doc2
|
||||||
|
*/
|
||||||
|
val v2: Int
|
||||||
|
)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
class A(/**
|
||||||
|
* Doc comment
|
||||||
|
*/ public val p1: Int, /** Doc comment */ public val p2: Int, /**
|
||||||
|
* Doc
|
||||||
|
*/ val p2: String)
|
||||||
|
|
||||||
|
class B(
|
||||||
|
/** Doc1 */
|
||||||
|
val v: Int,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doc2
|
||||||
|
*/ val v2: Int
|
||||||
|
)
|
||||||
@@ -340,6 +340,12 @@ public class JetFormatterTestGenerated extends AbstractJetFormatterTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ParameterDocComments.after.kt")
|
||||||
|
public void testParameterDocComments() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/ParameterDocComments.after.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("Parameters.after.kt")
|
@TestMetadata("Parameters.after.kt")
|
||||||
public void testParameters() throws Exception {
|
public void testParameters() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/Parameters.after.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/Parameters.after.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user