Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2016-08-23 14:11:25 +03:00
@@ -56,7 +56,8 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
DocBlockStart,
DocBlockEnd,
LineComment,
Comma
Comma,
LanguageStartDelimiter
}
@@ -104,6 +105,14 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
.isAt(BlockClosingBrace))) {
return myFactory.createIndentCalculator(getBlockIndentType(project, language), IndentCalculator.LINE_BEFORE);
}
else if (getPosition(editor, offset).matchesRule(position -> position.before().isAt(Semicolon))) {
SemanticEditorPosition beforeSemicolon = getPosition(editor, offset).before().beforeOptional(Semicolon);
int statementStart = getStatementStartOffset(beforeSemicolon);
SemanticEditorPosition atStatementStart = getPosition(editor, statementStart);
if (!atStatementStart.isAfterOnSameLine(ForKeyword)) {
return myFactory.createIndentCalculator(NONE, position -> statementStart);
}
}
else if (getPosition(editor, offset).matchesRule(
position -> position.before().isAt(ArrayOpeningBracket)
)) {
@@ -161,15 +170,16 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
private int getBlockStatementStartOffset(@NotNull SemanticEditorPosition position) {
Language currLanguage = position.getLanguage();
position.before().beforeOptional(BlockOpeningBrace);
if (position.isAt(Whitespace)) {
if (position.isAtMultiline()) return position.after().getStartOffset();
position.before();
}
if (position.isAt(RightParenthesis)) {
position.beforeParentheses(LeftParenthesis, RightParenthesis);
}
return getStatementStartOffset(position);
}
private int getStatementStartOffset(@NotNull SemanticEditorPosition position) {
Language currLanguage = position.getLanguage();
while (!position.isAtEnd()) {
if (currLanguage == Language.ANY || currLanguage == null) currLanguage = position.getLanguage();
if (position.isAt(Colon)) {
@@ -178,8 +188,18 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
return afterColon.getStartOffset();
}
}
if (position.isAtAnyOf(Semicolon, BlockOpeningBrace, BlockClosingBrace, BlockComment, DocBlockEnd, LineComment, LeftParenthesis) ||
(position.getLanguage() != Language.ANY) && !position.isAtLanguage(currLanguage)) {
else if (position.isAt(RightParenthesis)) {
position.beforeParentheses(LeftParenthesis, RightParenthesis);
}
else if (position.isAtAnyOf(Semicolon,
BlockOpeningBrace,
BlockClosingBrace,
BlockComment,
DocBlockEnd,
LineComment,
LeftParenthesis,
LanguageStartDelimiter) ||
(position.getLanguage() != Language.ANY) && !position.isAtLanguage(currLanguage)) {
SemanticEditorPosition statementStart = getPosition(position.getEditor(), position.getStartOffset());
if (!statementStart.after().afterOptional(Whitespace).isAtEnd()) {
return statementStart.getStartOffset();
@@ -187,7 +207,7 @@ public abstract class JavaLikeLangLineIndentProvider extends FormatterBasedLineI
}
position.before();
}
return -1;
return 0;
}