SSR: inspection performance test

GitOrigin-RevId: e5077c6c483d93c710646083cf2d54551623e946
This commit is contained in:
Bas Leijdekkers
2021-08-09 12:06:10 +02:00
committed by intellij-monorepo-bot
parent 94f955fb01
commit ad44d12a73

View File

@@ -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