Search in sources :

Example 6 with ThrowableRunnable

use of com.intellij.util.ThrowableRunnable in project intellij-plugins by JetBrains.

the class ActionScriptStubsTest method doTest.

private void doTest(@Nullable final ThrowableRunnable<Exception> runnable, String... files) throws Exception {
    Runnable r = runnable != null ? () -> {
        try {
            runnable.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } : null;
    doTestFor(true, r, files);
    // the first one was parsed during highlighting
    assertNotParsed(myPsiFiles.subList(1, myPsiFiles.size()));
    // we need to go though files open in editors
    assertNotParsed(ContainerUtil.mapNotNull(FileEditorManager.getInstance(myProject).getOpenFiles(), virtualFile -> {
        if (Comparing.equal(virtualFile, myFile.getVirtualFile())) {
            return null;
        }
        Document document = ((TextEditor) FileEditorManager.getInstance(myProject).getSelectedEditor(virtualFile)).getEditor().getDocument();
        return PsiDocumentManager.getInstance(myProject).getPsiFile(document);
    }));
}
Also used : VfsRootAccess(com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) VfsUtilCore.urlToPath(com.intellij.openapi.vfs.VfsUtilCore.urlToPath) JSTestOption(com.intellij.lang.javascript.JSTestOption) FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FlexStylesIndexableSetContributor(com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor) Comparing(com.intellij.openapi.util.Comparing) PsiFile(com.intellij.psi.PsiFile) ModuleType(com.intellij.openapi.module.ModuleType) ActionScriptDaemonAnalyzerTestCase(com.intellij.flex.util.ActionScriptDaemonAnalyzerTestCase) FlexTestUtils(com.intellij.flex.util.FlexTestUtils) LightQuickFixTestCase(com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase) TextEditor(com.intellij.openapi.fileEditor.TextEditor) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) ThrowableRunnable(com.intellij.util.ThrowableRunnable) PlatformTestUtil(com.intellij.testFramework.PlatformTestUtil) Collection(java.util.Collection) IOException(java.io.IOException) File(java.io.File) CommandProcessor(com.intellij.openapi.command.CommandProcessor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) VfsUtilCore.convertFromUrl(com.intellij.openapi.vfs.VfsUtilCore.convertFromUrl) JSTestOptions(com.intellij.lang.javascript.JSTestOptions) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) NotNull(org.jetbrains.annotations.NotNull) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ThrowableRunnable(com.intellij.util.ThrowableRunnable) Document(com.intellij.openapi.editor.Document) IOException(java.io.IOException)

Example 7 with ThrowableRunnable

use of com.intellij.util.ThrowableRunnable in project intellij-plugins by JetBrains.

the class FlexScopeTest method testTransitiveDependency.

public void testTransitiveDependency() throws Exception {
    final Module module2 = FlexTestUtils.createModule(myProject, "module2", getVirtualFile(getBasePath() + "m2"));
    final Module module3 = FlexTestUtils.createModule(myProject, "module3", getVirtualFile(getBasePath() + "m3"));
    FlexTestUtils.modifyConfigs(myProject, editor -> {
        final ModifiableFlexBuildConfiguration bc1 = editor.getConfigurations(myModule)[0];
        final ModifiableFlexBuildConfiguration bc2 = editor.getConfigurations(module2)[0];
        bc2.setOutputType(OutputType.Library);
        final ModifiableFlexBuildConfiguration bc3 = editor.getConfigurations(module3)[0];
        bc3.setOutputType(OutputType.Library);
        final ModifiableFlexBuildConfiguration bc3a = editor.createConfiguration(module3);
        bc3a.setOutputType(OutputType.Library);
        bc3a.setName("bc3a");
        bc1.getDependencies().getModifiableEntries().add(editor.createBcEntry(bc1.getDependencies(), bc2, null));
        bc2.getDependencies().getModifiableEntries().add(editor.createBcEntry(bc2.getDependencies(), bc3, null));
        bc2.getDependencies().getModifiableEntries().add(editor.createBcEntry(bc2.getDependencies(), bc3a, null));
    });
    FlexTestUtils.addFlexLibrary(false, module2, "Flex Lib", true, FlexTestUtils.getTestDataPath("flexlib/"), "flexlib.swc", null, null);
    doHighlightingTest("_1");
    class Test implements ThrowableRunnable<Exception> {

        private final LinkageType myLinkageType1;

        private final LinkageType myLinkageType2;

        private final String mySuffix;

        Test(LinkageType linkageType1, LinkageType linkageType2, String suffix) {
            myLinkageType1 = linkageType1;
            myLinkageType2 = linkageType2;
            mySuffix = suffix;
        }

        public void run() throws Exception {
            FlexTestUtils.modifyConfigs(myProject, editor -> {
                final ModifiableFlexBuildConfiguration bc = editor.getConfigurations(module2)[0];
                final ModifiableDependencyEntry e1 = bc.getDependencies().getModifiableEntries().get(0);
                e1.getDependencyType().setLinkageType(myLinkageType1);
                final ModifiableDependencyEntry e2 = bc.getDependencies().getModifiableEntries().get(1);
                e2.getDependencyType().setLinkageType(myLinkageType2);
            });
            doHighlightingTest(mySuffix);
        }
    }
    new Test(LinkageType.Default, LinkageType.Default, "_1").run();
    new Test(LinkageType.External, LinkageType.Default, "_1").run();
    new Test(LinkageType.Include, LinkageType.Default, "_2").run();
    new Test(LinkageType.LoadInRuntime, LinkageType.Default, "_1").run();
    new Test(LinkageType.Merged, LinkageType.Default, "_1").run();
    new Test(LinkageType.RSL, LinkageType.Default, "_1").run();
    new Test(LinkageType.RSL, LinkageType.Include, "_2").run();
    new Test(LinkageType.Include, LinkageType.Include, "_2").run();
    FlexTestUtils.modifyConfigs(myProject, editor -> {
        final ModifiableFlexBuildConfiguration bc2 = editor.getConfigurations(module2)[0];
        final ModifiableDependencyEntry entry = bc2.getDependencies().getModifiableEntries().get(2);
        assert entry instanceof ModifiableModuleLibraryEntry;
        entry.getDependencyType().setLinkageType(LinkageType.Include);
    });
    new Test(LinkageType.Include, LinkageType.Include, "_3").run();
}
Also used : ThrowableRunnable(com.intellij.util.ThrowableRunnable) FlexNavigationTest(com.intellij.flex.codeInsight.FlexNavigationTest) Module(com.intellij.openapi.module.Module) LinkageType(com.intellij.flex.model.bc.LinkageType)

Example 8 with ThrowableRunnable

use of com.intellij.util.ThrowableRunnable in project intellij-community by JetBrains.

the class VfsUtilPerformanceTest method testGetParentPerformance.

@Test
public void testGetParentPerformance() throws IOException {
    File tempDir = myTempDir.newFolder();
    VirtualFile vDir = LocalFileSystem.getInstance().findFileByIoFile(tempDir);
    assertNotNull(vDir);
    assertTrue(vDir.isDirectory());
    int depth = 10;
    new WriteCommandAction.Simple(null) {

        @Override
        protected void run() throws Throwable {
            VirtualFile dir = vDir;
            for (int i = 0; i < depth; i++) {
                dir = dir.createChildDirectory(this, "foo");
            }
            VirtualFile leafDir = dir;
            ThrowableRunnable checkPerformance = new ThrowableRunnable() {

                private VirtualFile findRoot(VirtualFile file) {
                    while (true) {
                        VirtualFile parent = file.getParent();
                        if (parent == null) {
                            return file;
                        }
                        file = parent;
                    }
                }

                @Override
                public void run() throws Throwable {
                    for (int i = 0; i < 5000000; i++) {
                        checkRootsEqual();
                    }
                }

                private void checkRootsEqual() {
                    assertEquals(findRoot(vDir), findRoot(leafDir));
                }
            };
            int time = 1200;
            PlatformTestUtil.startPerformanceTest("getParent is slow before movement", time, checkPerformance).useLegacyScaling().assertTiming();
            VirtualFile dir1 = vDir.createChildDirectory(this, "dir1");
            VirtualFile dir2 = vDir.createChildDirectory(this, "dir2");
            for (int i = 0; i < 13; i++) {
                /*13 is max length with THashMap capacity of 17, we get plenty collisions then*/
                dir1.createChildData(this, "a" + i + ".txt").move(this, dir2);
            }
            PlatformTestUtil.startPerformanceTest("getParent is slow after movement", time, checkPerformance).useLegacyScaling().assertTiming();
        }
    }.execute();
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) ThrowableRunnable(com.intellij.util.ThrowableRunnable) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) File(java.io.File) Test(org.junit.Test)

Example 9 with ThrowableRunnable

use of com.intellij.util.ThrowableRunnable in project intellij-community by JetBrains.

the class VcsSynchronousProgressWrapper method wrap.

public static boolean wrap(final ThrowableRunnable<VcsException> runnable, final Project project, final String title) {
    final VcsException[] exc = new VcsException[1];
    final Runnable process = new Runnable() {

        @Override
        public void run() {
            try {
                runnable.run();
            } catch (VcsException e) {
                exc[0] = e;
            }
        }
    };
    final boolean notCanceled;
    if (ApplicationManager.getApplication().isDispatchThread()) {
        notCanceled = ProgressManager.getInstance().runProcessWithProgressSynchronously(process, title, true, project);
    } else {
        process.run();
        notCanceled = true;
    }
    if (exc[0] != null) {
        AbstractVcsHelper.getInstance(project).showError(exc[0], title);
        return false;
    }
    return notCanceled;
}
Also used : VcsException(com.intellij.openapi.vcs.VcsException) ThrowableRunnable(com.intellij.util.ThrowableRunnable)

Aggregations

ThrowableRunnable (com.intellij.util.ThrowableRunnable)9 File (java.io.File)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 LightQuickFixTestCase (com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementPresentation (com.intellij.codeInsight.lookup.LookupElementPresentation)1 CompilerTask (com.intellij.compiler.progress.CompilerTask)1 FlexNavigationTest (com.intellij.flex.codeInsight.FlexNavigationTest)1 LinkageType (com.intellij.flex.model.bc.LinkageType)1 ActionScriptDaemonAnalyzerTestCase (com.intellij.flex.util.ActionScriptDaemonAnalyzerTestCase)1 FlexTestUtils (com.intellij.flex.util.FlexTestUtils)1 FlexStylesIndexableSetContributor (com.intellij.javascript.flex.css.FlexStylesIndexableSetContributor)1 JSTestOption (com.intellij.lang.javascript.JSTestOption)1 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)1 FlexModuleType (com.intellij.lang.javascript.flex.FlexModuleType)1 FlexBuildConfigurationManager (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager)1 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)1 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1