Line indent provider: more cases fixed

This commit is contained in:
Rustam Vishnyakov
2016-06-03 13:16:55 +03:00
parent 0eb6dfbe43
commit 876df072b4
3 changed files with 33 additions and 2 deletions
@@ -52,6 +52,7 @@ public class JavaLineIndentProvider extends JavaLikeLangLineIndentProvider {
SYNTAX_MAP.put(JavaTokenType.C_STYLE_COMMENT, BlockComment);
SYNTAX_MAP.put(JavaDocTokenType.DOC_COMMENT_START, DocBlockStart);
SYNTAX_MAP.put(JavaDocTokenType.DOC_COMMENT_END, DocBlockEnd);
SYNTAX_MAP.put(JavaTokenType.COMMA, Comma);
}
@Nullable
@@ -88,6 +88,20 @@ public abstract class SemanticEditorPosition {
}
return this;
}
public SemanticEditorPosition findLeftParenthesisBackwardsSkippingNested(@NotNull SyntaxElement leftParenthesis,
@NotNull SyntaxElement rightParenthesis) {
while (!myIterator.atEnd()) {
if (rightParenthesis.equals(map(myIterator.getTokenType()))) {
beforeParentheses(leftParenthesis, rightParenthesis);
}
else if (leftParenthesis.equals(map(myIterator.getTokenType()))) {
break;
}
myIterator.retreat();
}
return this;
}
public boolean isAfterOnSameLine(@NotNull SyntaxElement... syntaxElements) {
myIterator.retreat();
@@ -54,7 +54,8 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
ForKeyword,
BlockComment,
DocBlockStart,
DocBlockEnd
DocBlockEnd,
Comma
}
@@ -79,7 +80,22 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
if (getPosition(editor, offset).matchesRule(
position -> position.isAt(Whitespace) &&
position.isAtMultiline())) {
if (getPosition(editor, offset).matchesRule(
//noinspection StatementWithEmptyBody
if (getPosition(editor, offset).before().isAt(Comma)) {
// TODO: Add support
}
else if (getPosition(editor, offset + 1).isAt(BlockClosingBrace)) {
return myFactory.createIndentCalculator(
NONE,
position -> {
position.findLeftParenthesisBackwardsSkippingNested(BlockOpeningBrace, BlockClosingBrace);
if (!position.isAtEnd()) {
return getBlockStartOffset(position);
}
return -1;
});
}
else if (getPosition(editor, offset).matchesRule(
position -> position
.before()
.beforeOptional(Semicolon)