From ad44d12a73de467b78ae782e23fdd332466f27bf Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 9 Aug 2021 12:06:10 +0200 Subject: [PATCH] SSR: inspection performance test GitOrigin-RevId: e5077c6c483d93c710646083cf2d54551623e946 --- .../structuralsearch/SSRCodeInsightTest.java | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/platform/structuralsearch/testSource/com/intellij/structuralsearch/SSRCodeInsightTest.java b/platform/structuralsearch/testSource/com/intellij/structuralsearch/SSRCodeInsightTest.java index 962a8b19d401..8ada9c813af8 100644 --- a/platform/structuralsearch/testSource/com/intellij/structuralsearch/SSRCodeInsightTest.java +++ b/platform/structuralsearch/testSource/com/intellij/structuralsearch/SSRCodeInsightTest.java @@ -1,7 +1,18 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.structuralsearch; +import com.intellij.codeInspection.InspectionManager; +import com.intellij.codeInspection.LocalInspectionToolSession; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.codeInspection.ex.InspectionProfileImpl; +import com.intellij.codeInspection.ex.ToolsImpl; import com.intellij.ide.highlighter.JavaFileType; +import com.intellij.profile.codeInspection.InspectionProfileManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.PsiFile; +import com.intellij.psi.search.PsiElementProcessor; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.structuralsearch.inspection.SSBasedInspection; import com.intellij.structuralsearch.inspection.StructuralSearchProfileActionProvider; import com.intellij.structuralsearch.plugin.ui.SearchConfiguration; @@ -9,6 +20,9 @@ import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.UsefulTestCase; import com.intellij.testFramework.fixtures.*; import com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; public class SSRCodeInsightTest extends UsefulTestCase { protected CodeInsightTestFixture myFixture; @@ -75,6 +89,45 @@ public class SSRCodeInsightTest extends UsefulTestCase { doTest("f();", "method call"); } + public void testChainedMethodCallsPerformance() throws IOException { + final StringBuilder source = new StringBuilder("public class ChainedMethodCallsPerformance {\n" + + "\n" + + " void x() {\n" + + " new StringBuilder()\n"); + for (int i = 0; i < 400; i++) { + source.append(" .append(").append(i).append(")\n"); + } + source.append(" }\n" + + "}"); + myFixture.configureByText("ChainedMethodCallsPerformance.java", source.toString()); + + final SearchConfiguration configuration = new SearchConfiguration("Chained method call", "test"); + final MatchOptions options = configuration.getMatchOptions(); + options.setFileType(JavaFileType.INSTANCE); + options.fillSearchCriteria("'_x.'y('_z)"); + options.setRecursiveSearch(true); + + StructuralSearchProfileActionProvider.createNewInspection(configuration, myFixture.getProject()); + final InspectionProfileImpl profile = InspectionProfileManager.getInstance(myFixture.getProject()).getCurrentProfile(); + final ToolsImpl tools = profile.getToolsOrNull("SSBasedInspection", myFixture.getProject()); + final SSBasedInspection inspection = (SSBasedInspection)tools.getTool().getTool(); + final PsiFile file = myFixture.getFile(); + final InspectionManager inspectionManager = InspectionManager.getInstance(myFixture.getProject()); + final PsiElementVisitor visitor = inspection.buildVisitor(new ProblemsHolder(inspectionManager, file, true), true, + new LocalInspectionToolSession(file, 0, file.getTextLength())); + + PlatformTestUtil.startPerformanceTest("Chained method call inspection performance", 1500, + () -> { + PsiTreeUtil.processElements(file, new PsiElementProcessor<>() { + @Override + public boolean execute(@NotNull PsiElement element) { + element.accept(visitor); + return true; + } + }); + }).assertTiming(); + } + private void doTest(final String searchPattern, final String patternName) { final SearchConfiguration configuration = new SearchConfiguration(); //display name