Search in sources :

Example 6 with ImportClassFix

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;
    }
}
Also used : UndoManagerImpl(com.intellij.openapi.command.impl.UndoManagerImpl) ImportClassFixBase(com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase) ImportClassFix(com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix)

Example 7 with ImportClassFix

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()));
}
Also used : NonNls(org.jetbrains.annotations.NonNls) ImportClassFix(com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix)

Aggregations

ImportClassFix (com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFix)7 ImportClassFixBase (com.intellij.codeInsight.daemon.impl.quickfix.ImportClassFixBase)3 NonNls (org.jetbrains.annotations.NonNls)3 UndoManagerImpl (com.intellij.openapi.command.impl.UndoManagerImpl)2 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 Document (com.intellij.openapi.editor.Document)1