@Nullable private Sdk getSdk() { if (myModule == null) { return ProjectRootManager.getInstance(myProject).getProjectSdk(); } final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule); return rootManager.getSdk(); }
@TestOnly public static void setTestVersion( @NotNull final JavaSdkVersion testVersion, @NotNull Module module, @NotNull Disposable parentDisposable) { ModuleRootManager rootManager = ModuleRootManager.getInstance(module); final Sdk sdk = rootManager.getSdk(); final String oldVersionString = sdk.getVersionString(); ((ProjectJdkImpl) sdk).setVersionString(testVersion.getDescription()); assert JavaSdk.getInstance().getVersion(sdk) == testVersion; Disposer.register( parentDisposable, new Disposable() { @Override public void dispose() { ((ProjectJdkImpl) sdk).setVersionString(oldVersionString); } }); }