mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-21 22:11:40 +07:00
Python cleanup: remove redundant methods from PythonSdkAdditionalData: one should use sdk modificator
GitOrigin-RevId: 7682d5287264fd5bf75807be6c61c4527788c1d9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b396cf5446
commit
b1a58215ae
@@ -2,7 +2,6 @@
|
||||
package com.jetbrains.python.sdk;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.projectRoots.SdkAdditionalData;
|
||||
import com.intellij.openapi.util.JDOMExternalizer;
|
||||
@@ -18,6 +17,7 @@ import com.jetbrains.python.sdk.flavors.PyFlavorAndData;
|
||||
import com.jetbrains.python.sdk.flavors.PyFlavorData;
|
||||
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -93,6 +93,7 @@ public class PythonSdkAdditionalData implements SdkAdditionalData {
|
||||
/**
|
||||
* Temporary hack to deal with leagcy conda. Use constructor instead
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final void changeFlavorAndData(@NotNull PyFlavorAndData<?, ?> flavorAndData) {
|
||||
this.myFlavorAndData = flavorAndData;
|
||||
}
|
||||
@@ -100,6 +101,7 @@ public class PythonSdkAdditionalData implements SdkAdditionalData {
|
||||
/**
|
||||
* Persistent UUID of SDK. Could be used to point to "this particular" SDK.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final @NotNull UUID getUUID() {
|
||||
return myUUID;
|
||||
}
|
||||
@@ -108,48 +110,40 @@ public class PythonSdkAdditionalData implements SdkAdditionalData {
|
||||
return new PythonSdkAdditionalData(this);
|
||||
}
|
||||
|
||||
public void setAddedPathsFromVirtualFiles(@NotNull Set<VirtualFile> addedPaths) {
|
||||
public final void setAddedPathsFromVirtualFiles(@NotNull Set<VirtualFile> addedPaths) {
|
||||
myAddedPaths.clear();
|
||||
for (VirtualFile file : addedPaths) {
|
||||
myAddedPaths.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void setExcludedPathsFromVirtualFiles(@NotNull Set<VirtualFile> addedPaths) {
|
||||
@ApiStatus.Internal
|
||||
public final void setExcludedPathsFromVirtualFiles(@NotNull Set<VirtualFile> addedPaths) {
|
||||
myExcludedPaths.clear();
|
||||
for (VirtualFile file : addedPaths) {
|
||||
myExcludedPaths.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPathsToTransferFromVirtualFiles(@NotNull Set<VirtualFile> addedPaths) {
|
||||
@ApiStatus.Internal
|
||||
public final void setPathsToTransferFromVirtualFiles(@NotNull Set<VirtualFile> addedPaths) {
|
||||
myPathsToTransfer.clear();
|
||||
for (VirtualFile file : addedPaths) {
|
||||
myPathsToTransfer.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAssociatedModulePath() {
|
||||
public final String getAssociatedModulePath() {
|
||||
return myAssociatedModulePath;
|
||||
}
|
||||
|
||||
public void resetAssociatedModulePath() {
|
||||
setAssociatedModulePath(null);
|
||||
}
|
||||
|
||||
public void setAssociatedModulePath(@Nullable String associatedModulePath) {
|
||||
myAssociatedModulePath = associatedModulePath;
|
||||
}
|
||||
|
||||
public void associateWithModule(@NotNull Module module) {
|
||||
final String path = BasePySdkExtKt.getBasePath(module);
|
||||
if (path != null) {
|
||||
associateWithModulePath(path);
|
||||
}
|
||||
}
|
||||
|
||||
public void associateWithModulePath(@NotNull String modulePath) {
|
||||
myAssociatedModulePath = FileUtil.toSystemIndependentName(modulePath);
|
||||
/**
|
||||
* Be sure to use {@link com.intellij.openapi.projectRoots.SdkModificator} to save changes
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final void setAssociatedModulePath(@Nullable String modulePath) {
|
||||
myAssociatedModulePath = modulePath == null ? null : FileUtil.toSystemIndependentName(modulePath);
|
||||
}
|
||||
|
||||
public void save(final @NotNull Element rootElement) {
|
||||
@@ -173,11 +167,11 @@ public class PythonSdkAdditionalData implements SdkAdditionalData {
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull PythonSdkFlavor<?> getFlavor() {
|
||||
public final @NotNull PythonSdkFlavor<?> getFlavor() {
|
||||
return myFlavorAndData.getFlavor();
|
||||
}
|
||||
|
||||
public @NotNull PyFlavorAndData<?, ?> getFlavorAndData() {
|
||||
public final @NotNull PyFlavorAndData<?, ?> getFlavorAndData() {
|
||||
return myFlavorAndData;
|
||||
}
|
||||
|
||||
@@ -192,12 +186,11 @@ public class PythonSdkAdditionalData implements SdkAdditionalData {
|
||||
collectPaths(JDOMExternalizer.loadStringsList(element, PATHS_REMOVED_BY_USER_ROOT, PATH_REMOVED_BY_USER), myExcludedPaths);
|
||||
collectPaths(JDOMExternalizer.loadStringsList(element, PATHS_TO_TRANSFER_ROOT, PATH_TO_TRANSFER), myPathsToTransfer);
|
||||
if (element != null) {
|
||||
setAssociatedModulePath(element.getAttributeValue(ASSOCIATED_PROJECT_PATH));
|
||||
myAssociatedModulePath = element.getAttributeValue(ASSOCIATED_PROJECT_PATH);
|
||||
var uuidStr = element.getAttributeValue(SDK_UUID_FIELD_NAME);
|
||||
if (uuidStr != null) {
|
||||
myUUID = UUID.fromString(uuidStr);
|
||||
}
|
||||
setAssociatedModulePath(element.getAttributeValue(ASSOCIATED_PROJECT_PATH));
|
||||
var flavorId = JDOMExternalizer.readString(element, FLAVOR_ID);
|
||||
if (flavorId != null) {
|
||||
var flavorOpt = PythonSdkFlavor.getApplicableFlavors(true).stream().filter(f -> f.getUniqueId().equals(flavorId)).findFirst();
|
||||
@@ -227,18 +220,18 @@ public class PythonSdkAdditionalData implements SdkAdditionalData {
|
||||
}
|
||||
|
||||
|
||||
public Set<VirtualFile> getAddedPathFiles() {
|
||||
public final Set<VirtualFile> getAddedPathFiles() {
|
||||
return getPathsAsVirtualFiles(myAddedPaths);
|
||||
}
|
||||
|
||||
public Set<VirtualFile> getExcludedPathFiles() {
|
||||
public final Set<VirtualFile> getExcludedPathFiles() {
|
||||
return getPathsAsVirtualFiles(myExcludedPaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.jetbrains.python.sdk.PyTransferredSdkRootsKt#getPathsToTransfer(Sdk)
|
||||
*/
|
||||
public @NotNull Set<VirtualFile> getPathsToTransfer() {
|
||||
public final @NotNull Set<VirtualFile> getPathsToTransfer() {
|
||||
return getPathsAsVirtualFiles(myPathsToTransfer);
|
||||
}
|
||||
|
||||
|
||||
@@ -190,7 +190,7 @@ suspend fun Sdk.setAssociationToModuleAsync(module: Module) {
|
||||
suspend fun Sdk.setAssociationToPath(path: String?) {
|
||||
val data = getOrCreateAdditionalData().also {
|
||||
when {
|
||||
path != null -> it.associateWithModulePath(path)
|
||||
path != null -> it.associatedModulePath = path
|
||||
else -> it.associatedModulePath = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.jetbrains.python.configuration
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
@@ -6,10 +6,14 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.SdkModificator
|
||||
import com.intellij.util.concurrency.ThreadingAssertions
|
||||
import com.jetbrains.python.sdk.PythonSdkAdditionalData
|
||||
import com.jetbrains.python.sdk.basePath
|
||||
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
internal fun SdkModificator.associateWithModule(module: Module) {
|
||||
getOrCreateSdkAdditionalData().associateWithModule(module)
|
||||
@ApiStatus.Internal
|
||||
fun SdkModificator.associateWithModule(module: Module) {
|
||||
val basePath = module.basePath ?: throw IllegalArgumentException("Module $module has no roots and can't be associated")
|
||||
getOrCreateSdkAdditionalData().associatedModulePath = basePath
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,11 +21,11 @@ internal fun SdkModificator.associateWithModule(module: Module) {
|
||||
*/
|
||||
internal fun SdkModificator.associateWithProject(project: Project) {
|
||||
val projectBasePath = project.basePath
|
||||
if (projectBasePath != null) getOrCreateSdkAdditionalData().associateWithModulePath(projectBasePath)
|
||||
if (projectBasePath != null) getOrCreateSdkAdditionalData().associatedModulePath = projectBasePath
|
||||
}
|
||||
|
||||
internal fun SdkModificator.resetAssociatedModulePath() {
|
||||
(sdkAdditionalData as? PythonSdkAdditionalData)?.resetAssociatedModulePath()
|
||||
(sdkAdditionalData as? PythonSdkAdditionalData)?.associatedModulePath = null
|
||||
}
|
||||
|
||||
private fun SdkModificator.getOrCreateSdkAdditionalData(): PythonSdkAdditionalData {
|
||||
|
||||
@@ -308,7 +308,7 @@ fun PyDetectedSdk.setupAssociated(existingSdks: List<Sdk>, associatedModulePath:
|
||||
} ?: PythonSdkAdditionalData()
|
||||
|
||||
if (doAssociate && associatedModulePath != null) {
|
||||
data.associateWithModulePath(associatedModulePath)
|
||||
data.associatedModulePath = associatedModulePath
|
||||
}
|
||||
|
||||
val sdk = SdkConfigurationUtil.setupSdk(
|
||||
|
||||
Reference in New Issue
Block a user