KT-1545, KT-3161 KDoc formatter
This commit is contained in:
committed by
Natalia.Ukhorskaya
parent
c4bdf72054
commit
9dfe0f42a3
@@ -27,9 +27,13 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.JetNodeTypes.*;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
@@ -38,6 +42,7 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
* @see Block for good JavaDoc documentation
|
||||
*/
|
||||
public class JetBlock extends AbstractBlock {
|
||||
private static final int KDOC_COMMENT_INDENT = 1;
|
||||
private final ASTAlignmentStrategy myAlignmentStrategy;
|
||||
private final Indent myIndent;
|
||||
private final CodeStyleSettings mySettings;
|
||||
@@ -208,6 +213,9 @@ public class JetBlock extends AbstractBlock {
|
||||
}
|
||||
return new ChildAttributes(Indent.getContinuationIndent(), null);
|
||||
}
|
||||
else if (type == DOC_COMMENT) {
|
||||
return new ChildAttributes(Indent.getSpaceIndent(KDOC_COMMENT_INDENT), null);
|
||||
}
|
||||
|
||||
if (isIncomplete()) {
|
||||
return super.getChildAttributes(newChildIndex);
|
||||
@@ -321,6 +329,11 @@ public class JetBlock extends AbstractBlock {
|
||||
.in(PROPERTY, FUN)
|
||||
.notForType(BLOCK)
|
||||
.set(Indent.getContinuationWithoutFirstIndent()),
|
||||
|
||||
ASTIndentStrategy.forNode("KDoc comment indent")
|
||||
.in(DOC_COMMENT)
|
||||
.forType(KDocTokens.LEADING_ASTERISK, KDocTokens.END)
|
||||
.set(Indent.getSpaceIndent(KDOC_COMMENT_INDENT)),
|
||||
};
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
import static org.jetbrains.jet.JetNodeTypes.*;
|
||||
@@ -34,8 +35,9 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
|
||||
@NotNull
|
||||
@Override
|
||||
public FormattingModel createModel(PsiElement element, CodeStyleSettings settings) {
|
||||
PsiFile containingFile = element.getContainingFile().getViewProvider().getPsi(JetLanguage.INSTANCE);
|
||||
JetBlock block = new JetBlock(
|
||||
element.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings,
|
||||
containingFile.getNode(), ASTAlignmentStrategy.getNullStrategy(), Indent.getNoneIndent(), null, settings,
|
||||
createSpacingBuilder(settings));
|
||||
|
||||
return FormattingModelProvider.createFormattingModelForPsiFile(
|
||||
@@ -53,6 +55,7 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
|
||||
.between(IMPORT_DIRECTIVE, IMPORT_DIRECTIVE).lineBreakInCode()
|
||||
.after(IMPORT_DIRECTIVE).blankLines(1)
|
||||
|
||||
.before(DOC_COMMENT).lineBreakInCode()
|
||||
.before(FUN).lineBreakInCode()
|
||||
.before(PROPERTY).lineBreakInCode()
|
||||
.between(FUN, FUN).blankLines(1)
|
||||
@@ -105,6 +108,9 @@ public class JetFormattingModelBuilder implements FormattingModelBuilder {
|
||||
|
||||
.between(VALUE_ARGUMENT_LIST, FUNCTION_LITERAL_EXPRESSION).spaces(1)
|
||||
.aroundInside(ARROW, WHEN_ENTRY).spaces(1)
|
||||
|
||||
// KDoc
|
||||
.between(KDocTokens.LEADING_ASTERISK, KDocTokens.TEXT).spacing(1, 100, 0, true, 100)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/**
|
||||
* x<caret>
|
||||
*/
|
||||
fun test() = 0
|
||||
*/
|
||||
@@ -1,5 +1,4 @@
|
||||
/**
|
||||
* x
|
||||
* <caret>
|
||||
*/
|
||||
fun test() = 0
|
||||
*/
|
||||
@@ -0,0 +1,4 @@
|
||||
class Test { /**
|
||||
* do something
|
||||
*/ fun doSomething() = 0
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Test {
|
||||
/**
|
||||
* do something
|
||||
*/
|
||||
fun doSomething() = 0
|
||||
}
|
||||
@@ -72,6 +72,10 @@ public class JetFormatterTest extends AbstractJetFormatterTest {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testKDoc() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMultilineFunctionLiteral() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user