From 1b2711ebea5b0765ce93d4e72df74f190198be6e Mon Sep 17 00:00:00 2001 From: Leonid Shalupov Date: Fri, 26 Jul 2019 20:20:07 +0200 Subject: [PATCH] PlatformTestCase: register test project JDK New project model implementation requires all entities to be registered in project model, not just some Java mocks GitOrigin-RevId: bd878512668757ab2a560cf32c8a55dd1f32a120 --- .../CompilerReferencesFindUsagesTest.java | 4 ++-- .../testFramework/HeavyPlatformTestCase.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesFindUsagesTest.java b/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesFindUsagesTest.java index c8d570cfad0b..402114dc3c2c 100644 --- a/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesFindUsagesTest.java +++ b/java/java-tests/testSrc/com/intellij/java/compiler/CompilerReferencesFindUsagesTest.java @@ -10,6 +10,7 @@ import com.intellij.lang.injection.InjectedLanguageManager; import com.intellij.openapi.compiler.options.ExcludeEntryDescription; import com.intellij.openapi.compiler.options.ExcludesConfiguration; import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.java.LanguageLevel; @@ -21,7 +22,6 @@ import com.intellij.psi.search.searches.MethodReferencesSearch; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.psi.util.PointersKt; import com.intellij.testFramework.CompilerTester; -import com.intellij.testFramework.IdeaTestUtil; import com.intellij.testFramework.SkipSlowTestLocally; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; @@ -67,7 +67,7 @@ public class CompilerReferencesFindUsagesTest extends DaemonAnalyzerTestCase { @Override protected Sdk getTestProjectJdk() { - return IdeaTestUtil.getMockJdk18(); + return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk(); } public void testMethodUsageOnGetter() { diff --git a/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java index 7ae504147d75..600e2e5817d8 100644 --- a/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/HeavyPlatformTestCase.java @@ -36,6 +36,7 @@ import com.intellij.openapi.project.ex.ProjectManagerEx; import com.intellij.openapi.project.impl.ProjectImpl; import com.intellij.openapi.project.impl.ProjectManagerImpl; import com.intellij.openapi.project.impl.TooManyProjectLeakedException; +import com.intellij.openapi.projectRoots.ProjectJdkTable; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.ModuleRootModificationUtil; import com.intellij.openapi.roots.ex.ProjectRootManagerEx; @@ -642,8 +643,23 @@ public abstract class HeavyPlatformTestCase extends UsefulTestCase implements Da resetClassFields(aClass.getSuperclass()); } + private void registerTestProjectJdk(Sdk jdk) { + ProjectJdkTable jdkTable = ProjectJdkTable.getInstance(); + + for (Sdk existingSdk : jdkTable.getAllJdks()) { + if (existingSdk == jdk) return; + } + + WriteAction.runAndWait(()-> jdkTable.addJdk(jdk, myProject)); + } + protected void setUpJdk() { final Sdk jdk = getTestProjectJdk(); + + if (jdk != null) { + registerTestProjectJdk(jdk); + } + Module[] modules = ModuleManager.getInstance(myProject).getModules(); for (Module module : modules) { ModuleRootModificationUtil.setModuleSdk(module, jdk);