Fixed formatting of doc-comments for parameters

This commit is contained in:
Valentin Kipyatkov
2014-10-31 18:56:28 +03:00
parent 00fdd52b35
commit bfdb756e22
4 changed files with 53 additions and 5 deletions
@@ -29,11 +29,7 @@ import com.intellij.formatting.ASTBlock
import org.jetbrains.jet.plugin.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
import com.intellij.formatting.SpacingBuilder
import com.intellij.formatting.SpacingBuilder.RuleBuilder
import com.intellij.formatting.DependentSpacingRule
import com.intellij.formatting.DependentSpacingRule.Trigger
import com.intellij.formatting.DependentSpacingRule.Anchor
import com.intellij.openapi.util.TextRange
import com.intellij.formatting.DependantSpacingImpl
import org.jetbrains.jet.lexer.JetTokens
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(
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 {
@@ -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);
}
@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")
public void testParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/formatter/Parameters.after.kt");