all possible class names should be a valid lookup strings when completing an inner class after new

This commit is contained in:
peter
2011-11-08 20:38:05 +01:00
parent 778ab50cd3
commit 79f82fec64
4 changed files with 36 additions and 2 deletions
@@ -31,6 +31,9 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
/**
* @author peter
*/
@@ -168,17 +171,22 @@ public class PsiTypeLookupItem extends LookupItem {
}
}
PsiClass resolved = JavaPsiFacade.getInstance(psiClass.getProject()).getResolveHelper().resolveReferencedClass(psiClass.getName(), context);
Set<String> allStrings = new HashSet<String>();
String lookupString = psiClass.getName();
allStrings.add(lookupString);
if (!psiClass.getManager().areElementsEquivalent(resolved, psiClass)) {
// inner class name should be shown qualified if its not accessible by single name
PsiClass aClass = psiClass.getContainingClass();
while (aClass != null) {
lookupString = aClass.getName() + '.' + lookupString;
allStrings.add(lookupString);
aClass = aClass.getContainingClass();
}
}
PsiTypeLookupItem item = new PsiTypeLookupItem(psiClass, lookupString, diamond, bracketsCount);
item.addLookupStrings(allStrings.toArray(new String[allStrings.size()]));
item.setAttribute(SUBSTITUTOR, substitutor);
return item;
}
@@ -0,0 +1,12 @@
public class JavaClass {
{
Outer.Boo b = new Outer.Boo();<caret>
}
}
class Outer {
static class Boo { }
}
class ABooImpl extends Outer.Boo { }
@@ -0,0 +1,12 @@
public class JavaClass {
{
Outer.Boo b = new B<caret>
}
}
class Outer {
static class Boo { }
}
class ABooImpl extends Outer.Boo { }
@@ -411,8 +411,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testParameterizedConstructor() throws Throwable { doTest(); }
public void testNewInnerClassNameShortPrefix() throws Throwable { doTest(); }
public void testNewInnerOfParameterizedClass() throws Throwable { doTest(); }
public void testQualifiedThisInAnonymousConstructor() throws Throwable { doTest(); }
public void testExceptionTwice() throws Throwable { doTest(); }
@@ -684,7 +686,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testSuggestInstanceofedValueInComplexIf() throws Throwable { doTest(); }
public void testSuggestInstanceofedValueInElseNegated() throws Throwable { doTest(); }
public void testSuggestInstanceofedValueAfterReturn() throws Throwable { doTest(); }
public void testNoInstanceofedValueWhenBasicSuits() throws Throwable { doTest(); }