mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
skip inserting diamond when choosing class completion variant with (
This commit is contained in:
+4
-20
@@ -72,7 +72,8 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
if (delegate instanceof PsiTypeLookupItem) {
|
||||
fillTypeArgs = !isRawTypeExpected(context, (PsiTypeLookupItem)delegate) &&
|
||||
psiClass.getTypeParameters().length > 0 &&
|
||||
((PsiTypeLookupItem)delegate).calcGenerics(position).isEmpty();
|
||||
((PsiTypeLookupItem)delegate).calcGenerics(position).isEmpty() &&
|
||||
context.getCompletionChar() != '(';
|
||||
delegate.handleInsert(context);
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting(context.getFile().getViewProvider());
|
||||
}
|
||||
@@ -99,7 +100,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
editor.getDocument().insertString(offset, " {}");
|
||||
editor.getCaretModel().moveToOffset(offset + 2);
|
||||
|
||||
if (fillTypeArgs && promptTypeArgs(context, context.getOffset(insideRef))) return;
|
||||
if (fillTypeArgs && JavaCompletionUtil.promptTypeArgs(context, context.getOffset(insideRef))) return;
|
||||
|
||||
context.setLaterRunnable(generateAnonymousBody(editor, context.getFile()));
|
||||
}
|
||||
@@ -116,7 +117,7 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
if (mySmart) {
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed(JavaCompletionFeatures.AFTER_NEW);
|
||||
}
|
||||
if (fillTypeArgs && promptTypeArgs(context, context.getOffset(insideRef))) return;
|
||||
if (fillTypeArgs && JavaCompletionUtil.promptTypeArgs(context, context.getOffset(insideRef))) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,23 +137,6 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean promptTypeArgs(InsertionContext context, int offset) {
|
||||
if (offset < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OffsetKey key = context.trackOffset(offset, false);
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
|
||||
offset = context.getOffset(key);
|
||||
if (offset < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
context.getDocument().insertString(offset, "<>");
|
||||
context.getEditor().getCaretModel().moveToOffset(offset + 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean insertParentheses(InsertionContext context,
|
||||
LookupItem delegate,
|
||||
final PsiClass psiClass,
|
||||
|
||||
+2
-2
@@ -125,8 +125,8 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
}
|
||||
}
|
||||
|
||||
if (fillTypeArgs) {
|
||||
ConstructorInsertHandler.promptTypeArgs(context, context.getOffset(refEnd));
|
||||
if (fillTypeArgs && context.getCompletionChar() != '(') {
|
||||
JavaCompletionUtil.promptTypeArgs(context, context.getOffset(refEnd));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import com.intellij.psi.filters.ElementFilter;
|
||||
import com.intellij.psi.filters.element.ExcludeDeclaredFilter;
|
||||
import com.intellij.psi.filters.element.ExcludeSillyAssignment;
|
||||
import com.intellij.psi.html.HtmlTag;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.impl.source.PsiImmediateClassType;
|
||||
import com.intellij.psi.javadoc.PsiDocToken;
|
||||
import com.intellij.psi.scope.BaseScopeProcessor;
|
||||
@@ -909,4 +910,21 @@ public class JavaCompletionUtil {
|
||||
}
|
||||
return !hasAccessibleInnerClass(psiClass, position);
|
||||
}
|
||||
|
||||
public static boolean promptTypeArgs(InsertionContext context, int offset) {
|
||||
if (offset < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OffsetKey key = context.trackOffset(offset, false);
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
|
||||
offset = context.getOffset(key);
|
||||
if (offset < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
context.getDocument().insertString(offset, "<>");
|
||||
context.getEditor().getCaretModel().moveToOffset(offset + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user