mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
[rev=nik] fix incorrect parentheses insertion when code style dictates spaces before & inside call parens (IDEA-49942)
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
public class Bar {
|
||||
{
|
||||
foo ( ba<caret> )
|
||||
}
|
||||
|
||||
void foo(int x) {}
|
||||
int bar() {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Bar {
|
||||
{
|
||||
foo ( ba<caret> )
|
||||
}
|
||||
|
||||
void foo(int x) {}
|
||||
int bar(int x) {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Bar {
|
||||
{
|
||||
foo ( bar ( <caret> ) )
|
||||
}
|
||||
|
||||
void foo(int x) {}
|
||||
int bar(int x) {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public class Bar {
|
||||
{
|
||||
foo ( bar ()<caret> )
|
||||
}
|
||||
|
||||
void foo(int x) {}
|
||||
int bar() {}
|
||||
}
|
||||
@@ -333,6 +333,18 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testMethodNoPairBrace() throws Exception {
|
||||
final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
|
||||
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;
|
||||
|
||||
try {
|
||||
doTest '\n'
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old;
|
||||
}
|
||||
}
|
||||
|
||||
public void testExcessSpaceInTypeCast() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
selectItem(myItems[0]);
|
||||
@@ -351,6 +363,20 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMethodParenthesesSpaces() throws Throwable {
|
||||
final settings = CodeStyleSettingsManager.getSettings(getProject())
|
||||
settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
|
||||
settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMethodParenthesesSpacesArgs() throws Throwable {
|
||||
final settings = CodeStyleSettingsManager.getSettings(getProject())
|
||||
settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
|
||||
settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAtUnderClassNoModifiers() throws Throwable {
|
||||
doTest();
|
||||
}
|
||||
@@ -691,6 +717,12 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
checkResult();
|
||||
}
|
||||
|
||||
private void doTest(String finishChar) throws Exception {
|
||||
configure()
|
||||
type finishChar
|
||||
checkResult();
|
||||
}
|
||||
|
||||
private void doAntiTest() throws Exception {
|
||||
configure()
|
||||
checkResultByFile(getTestName(false) + ".java");
|
||||
|
||||
@@ -134,25 +134,20 @@ public abstract class ParenthesesInsertHandler<T extends LookupElement> implemen
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
int tailOffset = context.getTailOffset();
|
||||
if (mySpaceBeforeParentheses) {
|
||||
tailOffset = TailType.insertChar(editor, tailOffset, ' ');
|
||||
}
|
||||
tailOffset = TailType.insertChar(editor, tailOffset, '(');
|
||||
if (mySpaceBetweenParentheses) {
|
||||
tailOffset = TailType.insertChar(editor, tailOffset, ' ');
|
||||
}
|
||||
document.insertString(context.getTailOffset(), getSpace(mySpaceBeforeParentheses) + "(" + getSpace(mySpaceBetweenParentheses));
|
||||
editor.getCaretModel().moveToOffset(context.getTailOffset());
|
||||
}
|
||||
|
||||
if (!myInsertRightParenthesis) return;
|
||||
|
||||
int tailOffset = context.getTailOffset();
|
||||
int caret = tailOffset;
|
||||
if (mySpaceBetweenParentheses) {
|
||||
tailOffset = TailType.insertChar(editor, tailOffset, ' ');
|
||||
document.insertString(context.getTailOffset(), getSpace(mySpaceBetweenParentheses) + ")");
|
||||
if (!putCaretInside) {
|
||||
editor.getCaretModel().moveToOffset(context.getTailOffset());
|
||||
}
|
||||
document.insertString(tailOffset, ")");
|
||||
editor.getCaretModel().moveToOffset(putCaretInside ? caret : context.getTailOffset());
|
||||
}
|
||||
|
||||
private static String getSpace(boolean needSpace) {
|
||||
return needSpace ? " " : "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user