in completing an anonymous class, the closing parenthesis should be inserted regardless of the pair bracket settings (IDEA-63392)

This commit is contained in:
peter.gromov
2010-12-23 18:32:16 +03:00
parent 11014fdc4e
commit 4240c6817e
6 changed files with 53 additions and 25 deletions
@@ -921,7 +921,18 @@ public class JavaCompletionUtil {
return toDelete;
}
public static void insertParentheses(final InsertionContext context, final LookupElement item, boolean overloadsMatter, boolean hasParams) {
public static void insertParentheses(final InsertionContext context,
final LookupElement item,
boolean overloadsMatter,
boolean hasParams) {
insertParentheses(context, item, overloadsMatter, hasParams, false);
}
public static void insertParentheses(final InsertionContext context,
final LookupElement item,
boolean overloadsMatter,
boolean hasParams,
final boolean forceClosingParenthesis) {
final Editor editor = context.getEditor();
final char completionChar = context.getCompletionChar();
final PsiFile file = context.getFile();
@@ -933,28 +944,25 @@ public class JavaCompletionUtil {
final boolean addCompletionChar = context.shouldAddCompletionChar();
context.setAddCompletionChar(false);
final boolean needLeftParenth = isToInsertParenth(file.findElementAt(context.getStartOffset()));
final boolean needRightParenth = !smart && (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET || hasTail);
final boolean needRightParenth = forceClosingParenthesis || !smart && (CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET || hasTail);
if (hasTail) {
hasParams = false;
}
if (needLeftParenth) {
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
ParenthesesInsertHandler.getInstance(hasParams,
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,
needRightParenth,
styleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
).handleInsert(context, item);
}
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
ParenthesesInsertHandler.getInstance(hasParams,
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,
needRightParenth,
styleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
).handleInsert(context, item);
if (needLeftParenth && hasParams) {
if (hasParams) {
// Invoke parameters popup
AutoPopupController.getInstance(file.getProject()).autoPopupParameterInfo(editor, overloadsMatter ? null : (PsiElement)item.getObject());
}
if (smart || needLeftParenth && needRightParenth && addCompletionChar) {
if (smart || needRightParenth && addCompletionChar) {
TailType toInsert = tailType;
LookupItem lookupItem = item.as(LookupItem.class);
if (lookupItem == null || lookupItem.getAttribute(LookupItem.TAIL_TYPE_ATTR) != TailType.UNKNOWN) {
@@ -970,11 +978,6 @@ public class JavaCompletionUtil {
}
}
public static boolean isToInsertParenth(PsiElement place){
if (place == null) return true;
return !(place.getParent() instanceof PsiImportStaticReferenceElement);
}
//need to shorten references in type argument list
public static void shortenReference(final PsiFile file, final int offset) throws IncorrectOperationException {
final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());