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
This commit is contained in:
Leonid Shalupov
2019-08-02 21:02:32 +03:00
committed by intellij-monorepo-bot
parent ee62e1573f
commit 1b2711ebea
2 changed files with 18 additions and 2 deletions
@@ -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() {
@@ -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);