use of com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix in project intellij-community by JetBrains.
the class ImportHelperTest method testAutoImportCaretLocation.
public void testAutoImportCaretLocation() throws Throwable {
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
try {
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
configureByText(StdFileTypes.JAVA, "class X { ArrayList<caret> c; }");
((UndoManagerImpl) UndoManager.getInstance(getProject())).flushCurrentCommandMerger();
((UndoManagerImpl) UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(getFile().getVirtualFile());
type(" ");
backspace();
assertOneElement(highlightErrors());
int offset = myEditor.getCaretModel().getOffset();
PsiReference ref = myFile.findReferenceAt(offset - 1);
assertTrue(ref instanceof PsiJavaCodeReferenceElement);
ImportClassFixBase.Result result = new ImportClassFix((PsiJavaCodeReferenceElement) ref).doFix(getEditor(), true, false);
assertEquals(ImportClassFixBase.Result.POPUP_NOT_SHOWN, result);
UIUtil.dispatchAllInvocationEvents();
myEditor.getCaretModel().moveToOffset(offset - 1);
result = new ImportClassFix((PsiJavaCodeReferenceElement) ref).doFix(getEditor(), true, false);
assertEquals(ImportClassFixBase.Result.CLASS_AUTO_IMPORTED, result);
UIUtil.dispatchAllInvocationEvents();
assertEmpty(highlightErrors());
} finally {
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
}
}
use of com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix in project intellij-community by JetBrains.
the class ImportHelperTest method testAutoImportIgnoresUnresolvedImportReferences.
public void testAutoImportIgnoresUnresolvedImportReferences() throws Throwable {
@NonNls String text = "package x; import xxx.yyy.ArrayList; class S {{ ArrayList<caret> r; }}";
configureByText(StdFileTypes.JAVA, text);
PsiJavaFile javaFile = (PsiJavaFile) getFile();
PsiReference ref = javaFile.findReferenceAt(getEditor().getCaretModel().getOffset() - 1);
ImportClassFix fix = new ImportClassFix((PsiJavaCodeReferenceElement) ref);
assertFalse(fix.isAvailable(getProject(), getEditor(), getFile()));
}
Aggregations