mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
IDEA-41246 Ctrl + Shift + Enter problem if array elements are not the same line
This commit is contained in:
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiArrayInitializerExpression;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
@@ -34,21 +34,10 @@ public class MissingArrayInitializerBraceFixer implements Fixer {
|
||||
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
|
||||
if (!(psiElement instanceof PsiArrayInitializerExpression)) return;
|
||||
PsiArrayInitializerExpression expr = (PsiArrayInitializerExpression)psiElement;
|
||||
final Document doc = editor.getDocument();
|
||||
final String exprText = expr.getText();
|
||||
final TextRange textRange = expr.getTextRange();
|
||||
final int endOffset = textRange.getEndOffset();
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
final int startOffset = textRange.getStartOffset();
|
||||
if (caretOffset > startOffset && caretOffset < endOffset) {
|
||||
final int index = exprText.indexOf('\n', caretOffset - startOffset);
|
||||
if (index >= 0) {
|
||||
doc.insertString(index + startOffset, "}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!exprText.endsWith("}")) {
|
||||
doc.insertString(endOffset, "}");
|
||||
if (!expr.getText().endsWith("}")) {
|
||||
PsiErrorElement err = ContainerUtil.findInstance(expr.getChildren(), PsiErrorElement.class);
|
||||
int endOffset = (err != null ? err : expr).getTextRange().getEndOffset();
|
||||
editor.getDocument().insertString(endOffset, "}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Foo {
|
||||
public void fails() {
|
||||
final String ORIGIN = "";
|
||||
final String[] expected = {ORIGIN<caret>
|
||||
|
||||
System.out.println ( "tes");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Foo {
|
||||
public void fails() {
|
||||
final String ORIGIN = "";
|
||||
final String[] expected = {ORIGIN};<caret>
|
||||
|
||||
System.out.println ( "tes");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Foo {
|
||||
public void fails() {
|
||||
String[] a = new String[] {
|
||||
getName(<caret>
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class Foo {
|
||||
public void fails() {
|
||||
String[] a = new String[]{
|
||||
getName()
|
||||
};<caret>
|
||||
}
|
||||
}
|
||||
@@ -275,7 +275,9 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testPrivateInterfaceMethodBody() { doTest(); }
|
||||
|
||||
public void testArrayInitializerRBracket() throws Exception { doTest(); }
|
||||
|
||||
public void testArrayInitializerRBrace() { doTest(); }
|
||||
public void testArrayInitializerSeveralLines() { doTest(); }
|
||||
|
||||
public void testReturnInLambda() { doTest(); }
|
||||
|
||||
private void doTestBracesNextLineStyle() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user