IDEA-54362 When "Insert pair bracket" on Editor->Smart keys page is off, IDEA still inserts both parentheses on autocomplete lookup, but overtype doesn't work for functions with at least one argument

This commit is contained in:
peter.gromov
2010-12-03 15:29:05 +03:00
parent 579c1d30c1
commit 1209d0d670
4 changed files with 22 additions and 15 deletions
@@ -930,7 +930,7 @@ public class JavaCompletionUtil {
final boolean needLeftParenth = isToInsertParenth(file.findElementAt(context.getStartOffset()));
final boolean needRightParenth = shouldInsertRParenth(context.getCompletionChar(), tailType, hasParams);
final boolean needRightParenth = tailType != TailType.SMART_COMPLETION && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
if (needLeftParenth) {
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
@@ -948,6 +948,10 @@ public class JavaCompletionUtil {
}
if (tailType == TailType.SEMICOLON) {
if (!needRightParenth) {
return;
}
PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
if (psiElement().beforeLeaf(psiElement().withText(".")).accepts(file.findElementAt(context.getTailOffset() - 1))) {
return;
@@ -959,19 +963,6 @@ public class JavaCompletionUtil {
}
}
public static boolean shouldInsertRParenth(char completionChar, TailType tailType, boolean hasParams) {
if (tailType == TailType.SMART_COMPLETION) {
return false;
}
if (completionChar == '(' && !hasParams) {
//it's highly probable that the user will type ')' next and it may not be overwritten if the flag is off
return CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
}
return true;
}
@NotNull
public static TailType getTailType(final LookupElement item, InsertionContext context) {
final char completionChar = context.getCompletionChar();
@@ -0,0 +1,8 @@
class MyClass {
void foo() {}
{
fo<caret>
}
}
@@ -0,0 +1,8 @@
class MyClass {
void foo() {}
{
foo(<caret>
}
}
@@ -3,6 +3,6 @@ class MyClass {
void foo() {}
{
foo();<caret>
foo(<caret>
}
}