mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-95660 Groovy: complete inaccessible constructor in new expr position caret in wrong place
This commit is contained in:
+16
-4
@@ -405,12 +405,24 @@ public class GroovyCompletionUtil {
|
||||
}
|
||||
|
||||
public static boolean hasConstructorParameters(@NotNull PsiClass clazz, @NotNull GroovyPsiElement place) {
|
||||
for (GroovyResolveResult result : ResolveUtil.getAllClassConstructors(clazz, place, PsiSubstitutor.EMPTY, null)) {
|
||||
if (result.isAccessible() && ((PsiMethod)result.getElement()).getParameterList().getParametersCount() > 0) {
|
||||
return true;
|
||||
final GroovyResolveResult[] constructors = ResolveUtil.getAllClassConstructors(clazz, place, PsiSubstitutor.EMPTY, null);
|
||||
|
||||
boolean hasParameters = false;
|
||||
boolean hasAccessibleConstructors = false;
|
||||
for (GroovyResolveResult result : constructors) {
|
||||
final PsiElement element = result.getElement();
|
||||
if (element instanceof PsiMethod) {
|
||||
if (((PsiMethod)element).getParameterList().getParametersCount() > 0) {
|
||||
hasParameters = true;
|
||||
}
|
||||
if (result.isAccessible()) {
|
||||
hasAccessibleConstructors = true;
|
||||
}
|
||||
if (hasAccessibleConstructors && hasParameters) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
return !hasAccessibleConstructors && hasParameters;
|
||||
}
|
||||
|
||||
public static void addImportForItem(PsiFile file, int startOffset, LookupItem item) throws IncorrectOperationException {
|
||||
|
||||
+35
@@ -1583,4 +1583,39 @@ this.<caret>
|
||||
void testPrimitiveTypeTailTextInSafeCast() {
|
||||
doBasicTest('print(a as boolea<caret>)', 'print(a as boolean<caret>)')
|
||||
}
|
||||
|
||||
void testCompleteInaccessibleConstructors() {
|
||||
doBasicTest('''\
|
||||
class Foooo {
|
||||
private Foooo(int x) {}
|
||||
}
|
||||
|
||||
new Fooo<caret>
|
||||
''', '''\
|
||||
class Foooo {
|
||||
private Foooo(int x) {}
|
||||
}
|
||||
|
||||
new Foooo(<caret>)
|
||||
''')
|
||||
}
|
||||
|
||||
void testCompleteInaccessibleVsAccessibleConstructors() {
|
||||
doBasicTest('''\
|
||||
class Foooo {
|
||||
private Foooo(int x) {}
|
||||
public Foooo() {}
|
||||
}
|
||||
|
||||
new Fooo<caret>
|
||||
''', '''\
|
||||
class Foooo {
|
||||
private Foooo(int x) {}
|
||||
public Foooo() {}
|
||||
}
|
||||
|
||||
new Foooo()<caret>
|
||||
''')
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user