preselect available type, leave inacessible in combo

This commit is contained in:
anna
2010-08-09 18:54:31 +04:00
parent a97f796ed0
commit d8b0141c02
6 changed files with 111 additions and 48 deletions
@@ -0,0 +1,6 @@
class Test {
void foo() {
class C {}
C c<caret>c;
}
}
@@ -0,0 +1,7 @@
class Test {
class C {}
void foo() {
C c<caret>c;
}
}
@@ -1,12 +1,13 @@
package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiLocalVariable;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.ui.TypeSelectorManagerImpl;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.testFramework.TestDataPath;
import com.intellij.util.VisibilityUtil;
@@ -87,6 +88,37 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase {
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
public void testResultedType() throws Exception {
checkDefaultType("java.lang.Object");
}
public void testResultedTypeWhenNonLocal() throws Exception {
checkDefaultType("Test.C");
}
private void checkDefaultType(final String expectedType) throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
new MockIntroduceConstantHandler(null){
@Override
protected Settings showRefactoringDialog(Project project,
Editor editor,
PsiClass parentClass,
PsiExpression expr,
PsiType type,
PsiExpression[] occurences,
PsiElement anchorElement,
PsiElement anchorElementIfAll) {
final TypeSelectorManagerImpl selectorManager =
new TypeSelectorManagerImpl(project, type, PsiTreeUtil.getParentOfType(anchorElement, PsiMethod.class), expr, occurences);
final PsiType psiType = selectorManager.getDefaultType();
Assert.assertEquals(psiType.getCanonicalText(), expectedType);
return new Settings("xxx", true, true, true,
InitializationPlace.IN_FIELD_DECLARATION, getVisibility(), null, psiType, false,
parentClass, false, false);
}
}.invoke(getProject(), getEditor(), getFile(), null);
}
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}