IDEA-69745 Buggy completion for Point2D.Double and similar classes

This commit is contained in:
peter
2011-07-12 18:10:11 +02:00
parent 47a6fc0a41
commit 8cd9bc819f
5 changed files with 48 additions and 1 deletions
@@ -396,6 +396,10 @@ public class ImportHelper{
}
}
if (useOnDemand && curRefClass != null && "java.lang".equals(StringUtil.getPackageName(curRefClass.getQualifiedName()))) {
return false;
}
try {
PsiImportList importList = file.getImportList();
PsiImportStatement statement = useOnDemand ? factory.createImportStatementOnDemand(packageName) : factory.createImportStatement(refClass);
@@ -103,7 +103,15 @@ public class ReferenceAdjuster {
return (TreeElement)replaceReferenceWithFQ(element, (PsiClass)refElement);
}
else {
return (TreeElement)makeShortReference((CompositeElement)element, (PsiClass)refElement, addImports);
int oldLength = element.getTextLength();
TreeElement treeElement = (TreeElement)makeShortReference((CompositeElement)element, (PsiClass)refElement, addImports);
if (treeElement.getTextLength() == oldLength && ((PsiClass)refElement).getContainingClass() != null) {
PsiElement qualifier = ref.getQualifier();
if (qualifier instanceof PsiJavaCodeReferenceElement && ((PsiJavaCodeReferenceElement)qualifier).resolve() instanceof PsiClass) {
process((TreeElement)qualifier.getNode(), addImports, uncompleteCode);
}
}
return treeElement;
}
}
}
@@ -0,0 +1,12 @@
import java.awt.geom.Point2D;
class UTest {
void foo() {
Point2D.Double d = new Point2D.Double();<caret>
}
void bar() {
Double d;
}
}
@@ -0,0 +1,12 @@
import java.awt.geom.Point2D;
class UTest {
void foo() {
Point2D.Double d = new <caret>
}
void bar() {
Double d;
}
}
@@ -1017,6 +1017,17 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doActionTest();
}
public void testInnerClassImports() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).INSERT_INNER_CLASS_IMPORTS = true;
try {
myFixture.addClass("package java.awt.geom; public class Point2D { public static class Double {} }");
doActionTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).INSERT_INNER_CLASS_IMPORTS = false;
}
}
public void testCastWithGenerics() throws Throwable {
doActionTest();
}