IDEA-95660 Groovy: complete inaccessible constructor in new expr position caret in wrong place

This commit is contained in:
Max Medvedev
2012-11-29 16:24:30 +04:00
parent fd66e6f1d1
commit 21b369c8c7
2 changed files with 51 additions and 4 deletions
@@ -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 {
@@ -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>
''')
}
}