Search in sources :

Example 1 with ThrowableRunnable

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

the class DomPerformanceTest method testVisitorPerformance.

public void testVisitorPerformance() throws Throwable {
    final MyElement element = createElement("<root xmlns=\"adsf\" targetNamespace=\"adsf\"/>", MyElement.class);
    MetaRegistry.bindDataToElement(DomUtil.getFile(element).getDocument(), new XmlNSDescriptorImpl());
    final MyElement child = element.addChildElement();
    child.getAttr().setValue("239");
    child.getChild239().getAttr().setValue("42");
    child.getChild().getAttr().setValue("42xx");
    child.getChild2().getAttr().setValue("42yy");
    child.addChildElement().getChild().addFooChild().getAttr().setValue("xxx");
    child.addChildElement().addFooChild().getAttr().setValue("yyy");
    child.addChildElement().addFooChild().addBarChild().addBarChild().addChildElement().getChild().getAttr().setValue("xxx");
    child.addChildElement().addBarComposite().setValue("ssss");
    child.addBarChild().getChild2().getAttr().setValue("234178956023");
    PlatformTestUtil.startPerformanceTest(getTestName(false), 80000, () -> ApplicationManager.getApplication().runWriteAction(() -> {
        for (int i = 0; i < 239; i++) {
            element.addChildElement().copyFrom(child);
        }
    })).cpuBound().attempts(1).useLegacyScaling().assertTiming();
    final MyElement newElement = createElement(DomUtil.getFile(element).getText(), MyElement.class);
    PlatformTestUtil.startPerformanceTest(getTestName(false), 300, new ThrowableRunnable() {

        @Override
        public void run() throws Exception {
            newElement.acceptChildren(new DomElementVisitor() {

                @Override
                public void visitDomElement(DomElement element) {
                    element.acceptChildren(this);
                }
            });
        }
    }).cpuBound().useLegacyScaling().assertTiming();
}
Also used : ThrowableRunnable(com.intellij.util.ThrowableRunnable) XmlNSDescriptorImpl(com.intellij.xml.impl.dtd.XmlNSDescriptorImpl)

Example 2 with ThrowableRunnable

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

the class CompileDriver method startup.

private void startup(final CompileScope scope, final boolean isRebuild, final boolean forceCompile, final CompileStatusNotification callback, final CompilerMessage message) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    final String contentName = CompilerBundle.message(forceCompile ? "compiler.content.name.compile" : "compiler.content.name.make");
    final boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode();
    final CompilerTask compileTask = new CompilerTask(myProject, contentName, isUnitTestMode, true, true, isCompilationStartedAutomatically(scope));
    StatusBar.Info.set("", myProject, "Compiler");
    // ensure the project model seen by build process is up-to-date
    myProject.save();
    if (!isUnitTestMode) {
        ApplicationManager.getApplication().saveSettings();
    }
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
    final CompileContextImpl compileContext = new CompileContextImpl(myProject, compileTask, scope, !isRebuild && !forceCompile, isRebuild);
    final Runnable compileWork = () -> {
        final ProgressIndicator indicator = compileContext.getProgressIndicator();
        if (indicator.isCanceled() || myProject.isDisposed()) {
            if (callback != null) {
                callback.finished(true, 0, 0, compileContext);
            }
            return;
        }
        CompilerCacheManager compilerCacheManager = CompilerCacheManager.getInstance(myProject);
        try {
            LOG.info("COMPILATION STARTED (BUILD PROCESS)");
            if (message != null) {
                compileContext.addMessage(message);
            }
            if (isRebuild) {
                CompilerUtil.runInContext(compileContext, "Clearing build system data...", (ThrowableRunnable<Throwable>) () -> compilerCacheManager.clearCaches(compileContext));
            }
            final boolean beforeTasksOk = executeCompileTasks(compileContext, true);
            final int errorCount = compileContext.getMessageCount(CompilerMessageCategory.ERROR);
            if (!beforeTasksOk || errorCount > 0) {
                COMPILE_SERVER_BUILD_STATUS.set(compileContext, errorCount > 0 ? ExitStatus.ERRORS : ExitStatus.CANCELLED);
                return;
            }
            final TaskFuture future = compileInExternalProcess(compileContext, false);
            if (future != null) {
                while (!future.waitFor(200L, TimeUnit.MILLISECONDS)) {
                    if (indicator.isCanceled()) {
                        future.cancel(false);
                    }
                }
                if (!executeCompileTasks(compileContext, false)) {
                    COMPILE_SERVER_BUILD_STATUS.set(compileContext, ExitStatus.CANCELLED);
                }
                if (compileContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) {
                    COMPILE_SERVER_BUILD_STATUS.set(compileContext, ExitStatus.ERRORS);
                }
            }
        } catch (ProcessCanceledException ignored) {
            compileContext.putUserDataIfAbsent(COMPILE_SERVER_BUILD_STATUS, ExitStatus.CANCELLED);
        } catch (Throwable e) {
            // todo
            LOG.error(e);
        } finally {
            compilerCacheManager.flushCaches();
            final long duration = notifyCompilationCompleted(compileContext, callback, COMPILE_SERVER_BUILD_STATUS.get(compileContext));
            CompilerUtil.logDuration("\tCOMPILATION FINISHED (BUILD PROCESS); Errors: " + compileContext.getMessageCount(CompilerMessageCategory.ERROR) + "; warnings: " + compileContext.getMessageCount(CompilerMessageCategory.WARNING), duration);
        }
    };
    compileTask.start(compileWork, () -> {
        if (isRebuild) {
            final int rv = Messages.showOkCancelDialog(myProject, "You are about to rebuild the whole project.\nRun 'Build Project' instead?", "Confirm Project Rebuild", "Build", "Rebuild", Messages.getQuestionIcon());
            if (rv == Messages.OK) /*yes, please, do run make*/
            {
                startup(scope, false, false, callback, null);
                return;
            }
        }
        startup(scope, isRebuild, forceCompile, callback, message);
    });
}
Also used : CompilerTask(com.intellij.compiler.progress.CompilerTask) ThrowableRunnable(com.intellij.util.ThrowableRunnable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ThrowableRunnable(com.intellij.util.ThrowableRunnable) TaskFuture(org.jetbrains.jps.api.TaskFuture) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 3 with ThrowableRunnable

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

the class FindManagerTest method testLocalScopeSearchPerformance.

public void testLocalScopeSearchPerformance() throws Exception {
    final int fileCount = 3000;
    final int lineCount = 500;
    TempDirTestFixture fixture = new LightTempDirTestFixtureImpl();
    fixture.setUp();
    try {
        String sampleText = StringUtil.repeat("zoo TargetWord foo bar goo\n", lineCount);
        for (int i = 0; i < fileCount; i++) {
            fixture.createFile("a" + i + ".txt", sampleText);
        }
        PsiTestUtil.addSourceContentToRoots(myModule, fixture.getFile(""));
        VirtualFile file = fixture.createFile("target.txt", sampleText);
        PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
        assertNotNull(psiFile);
        final FindModel findModel = new FindModel();
        findModel.setStringToFind("TargetWord");
        findModel.setWholeWordsOnly(true);
        findModel.setFromCursor(false);
        findModel.setGlobal(true);
        findModel.setMultipleFiles(true);
        findModel.setCustomScope(true);
        ThrowableRunnable test = () -> assertSize(lineCount, findUsages(findModel));
        findModel.setCustomScope(GlobalSearchScope.fileScope(psiFile));
        PlatformTestUtil.startPerformanceTest("slow", 400, test).attempts(2).cpuBound().usesAllCPUCores().useLegacyScaling().assertTiming();
        findModel.setCustomScope(new LocalSearchScope(psiFile));
        PlatformTestUtil.startPerformanceTest("slow", 400, test).attempts(2).cpuBound().usesAllCPUCores().useLegacyScaling().assertTiming();
    } finally {
        fixture.tearDown();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) TempDirTestFixture(com.intellij.testFramework.fixtures.TempDirTestFixture) ThrowableRunnable(com.intellij.util.ThrowableRunnable) LightTempDirTestFixtureImpl(com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl)

Example 4 with ThrowableRunnable

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

the class Test method testPerformance.

public void testPerformance() throws Exception {
    final String path = PathManagerEx.getTestDataPath() + "/psi/stub/StubPerformanceTest.java";
    String text = FileUtil.loadFile(new File(path));
    final PsiJavaFile file = (PsiJavaFile) createLightFile("test.java", text);
    PlatformTestUtil.startPerformanceTest("Source file size: " + text.length(), 2000, new ThrowableRunnable() {

        @Override
        public void run() throws Exception {
            NEW_BUILDER.buildStubTree(file);
        }
    }).cpuBound().assertTiming();
}
Also used : ThrowableRunnable(com.intellij.util.ThrowableRunnable) File(java.io.File)

Example 5 with ThrowableRunnable

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

the class ActionScriptCompletionTest method testTwoSdks.

public void testTwoSdks() throws Exception {
    final Sdk sdk45 = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.5"), null, true);
    final Sdk sdk46 = FlexTestUtils.createSdk(FlexTestUtils.getPathToCompleteFlexSdk("4.6"), null, false);
    FlexTestUtils.modifyConfigs(myProject, new Consumer<FlexProjectConfigurationEditor>() {

        public void consume(final FlexProjectConfigurationEditor editor) {
            ModifiableFlexBuildConfiguration bc1 = editor.getConfigurations(myModule)[0];
            bc1.setName("1");
            FlexTestUtils.setSdk(bc1, sdk45);
            ModifiableFlexBuildConfiguration bc2 = editor.createConfiguration(myModule);
            bc2.setName("2");
            FlexTestUtils.setSdk(bc2, sdk46);
        }
    });
    final FlexBuildConfigurationManager m = FlexBuildConfigurationManager.getInstance(myModule);
    class TestZZ implements ThrowableRunnable<Exception> {

        private final String myBcName;

        private final String myExpectedTypeText;

        TestZZ(final String bcName, final String expectedTypeText) {
            myBcName = bcName;
            myExpectedTypeText = expectedTypeText;
        }

        @Override
        public void run() throws Exception {
            m.setActiveBuildConfiguration(m.findConfigurationByName(myBcName));
            defaultTest();
            for (LookupElement item : myItems) {
                final LookupElementPresentation p = new LookupElementPresentation();
                item.renderElement(p);
                assertEquals(myExpectedTypeText, p.getTypeText());
            }
        }
    }
    new TestZZ("1", sdk45.getName()).run();
    new TestZZ("2", sdk46.getName()).run();
    new TestZZ("1", sdk45.getName()).run();
}
Also used : FlexProjectConfigurationEditor(com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor) FlexBuildConfigurationManager(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfigurationManager) ThrowableRunnable(com.intellij.util.ThrowableRunnable) LookupElementPresentation(com.intellij.codeInsight.lookup.LookupElementPresentation) Sdk(com.intellij.openapi.projectRoots.Sdk) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ModifiableFlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)

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