When '.' is typed on a new line, automatically adjust line indent for a chained call (solves IDEA-255648)

GitOrigin-RevId: 21315bb550bacc92cd2958c505eb0b5a989ee858
This commit is contained in:
Rustam Vishnyakov
2021-04-16 14:20:32 +03:00
committed by intellij-monorepo-bot
parent a0b11d47da
commit 0887e2cfb8
4 changed files with 40 additions and 0 deletions

View File

@@ -366,9 +366,29 @@ public class JavaTypedHandler extends TypedHandlerDelegate {
else if (c == ',' && handleAnnotationParameter(project, editor, file)) {
return Result.STOP;
}
else if (c == '.') {
if (handleDotTyped(project, editor, file)) {
return Result.STOP;
}
}
return Result.CONTINUE;
}
private static boolean handleDotTyped(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
int offset = editor.getCaretModel().getOffset() - 1;
if (offset >= 0) {
Document document = editor.getDocument();
int line = document.getLineNumber(offset);
int lineStart = document.getLineStartOffset(line);
if (StringUtil.isEmptyOrSpaces(document.getCharsSequence().subSequence(lineStart, offset))) {
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
return true;
}
}
return false;
}
private static boolean handleAnnotationParameter(Project project, @NotNull Editor editor, @NotNull PsiFile file) {
int caret = editor.getCaretModel().getOffset();
if (mightBeInsideDefaultAnnotationAttribute(editor, caret - 2)) {

View File

@@ -0,0 +1,9 @@
public class Test {
void foo1() {
foo(
strings
.stream()
.<caret>
);
}
}

View File

@@ -0,0 +1,9 @@
public class Test {
void foo1() {
foo(
strings
.stream()
<caret>
);
}
}

View File

@@ -152,6 +152,8 @@ public class JavaTypingTest extends BasePlatformTestCase {
public void testEqualAfterBitwiseOp() { doTest('='); }
public void testDotOnNewLine() { doTest('.'); }
public void testEqualAfterBitwiseOp2() {
myFixture.configureByFile(getTestName(true) + "_before.java");
CommonCodeStyleSettings settings = CodeStyle.getLanguageSettings(myFixture.getFile());