Support indent after comma in parameter lists

This commit is contained in:
Rustam Vishnyakov
2016-11-10 18:00:14 +03:00
parent 48c061965f
commit d1fdf69d47
3 changed files with 21 additions and 4 deletions
@@ -147,7 +147,7 @@ public abstract class SemanticEditorPosition {
public int getStartOffset() {
return myIterator.getStart();
}
@SuppressWarnings("unused")
public boolean isAtAnyOf(@NotNull SyntaxElement... syntaxElements) {
if (!myIterator.atEnd()) {
@@ -172,6 +172,13 @@ public abstract class SemanticEditorPosition {
return -1;
}
public boolean hasEmptyLineAfter(int offset) {
for (int i = offset; i < myIterator.getEnd(); i ++) {
if (myChars.charAt(i) == '\n') return true;
}
return false;
}
public EditorEx getEditor() {
return myEditor;
}
@@ -57,7 +57,13 @@ class IndentCalculator {
return CharArrayUtil.shiftBackward(currPosition.getChars(), currPosition.getStartOffset(), " \t\n\r");
}
};
public final static BaseLineOffsetCalculator LINE_AFTER = new BaseLineOffsetCalculator() {
@Override
public int getOffsetInBaseIndentLine(@NotNull SemanticEditorPosition currPosition) {
return CharArrayUtil.shiftForward(currPosition.getChars(), currPosition.getStartOffset(), " \t\n\r");
}
};
@Nullable
String getIndentString(@Nullable Language language, @NotNull SemanticEditorPosition currPosition) {
@@ -85,9 +85,13 @@ public abstract class JavaLikeLangLineIndentProvider implements LineIndentProvid
if (getPosition(editor, offset).matchesRule(
position -> position.isAt(Whitespace) &&
position.isAtMultiline())) {
//noinspection StatementWithEmptyBody
if (getPosition(editor, offset).before().isAt(Comma)) {
// TODO: Add support
SemanticEditorPosition position = getPosition(editor,offset);
if (position.hasEmptyLineAfter(offset) &&
!position.after().isAtAnyOf(ArrayClosingBracket, BlockOpeningBrace, BlockClosingBrace, RightParenthesis) &&
!position.isAtEnd()) {
return myFactory.createIndentCalculator(NONE, IndentCalculator.LINE_AFTER);
}
}
else if (getPosition(editor, offset + 1).isAt(BlockClosingBrace)) {
return myFactory.createIndentCalculator(