[Frontend] Make DiagnosticSuppressor a project-level extension

Originally it was an application-level component, which caused non-trivial
  logic and cognitive load to carefully handle those extensions to avoid
  memory leaks.

6740a596 introduced a way to easily register `DiagnosticSuppressor` to
  project, and this commit continues this work, making it a proper
  project-level extension

A lot of changes caused by the fact, that this extension is needed to be
  obtained from `BindingContext` (see `BindingContextSuppressCache` and
  its usages), so almost all changes are introducing `Project` to
  `BindingContext`

^KT-66449 Fixed
This commit is contained in:
Dmitriy Novozhilov
2024-03-08 08:52:28 +02:00
committed by Space Team
parent a552238874
commit d352cc9d96
45 changed files with 165 additions and 127 deletions
@@ -133,7 +133,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
val separateModules = groupedByModule.size == 1 && groupedByModule.keys.single() == null
val result = analyzeModuleContents(
moduleContext, ktFiles, NoScopeRecordCliBindingTrace(),
moduleContext, ktFiles, NoScopeRecordCliBindingTrace(project),
languageVersionSettings, separateModules, loadJvmTarget(testFilesInModule)
)
if (oldModule != result.moduleDescriptor) {
@@ -304,7 +304,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
try {
GenerationState generationState = GenerationUtils.compileFiles(
myFiles.getPsiFiles(), myEnvironment, getClassBuilderFactory(),
new NoScopeRecordCliBindingTrace()
new NoScopeRecordCliBindingTrace(myEnvironment.getProject())
);
classFileFactory = generationState.getFactory();
@@ -244,7 +244,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
registerJavacIfNeeded(environment);
configureEnvironment(environment);
AnalysisResult result = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
environment.getProject(), environment.getSourceFiles(), new NoScopeRecordCliBindingTrace(),
environment.getProject(), environment.getSourceFiles(), new NoScopeRecordCliBindingTrace(environment.getProject()),
configuration, environment::createPackagePartProvider
);
@@ -153,7 +153,7 @@ public class ExpectedResolveDataUtil {
LanguageVersionSettings languageVersionSettings = CommonConfigurationKeysKt.getLanguageVersionSettings(environment.getConfiguration());
ExpressionTypingContext context = ExpressionTypingContext.newContext(
new BindingTraceContext(), lexicalScope,
new BindingTraceContext(project), lexicalScope,
DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE, languageVersionSettings, container.getDataFlowValueFactory());
KtExpression callElement = new KtPsiFactory(project).createExpression(name);
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.test;
import com.google.common.collect.ImmutableMap;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -67,9 +68,21 @@ public class DummyTraces {
public void addOwnDataTo(@NotNull BindingTrace trace, boolean commitDiagnostics) {
// do nothing
}
@Nullable
@Override
public Project getProject() {
return null;
}
};
}
@Nullable
@Override
public Project getProject() {
return null;
}
@Override
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
}
@@ -121,6 +134,12 @@ public class DummyTraces {
@Override
public BindingContext getBindingContext() {
return new BindingContext() {
@Nullable
@Override
public Project getProject() {
return null;
}
@NotNull
@Override
public Diagnostics getDiagnostics() {
@@ -158,6 +177,12 @@ public class DummyTraces {
};
}
@Nullable
@Override
public Project getProject() {
return null;
}
@Override
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
}
@@ -41,7 +41,7 @@ fun createContainerForTests(project: Project, module: ModuleDescriptor): Contain
ModuleContext(module, project, "container for tests"),
JvmPlatforms.defaultJvmPlatform,
JvmPlatformAnalyzerServices,
BindingTraceContext(),
BindingTraceContext(project),
LanguageVersionSettingsImpl.DEFAULT,
optimizingOptions = null,
absentDescriptorHandlerClass = BasicAbsentDescriptorHandler::class.java