mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-86286 Java: bad completion (interface without package?)
This commit is contained in:
@@ -46,12 +46,15 @@ public class InheritorsHolder implements Consumer<LookupElement> {
|
||||
if (object instanceof PsiClass) {
|
||||
final PsiClass psiClass = (PsiClass)object;
|
||||
if (JavaCompletionUtil.hasAccessibleInnerClass(psiClass, myPosition)) return;
|
||||
|
||||
ContainerUtil.addIfNotNull(myAddedClasses, getClassName(psiClass));
|
||||
registerClass(psiClass);
|
||||
}
|
||||
myResult.addElement(AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(lookupElement));
|
||||
}
|
||||
|
||||
public void registerClass(PsiClass psiClass) {
|
||||
ContainerUtil.addIfNotNull(myAddedClasses, getClassName(psiClass));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getClassName(PsiClass psiClass) {
|
||||
String name = psiClass.getQualifiedName();
|
||||
|
||||
+2
-2
@@ -225,11 +225,11 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return;
|
||||
}
|
||||
|
||||
final InheritorsHolder inheritors = new InheritorsHolder(position, result);
|
||||
if (JavaSmartCompletionContributor.IN_TYPE_ARGS.accepts(position)) {
|
||||
new TypeArgumentCompletionProvider(false).addCompletions(parameters, new ProcessingContext(), result);
|
||||
new TypeArgumentCompletionProvider(false, inheritors).addCompletions(parameters, new ProcessingContext(), result);
|
||||
}
|
||||
|
||||
final InheritorsHolder inheritors = new InheritorsHolder(position, result);
|
||||
if (JavaSmartCompletionContributor.AFTER_NEW.accepts(position)) {
|
||||
new JavaInheritorsGetter(ConstructorInsertHandler.BASIC_INSTANCE).generateVariants(parameters, result.getPrefixMatcher(), inheritors);
|
||||
}
|
||||
|
||||
+1
-1
@@ -286,7 +286,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
|
||||
extend(CompletionType.SMART, IN_TYPE_ARGS, new TypeArgumentCompletionProvider(true));
|
||||
extend(CompletionType.SMART, IN_TYPE_ARGS, new TypeArgumentCompletionProvider(true, null));
|
||||
|
||||
|
||||
extend(CompletionType.SMART, AFTER_NEW, new JavaInheritorsGetter(ConstructorInsertHandler.SMART_INSTANCE));
|
||||
|
||||
+16
-4
@@ -47,9 +47,11 @@ import static com.intellij.patterns.PsiJavaPatterns.psiElement;
|
||||
*/
|
||||
class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParameters> {
|
||||
private final boolean mySmart;
|
||||
@Nullable private final InheritorsHolder myInheritors;
|
||||
|
||||
TypeArgumentCompletionProvider(boolean smart) {
|
||||
TypeArgumentCompletionProvider(boolean smart, @Nullable InheritorsHolder inheritors) {
|
||||
mySmart = smart;
|
||||
myInheritors = inheritors;
|
||||
}
|
||||
|
||||
protected void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext processingContext, @NotNull final CompletionResultSet resultSet) {
|
||||
@@ -71,7 +73,7 @@ class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParame
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillExpectedTypeArgs(CompletionResultSet resultSet,
|
||||
private void fillExpectedTypeArgs(CompletionResultSet resultSet,
|
||||
PsiElement context,
|
||||
final PsiClass actualClass,
|
||||
final int index,
|
||||
@@ -98,6 +100,14 @@ class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParame
|
||||
typeItems.add(PsiTypeLookupItem.createLookupItem(arg, context));
|
||||
}
|
||||
|
||||
if (typeItems.size() == 1 && myInheritors != null) {
|
||||
PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(typeItems.get(0).getPsiType());
|
||||
if (aClass != null) {
|
||||
JavaCompletionUtil.setShowFQN(typeItems.get(0));
|
||||
myInheritors.registerClass(aClass);
|
||||
}
|
||||
}
|
||||
|
||||
resultSet.addElement(new TypeArgsLookupElement(typeItems, globalTail, ConstructorInsertHandler.hasConstructorParameters(actualClass, context)));
|
||||
}
|
||||
|
||||
@@ -208,8 +218,10 @@ class TypeArgumentCompletionProvider extends CompletionProvider<CompletionParame
|
||||
public void renderElement(LookupElementPresentation presentation) {
|
||||
myTypeItems.get(0).renderElement(presentation);
|
||||
presentation.setItemText(getLookupString());
|
||||
presentation.setTailText(null);
|
||||
presentation.setTypeText(null);
|
||||
if (myTypeItems.size() > 1) {
|
||||
presentation.setTailText(null);
|
||||
presentation.setTypeText(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
class Zoo {
|
||||
{
|
||||
List<String> l = new ArrayList<Stri<caret>>
|
||||
}
|
||||
}
|
||||
+7
@@ -1294,6 +1294,13 @@ public class ListUtils {
|
||||
assert !('return' in myFixture.lookupElementStrings)
|
||||
}
|
||||
|
||||
public void testDuplicateExpectedTypeInTypeArgumentList() {
|
||||
configure()
|
||||
def items = myFixture.lookupElements.findAll { it.lookupString == 'String' }
|
||||
assert items.size() == 1
|
||||
assert LookupElementPresentation.renderElement(items[0]).tailText?.contains('java.lang')
|
||||
}
|
||||
|
||||
public void testSameSignature() {
|
||||
configure()
|
||||
lookup.setCurrentItem(myItems[1])
|
||||
|
||||
Reference in New Issue
Block a user