Search in sources :

Example 1 with FileTypeManagerImpl

use of com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl in project intellij-community by JetBrains.

the class LightPlatformTestCase method doSetup.

public static void doSetup(@NotNull LightProjectDescriptor descriptor, @NotNull LocalInspectionTool[] localInspectionTools, @NotNull Disposable parentDisposable) throws Exception {
    assertNull("Previous test " + ourTestCase + " hasn't called tearDown(). Probably overridden without super call.", ourTestCase);
    IdeaLogger.ourErrorsOccurred = null;
    ApplicationManager.getApplication().assertIsDispatchThread();
    boolean reusedProject = true;
    if (ourProject == null || ourProjectDescriptor == null || !ourProjectDescriptor.equals(descriptor)) {
        initProject(descriptor);
        reusedProject = false;
    }
    ProjectManagerEx projectManagerEx = ProjectManagerEx.getInstanceEx();
    projectManagerEx.openTestProject(ourProject);
    if (reusedProject) {
        DumbService.getInstance(ourProject).queueTask(new UnindexedFilesUpdater(ourProject));
    }
    MessageBusConnection connection = ourProject.getMessageBus().connect(parentDisposable);
    connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {

        @Override
        public void moduleAdded(@NotNull Project project, @NotNull Module module) {
            fail("Adding modules is not permitted in LightIdeaTestCase.");
        }
    });
    clearUncommittedDocuments(getProject());
    InspectionsKt.configureInspections(localInspectionTools, getProject(), parentDisposable);
    assertFalse(getPsiManager().isDisposed());
    Boolean passed = null;
    try {
        passed = StartupManagerEx.getInstanceEx(getProject()).startupActivityPassed();
    } catch (Exception ignored) {
    }
    assertTrue("open: " + getProject().isOpen() + "; disposed:" + getProject().isDisposed() + "; startup passed:" + passed + "; all open projects: " + Arrays.asList(ProjectManager.getInstance().getOpenProjects()), getProject().isInitialized());
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(new CodeStyleSettings());
    final FileDocumentManager manager = FileDocumentManager.getInstance();
    if (manager instanceof FileDocumentManagerImpl) {
        Document[] unsavedDocuments = manager.getUnsavedDocuments();
        manager.saveAllDocuments();
        ApplicationManager.getApplication().runWriteAction(((FileDocumentManagerImpl) manager)::dropAllUnsavedDocuments);
        assertEmpty("There are unsaved documents", Arrays.asList(unsavedDocuments));
    }
    // startup activities
    UIUtil.dispatchAllInvocationEvents();
    ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ModuleListener(com.intellij.openapi.project.ModuleListener) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) FileDocumentManagerImpl(com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl) Document(com.intellij.openapi.editor.Document) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) Module(com.intellij.openapi.module.Module) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) UnindexedFilesUpdater(com.intellij.util.indexing.UnindexedFilesUpdater)

Example 2 with FileTypeManagerImpl

use of com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl in project intellij-community by JetBrains.

the class PlatformTestCase method setUpProject.

protected void setUpProject() throws Exception {
    myProjectManager = ProjectManagerEx.getInstanceEx();
    assertNotNull("Cannot instantiate ProjectManager component", myProjectManager);
    File projectFile = getIprFile();
    myProject = doCreateProject(projectFile);
    myProjectManager.openTestProject(myProject);
    LocalFileSystem.getInstance().refreshIoFiles(myFilesToDelete);
    setUpModule();
    setUpJdk();
    LightPlatformTestCase.clearUncommittedDocuments(getProject());
    runStartupActivities();
    ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl)

Example 3 with FileTypeManagerImpl

use of com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl in project intellij-community by JetBrains.

the class DaemonCodeAnalyzerImpl method runPasses.

@NotNull
@TestOnly
List<HighlightInfo> runPasses(@NotNull PsiFile file, @NotNull Document document, @NotNull List<TextEditor> textEditors, @NotNull int[] toIgnore, boolean canChangeDocument, @Nullable final Runnable callbackWhileWaiting) throws ProcessCanceledException {
    assert myInitialized;
    assert !myDisposed;
    ApplicationEx application = ApplicationManagerEx.getApplicationEx();
    application.assertIsDispatchThread();
    if (application.isWriteAccessAllowed()) {
        throw new AssertionError("Must not start highlighting from within write action, or deadlock is imminent");
    }
    DaemonProgressIndicator.setDebug(!ApplicationInfoImpl.isInStressTest());
    ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
    // pump first so that queued event do not interfere
    UIUtil.dispatchAllInvocationEvents();
    // refresh will fire write actions interfering with highlighting
    while (RefreshQueueImpl.isRefreshInProgress() || HeavyProcessLatch.INSTANCE.isRunning()) {
        UIUtil.dispatchAllInvocationEvents();
    }
    long dstart = System.currentTimeMillis();
    while (mustWaitForSmartMode && DumbService.getInstance(myProject).isDumb()) {
        if (System.currentTimeMillis() > dstart + 100000) {
            throw new IllegalStateException("Timeout waiting for smart mode. If you absolutely want to be dumb, please use DaemonCodeAnalyzerImpl.mustWaitForSmartMode(false).");
        }
        UIUtil.dispatchAllInvocationEvents();
    }
    UIUtil.dispatchAllInvocationEvents();
    Project project = file.getProject();
    FileStatusMap fileStatusMap = getFileStatusMap();
    fileStatusMap.allowDirt(canChangeDocument);
    Map<FileEditor, HighlightingPass[]> map = new HashMap<>();
    for (TextEditor textEditor : textEditors) {
        if (textEditor instanceof TextEditorImpl) {
            try {
                ((TextEditorImpl) textEditor).waitForLoaded(10, TimeUnit.SECONDS);
            } catch (TimeoutException e) {
                throw new RuntimeException(textEditor + " has not completed loading in 10 seconds");
            }
        }
        TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter) textEditor.getBackgroundHighlighter();
        if (highlighter == null) {
            Editor editor = textEditor.getEditor();
            throw new RuntimeException("Null highlighter from " + textEditor + "; loaded: " + AsyncEditorLoader.isEditorLoaded(editor));
        }
        final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
        HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]);
        assert array.length != 0 : "Highlighting is disabled for the file " + file;
        map.put(textEditor, array);
    }
    for (int ignoreId : toIgnore) {
        fileStatusMap.markFileUpToDate(document, ignoreId);
    }
    myUpdateRunnableFuture.cancel(false);
    final DaemonProgressIndicator progress = createUpdateProgress();
    myPassExecutorService.submitPasses(map, progress);
    try {
        long start = System.currentTimeMillis();
        while (progress.isRunning() && System.currentTimeMillis() < start + 5 * 60 * 1000) {
            wrap(() -> {
                progress.checkCanceled();
                if (callbackWhileWaiting != null) {
                    callbackWhileWaiting.run();
                }
                waitInOtherThread(50, canChangeDocument);
                UIUtil.dispatchAllInvocationEvents();
                Throwable savedException = PassExecutorService.getSavedException(progress);
                if (savedException != null)
                    throw savedException;
            });
        }
        if (progress.isRunning() && !progress.isCanceled()) {
            throw new RuntimeException("Highlighting still running after " + (System.currentTimeMillis() - start) / 1000 + " seconds.\n" + ThreadDumper.dumpThreadsToString());
        }
        final HighlightingSessionImpl session = (HighlightingSessionImpl) HighlightingSessionImpl.getOrCreateHighlightingSession(file, textEditors.get(0).getEditor(), progress, null);
        wrap(() -> {
            if (!waitInOtherThread(60000, canChangeDocument)) {
                throw new TimeoutException("Unable to complete in 60s");
            }
            session.waitForHighlightInfosApplied();
        });
        UIUtil.dispatchAllInvocationEvents();
        UIUtil.dispatchAllInvocationEvents();
        assert progress.isCanceled() && progress.isDisposed();
        return getHighlights(document, null, project);
    } finally {
        DaemonProgressIndicator.setDebug(false);
        fileStatusMap.allowDirt(true);
        waitForTermination();
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) THashMap(gnu.trove.THashMap) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl) HighlightingPass(com.intellij.codeHighlighting.HighlightingPass) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) Project(com.intellij.openapi.project.Project) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) TextEditorImpl(com.intellij.openapi.fileEditor.impl.text.TextEditorImpl) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with FileTypeManagerImpl

use of com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl in project intellij-community by JetBrains.

the class HeavyIdeaTestFixtureImpl method setUpProject.

private void setUpProject() throws IOException {
    File tempDirectory = FileUtil.createTempDirectory(myName, "");
    PlatformTestCase.synchronizeTempDirVfs(ObjectUtils.assertNotNull(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDirectory)));
    myFilesToDelete.add(tempDirectory);
    String projectPath = FileUtil.toSystemIndependentName(tempDirectory.getPath()) + "/" + myName + ProjectFileType.DOT_DEFAULT_EXTENSION;
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    new Throwable(projectPath).printStackTrace(new PrintStream(buffer));
    myProject = PlatformTestCase.createProject(projectPath, buffer.toString());
    EdtTestUtil.runInEdtAndWait(() -> {
        ProjectManagerEx.getInstanceEx().openTestProject(myProject);
        for (ModuleFixtureBuilder moduleFixtureBuilder : myModuleFixtureBuilders) {
            moduleFixtureBuilder.getFixture().setUp();
        }
        LightPlatformTestCase.clearUncommittedDocuments(myProject);
        ((FileTypeManagerImpl) FileTypeManager.getInstance()).drainReDetectQueue();
    });
}
Also used : PrintStream(java.io.PrintStream) ModuleFixtureBuilder(com.intellij.testFramework.builders.ModuleFixtureBuilder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileTypeManagerImpl(com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl)

Aggregations

FileTypeManagerImpl (com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl)4 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 FileDocumentManagerImpl (com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl)1 TextEditorImpl (com.intellij.openapi.fileEditor.impl.text.TextEditorImpl)1 Module (com.intellij.openapi.module.Module)1 ModuleListener (com.intellij.openapi.project.ModuleListener)1 ProjectManagerEx (com.intellij.openapi.project.ex.ProjectManagerEx)1 PsiFile (com.intellij.psi.PsiFile)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1 ModuleFixtureBuilder (com.intellij.testFramework.builders.ModuleFixtureBuilder)1