IDEA-223316 Name suggestions are not available when variable type is unresolved

GitOrigin-RevId: 20601bf806f770a4cf07c3a0a8c1d856f9c017fb
This commit is contained in:
peter
2019-09-30 10:32:59 +00:00
committed by intellij-monorepo-bot
parent fc82e319c3
commit bb7a79b54a
2 changed files with 21 additions and 1 deletions
@@ -106,7 +106,11 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
}
PsiType type = var.getType();
if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == null) return;
if (type instanceof PsiClassType &&
((PsiClassType)type).resolve() == null &&
seemsMistypedKeyword(((PsiClassType)type).getClassName())) {
return;
}
SuggestedNameInfo suggestedNameInfo = codeStyleManager.suggestVariableName(variableKind, propertyName, null, type, StringUtil.isEmpty(matcher.getPrefix()));
suggestedNameInfo = codeStyleManager.suggestUniqueVariableName(suggestedNameInfo, var, false);
@@ -138,6 +142,10 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
}
}
private static boolean seemsMistypedKeyword(String className) {
return className != null && !StringUtil.isCapitalized(className);
}
private static boolean hasStartMatches(PrefixMatcher matcher, Set<String> set) {
for (String s : set) {
if (matcher.isStartMatch(s)) {
@@ -307,4 +307,16 @@ class C {
assert myFixture.completeBasic()?.size() == 0
}
void "test suggest variable name when the type is unresolved but does not seem a mistyped keyword"() {
myFixture.configureByText 'a.java', '''
class C {
{
UndefinedType <caret>
}
}
'''
myFixture.completeBasic()
myFixture.assertPreferredCompletionItems 0, 'undefinedType', 'type'
}
}