mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java: fix PIEAE when completing a constructor call invalidates the class being completed
GitOrigin-RevId: bf6a03e359482f777e63e38383ecc4160cca82ec
This commit is contained in:
committed by
intellij-monorepo-bot
parent
330669bb22
commit
b65a8a3a35
+7
-3
@@ -52,6 +52,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
PsiJavaCodeReferenceElement ref = position != null && position.getParent() instanceof PsiJavaCodeReferenceElement ?
|
||||
(PsiJavaCodeReferenceElement) position.getParent() : null;
|
||||
PsiClass psiClass = item.getObject();
|
||||
SmartPsiElementPointer<PsiClass> classPointer = SmartPointerManager.createPointer(psiClass);
|
||||
final Project project = context.getProject();
|
||||
|
||||
final Editor editor = context.getEditor();
|
||||
@@ -90,18 +91,21 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
refEnd = context.trackOffset(context.getTailOffset(), false);
|
||||
|
||||
context.commitDocument();
|
||||
|
||||
psiClass = classPointer.dereference();
|
||||
|
||||
if (item.getUserData(JavaChainLookupElement.CHAIN_QUALIFIER) == null &&
|
||||
shouldInsertParentheses(file.findElementAt(context.getTailOffset() - 1))) {
|
||||
if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
|
||||
overwriteTopmostReference(context);
|
||||
context.commitDocument();
|
||||
}
|
||||
if (ConstructorInsertHandler.insertParentheses(context, item, psiClass, false)) {
|
||||
if (psiClass != null && ConstructorInsertHandler.insertParentheses(context, item, psiClass, false)) {
|
||||
fillTypeArgs |= psiClass.hasTypeParameters() && PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
}
|
||||
else if (insertingAnnotation(context, item)) {
|
||||
if (shouldHaveAnnotationParameters(psiClass)) {
|
||||
if (psiClass != null && shouldHaveAnnotationParameters(psiClass)) {
|
||||
JavaCompletionUtil.insertParentheses(context, item, false, true);
|
||||
}
|
||||
if (context.getCompletionChar() == Lookup.NORMAL_SELECT_CHAR || context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) {
|
||||
@@ -117,7 +121,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
JavaCompletionUtil.promptTypeArgs(context, context.getOffset(refEnd));
|
||||
}
|
||||
else if (context.getCompletionChar() == Lookup.COMPLETE_STATEMENT_SELECT_CHAR &&
|
||||
psiClass.getTypeParameters().length == 1 &&
|
||||
psiClass != null && psiClass.getTypeParameters().length == 1 &&
|
||||
PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5)) {
|
||||
wrapFollowingTypeInGenerics(context, context.getOffset(refEnd));
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class Cx {
|
||||
Another F = new C<caret>Another(
|
||||
f -> ((String)f).stream().anyMatch(c -> c.m(f) != null));
|
||||
|
||||
}
|
||||
|
||||
class Another {}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class Cx {
|
||||
Another F = new Cx()<caret>Another(
|
||||
f -> ((String)f).stream().anyMatch(c -> c.m(f) != null));
|
||||
|
||||
}
|
||||
|
||||
class Another {}
|
||||
+2
@@ -2216,4 +2216,6 @@ class Abc {
|
||||
assert !lookup
|
||||
}.assertTiming()
|
||||
}
|
||||
|
||||
void testNoExceptionsWhenCompletingInapplicableClassNameAfterNew() { doTest('\n') }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user