final TailType tailType = getTailType(item, context);
final Document document = editor.getDocument();
final PsiFile file = context.getFile();
+ final int offset = editor.getCaretModel().getOffset();
context.setAddCompletionChar(false);
final LookupElement[] allItems = context.getElements();
- boolean signatureSelected = allItems.length > 1 || item.getUserData(LookupItem.FORCE_SHOW_SIGNATURE_ATTR) != null;
+ final boolean overloadsMatter = allItems.length == 1 && item.getUserData(LookupItem.FORCE_SHOW_SIGNATURE_ATTR) == null;
- int offset = editor.getCaretModel().getOffset();
+ final boolean hasParams = MethodParenthesesHandler.hasParams(item, allItems, overloadsMatter, myMethod);
final boolean needLeftParenth = isToInsertParenth(file.findElementAt(context.getStartOffset()));
- final boolean hasParams = MethodParenthesesHandler.hasParams(item, allItems, !signatureSelected, myMethod);
+ final boolean needRightParenth = shouldInsertRParenth(completionChar, tailType, hasParams);
+
if (needLeftParenth) {
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
- new MethodParenthesesHandler(myMethod, !signatureSelected,
+ new MethodParenthesesHandler(myMethod, overloadsMatter,
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,
- shouldInsertRightParenthesis(tailType)
+ needRightParenth
).handleInsert(context, item);
}
-
+
insertExplicitTypeParams(item, document, offset, file);
final PsiType type = myMethod.getReturnType();
if (needLeftParenth && hasParams) {
// Invoke parameters popup
- AutoPopupController.getInstance(myMethod.getProject()).autoPopupParameterInfo(editor, signatureSelected ? myMethod : null);
+ AutoPopupController.getInstance(myMethod.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : myMethod);
+ }
+ if (tailType == TailType.SMART_COMPLETION || needLeftParenth && needRightParenth) {
+ tailType.processTail(editor, context.getTailOffset());
}
- tailType.processTail(editor, context.getTailOffset());
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
- protected static boolean shouldInsertRightParenthesis(TailType tailType) {
- return tailType != TailType.SMART_COMPLETION;
+ private 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
checkResultByFile("/codeInsight/completion/normal/MethodWithLeftParTailType2_after.java");
}
+ public void testMethodWithLeftParTailTypeNoPairBrace() throws Exception {
+ final boolean old = CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET;
+ CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = false;
+
+ try {
+ configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
+ selectItem(myItems[0], '(');
+ checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
+
+ //no tail type should work the normal way
+ configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
+ selectItem(myItems[0]);
+ checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after2.java");
+ }
+ finally {
+ CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET = old;
+ }
+ }
+
public void testExcessSpaceInTypeCast() throws Throwable {
configureByFile("/codeInsight/completion/normal/" + getTestName(false) + ".java");
selectItem(myItems[0]);
final Document document = editor.getDocument();
PsiElement element = findNextToken(context);
- final boolean hasParams = placeCaretInsideParentheses(context, item);
-
final char completionChar = context.getCompletionChar();
+ final boolean putCaretInside = completionChar == '(' || placeCaretInsideParentheses(context, item);
+
if (completionChar == '(') {
context.setAddCompletionChar(false);
}
if (isToken(last, ")")) {
int rparenthOffset = last.getTextRange().getStartOffset();
context.setTailOffset(rparenthOffset + 1);
- if (!hasParams) {
+ if (!putCaretInside) {
for (int i = lparenthOffset + 1; i < rparenthOffset; i++) {
if (!Character.isWhitespace(document.getCharsSequence().charAt(i))) {
return;
tailOffset = TailType.insertChar(editor, tailOffset, ' ');
}
document.insertString(tailOffset, ")");
- editor.getCaretModel().moveToOffset(hasParams ? caret : context.getTailOffset());
+ editor.getCaretModel().moveToOffset(putCaretInside ? caret : context.getTailOffset());
}
@Nullable