void () { enableInspectionTool(new RedundantCastInspection()); @Language("JAVA") String template = """ import java.util.function.Function; abstract class Snippet { abstract <V> V valueOf(V var2); abstract <V> V valueOf(java.util.List<? extends V> var2); static final class Builder { public Builder foo(Foo foo) { return this; } public Snippet build() { return null; } } public static final class Foo { } public static final Function<Snippet, Snippet> _snippet = snippet -> { Foo foo = new Foo(); return new Builder(). $chain$ .build(); }; }"""; int count = 70; String entries = "foo(snippet.valueOf(foo))\n" +//to trick injection StringUtil.repeat(".foo(snippet.valueOf(foo))\n", count); configureFromFileText("Test.java", template.replace("$chain$", entries)); PlatformTestUtil.startPerformanceTest(count + " chain in type cast", 3000, () -> doHighlighting()) .setup(() -> PsiManager.getInstance(getProject()).dropPsiCaches()) .usesAllCPUCores().assertTiming(); assertEmpty(highlightErrors()); }