mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull, cleanup
This commit is contained in:
@@ -72,7 +72,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
|
||||
// GUI components
|
||||
private JPanel myMainPanel;
|
||||
private TabbedPaneWrapper myTabbedPane;
|
||||
private Project myProject;
|
||||
private final Project myProject;
|
||||
private final SdkModel mySdkModel;
|
||||
private JLabel myHomeFieldLabel;
|
||||
private String myVersionString;
|
||||
@@ -199,7 +199,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
|
||||
for (SdkPathEditor pathEditor : myPathEditors.values()) {
|
||||
pathEditor.apply(sdkModificator);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(() -> sdkModificator.commitChanges());
|
||||
ApplicationManager.getApplication().runWriteAction(sdkModificator::commitChanges);
|
||||
for (final AdditionalDataConfigurable configurable : getAdditionalDataConfigurable()) {
|
||||
if (configurable != null) {
|
||||
configurable.apply();
|
||||
@@ -435,6 +435,7 @@ public class SdkEditor implements Configurable, Place.Navigator {
|
||||
throw new UnsupportedOperationException(); // not supported for this editor
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getRoots(OrderRootType rootType) {
|
||||
final PathEditor editor = myPathEditors.get(rootType);
|
||||
@@ -443,17 +444,17 @@ public class SdkEditor implements Configurable, Place.Navigator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
myPathEditors.get(rootType).addPaths(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
myPathEditors.get(rootType).removePaths(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoots(OrderRootType rootType) {
|
||||
public void removeRoots(@NotNull OrderRootType rootType) {
|
||||
myPathEditors.get(rootType).clearList();
|
||||
}
|
||||
|
||||
|
||||
@@ -388,15 +388,16 @@ public class JavaSdkImpl extends JavaSdk {
|
||||
@Override public void setVersionString(String versionString) { throw new UnsupportedOperationException(); }
|
||||
@Override public SdkAdditionalData getSdkAdditionalData() { throw new UnsupportedOperationException(); }
|
||||
@Override public void setSdkAdditionalData(SdkAdditionalData data) { throw new UnsupportedOperationException(); }
|
||||
@NotNull
|
||||
@Override public VirtualFile[] getRoots(OrderRootType rootType) { throw new UnsupportedOperationException(); }
|
||||
@Override public void removeRoot(VirtualFile root, OrderRootType rootType) { throw new UnsupportedOperationException(); }
|
||||
@Override public void removeRoots(OrderRootType rootType) { throw new UnsupportedOperationException(); }
|
||||
@Override public void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) { throw new UnsupportedOperationException(); }
|
||||
@Override public void removeRoots(@NotNull OrderRootType rootType) { throw new UnsupportedOperationException(); }
|
||||
@Override public void removeAllRoots() { throw new UnsupportedOperationException(); }
|
||||
@Override public void commitChanges() { throw new UnsupportedOperationException(); }
|
||||
@Override public boolean isWritable() { throw new UnsupportedOperationException(); }
|
||||
|
||||
@Override
|
||||
public void addRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
rootContainer.addRoot(root, rootType);
|
||||
}
|
||||
};
|
||||
@@ -435,17 +436,17 @@ public class JavaSdkImpl extends JavaSdk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
throwReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
throwReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoots(OrderRootType rootType) {
|
||||
public void removeRoots(@NotNull OrderRootType rootType) {
|
||||
throwReadOnly();
|
||||
}
|
||||
|
||||
@@ -464,6 +465,7 @@ public class JavaSdkImpl extends JavaSdk {
|
||||
throwReadOnly();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getRoots(OrderRootType rootType) {
|
||||
return rootContainer.getRootFiles(rootType);
|
||||
|
||||
@@ -19,13 +19,14 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.projectRoots.SdkModificator;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SdkPathEditor extends PathEditor {
|
||||
private final String myDisplayName;
|
||||
private final OrderRootType myOrderRootType;
|
||||
|
||||
public SdkPathEditor(String displayName, OrderRootType orderRootType, FileChooserDescriptor descriptor) {
|
||||
public SdkPathEditor(String displayName, @NotNull OrderRootType orderRootType, FileChooserDescriptor descriptor) {
|
||||
super(descriptor);
|
||||
myDisplayName = displayName;
|
||||
myOrderRootType = orderRootType;
|
||||
@@ -35,6 +36,7 @@ public class SdkPathEditor extends PathEditor {
|
||||
return myDisplayName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OrderRootType getOrderRootType() {
|
||||
return myOrderRootType;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.openapi.projectRoots;
|
||||
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface SdkModificator {
|
||||
@@ -37,13 +38,14 @@ public interface SdkModificator {
|
||||
|
||||
void setSdkAdditionalData(SdkAdditionalData data);
|
||||
|
||||
@NotNull
|
||||
VirtualFile[] getRoots(OrderRootType rootType);
|
||||
|
||||
void addRoot(VirtualFile root, OrderRootType rootType);
|
||||
void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType);
|
||||
|
||||
void removeRoot(VirtualFile root, OrderRootType rootType);
|
||||
void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType);
|
||||
|
||||
void removeRoots(OrderRootType rootType);
|
||||
void removeRoots(@NotNull OrderRootType rootType);
|
||||
|
||||
void removeAllRoots();
|
||||
|
||||
|
||||
+4
-3
@@ -321,6 +321,7 @@ public class ProjectJdkImpl extends UserDataHolderBase implements Sdk, SdkModifi
|
||||
myAdditionalData = data;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VirtualFile[] getRoots(OrderRootType rootType) {
|
||||
final ProjectRoot[] roots = myRootContainer.getRoots(rootType); // use getRoots() cause the data is most up-to-date there
|
||||
@@ -332,17 +333,17 @@ public class ProjectJdkImpl extends UserDataHolderBase implements Sdk, SdkModifi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void addRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
myRootContainer.addRoot(root, rootType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoot(VirtualFile root, OrderRootType rootType) {
|
||||
public void removeRoot(@NotNull VirtualFile root, @NotNull OrderRootType rootType) {
|
||||
myRootContainer.removeRoot(root, rootType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRoots(OrderRootType rootType) {
|
||||
public void removeRoots(@NotNull OrderRootType rootType) {
|
||||
myRootContainer.removeAllRoots(rootType);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileSystemUtil;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.CharFilter;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
@@ -83,7 +82,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -101,16 +99,16 @@ import java.util.stream.Collectors;
|
||||
public final class PythonSdkType extends SdkType {
|
||||
public static final String REMOTE_SOURCES_DIR_NAME = "remote_sources";
|
||||
private static final Logger LOG = Logger.getInstance(PythonSdkType.class);
|
||||
private static final String[] WINDOWS_EXECUTABLE_SUFFIXES = new String[]{"cmd", "exe", "bat", "com"};
|
||||
private static final String[] WINDOWS_EXECUTABLE_SUFFIXES = {"cmd", "exe", "bat", "com"};
|
||||
|
||||
static final int MINUTE = 60 * 1000; // 60 seconds, used with script timeouts
|
||||
@NonNls public static final String SKELETONS_TOPIC = "Skeletons";
|
||||
private static final String[] DIRS_WITH_BINARY = new String[]{"", "bin", "Scripts"};
|
||||
private static final String[] UNIX_BINARY_NAMES = new String[]{"jython", "pypy", "python", "python3"};
|
||||
private static final String[] WIN_BINARY_NAMES = new String[]{"jython.bat", "ipy.exe", "pypy.exe", "python.exe", "python3.exe"};
|
||||
private static final int MINUTE = 60 * 1000; // 60 seconds, used with script timeouts
|
||||
@NonNls private static final String SKELETONS_TOPIC = "Skeletons";
|
||||
private static final String[] DIRS_WITH_BINARY = {"", "bin", "Scripts"};
|
||||
private static final String[] UNIX_BINARY_NAMES = {"jython", "pypy", "python", "python3"};
|
||||
private static final String[] WIN_BINARY_NAMES = {"jython.bat", "ipy.exe", "pypy.exe", "python.exe", "python3.exe"};
|
||||
|
||||
private static final Key<WeakReference<Component>> SDK_CREATOR_COMPONENT_KEY = Key.create("#com.jetbrains.python.sdk.creatorComponent");
|
||||
public static final Predicate<Sdk> REMOTE_SDK_PREDICATE = sdk -> isRemote(sdk);
|
||||
private static final Predicate<Sdk> REMOTE_SDK_PREDICATE = PythonSdkType::isRemote;
|
||||
|
||||
public static PythonSdkType getInstance() {
|
||||
return SdkType.findInstance(PythonSdkType.class);
|
||||
@@ -120,6 +118,7 @@ public final class PythonSdkType extends SdkType {
|
||||
super("Python SDK");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return PythonIcons.Python.Python;
|
||||
}
|
||||
@@ -130,6 +129,7 @@ public final class PythonSdkType extends SdkType {
|
||||
return "reference.project.structure.sdk.python";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Icon getIconForAddAction() {
|
||||
return PythonFileType.INSTANCE.getIcon();
|
||||
@@ -150,6 +150,7 @@ public final class PythonSdkType extends SdkType {
|
||||
return level.isOlderThan(LanguageLevel.PYTHON30) ? PyBuiltinCache.BUILTIN_FILE : PyBuiltinCache.BUILTIN_FILE_3K;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNls
|
||||
@Nullable
|
||||
public String suggestHomePath() {
|
||||
@@ -201,11 +202,7 @@ public final class PythonSdkType extends SdkType {
|
||||
}
|
||||
|
||||
private static String findDigits(String s) {
|
||||
int pos = StringUtil.findFirst(s, new CharFilter() {
|
||||
public boolean accept(char ch) {
|
||||
return Character.isDigit(ch);
|
||||
}
|
||||
});
|
||||
int pos = StringUtil.findFirst(s, Character::isDigit);
|
||||
if (pos >= 0) {
|
||||
return s.substring(pos);
|
||||
}
|
||||
@@ -221,6 +218,7 @@ public final class PythonSdkType extends SdkType {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidSdkHome(@Nullable final String path) {
|
||||
return PythonSdkFlavor.getFlavor(path) != null;
|
||||
}
|
||||
@@ -285,10 +283,12 @@ public final class PythonSdkType extends SdkType {
|
||||
}.withTitle(PyBundle.message("sdk.select.path")).withShowHiddenFiles(SystemInfo.isUnix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsCustomCreateUI() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCustomCreateUI(@NotNull SdkModel sdkModel,
|
||||
@NotNull final JComponent parentComponent,
|
||||
@NotNull final Consumer<Sdk> sdkCreatedCallback) {
|
||||
@@ -424,6 +424,7 @@ public final class PythonSdkType extends SdkType {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String suggestSdkName(final String currentSdkName, final String sdkHome) {
|
||||
String name = getVersionString(sdkHome);
|
||||
return suggestSdkNameFromVersion(sdkHome, name);
|
||||
@@ -447,6 +448,7 @@ public final class PythonSdkType extends SdkType {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public AdditionalDataConfigurable createAdditionalDataConfigurable(@NotNull final SdkModel sdkModel,
|
||||
@NotNull final SdkModificator sdkModificator) {
|
||||
@@ -475,6 +477,7 @@ public final class PythonSdkType extends SdkType {
|
||||
return path.contains(SKELETON_DIR_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@NonNls
|
||||
public String getPresentableName() {
|
||||
@@ -494,6 +497,7 @@ public final class PythonSdkType extends SdkType {
|
||||
return FileUtil.toSystemDependentName(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupSdkPaths(@NotNull Sdk sdk) {
|
||||
final Project project;
|
||||
final WeakReference<Component> ownerComponentRef = sdk.getUserData(SDK_CREATOR_COMPONENT_KEY);
|
||||
@@ -517,23 +521,20 @@ public final class PythonSdkType extends SdkType {
|
||||
String notificationMessage;
|
||||
if (e.getCause() instanceof VagrantNotStartedException) {
|
||||
notificationListener =
|
||||
new NotificationListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
|
||||
final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
|
||||
if (manager != null) {
|
||||
try {
|
||||
VagrantNotStartedException cause = (VagrantNotStartedException)e.getCause();
|
||||
manager.runVagrant(cause.getVagrantFolder(), cause.getMachineName());
|
||||
}
|
||||
catch (ExecutionException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
(notification, event) -> {
|
||||
final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
|
||||
if (manager != null) {
|
||||
try {
|
||||
VagrantNotStartedException cause = (VagrantNotStartedException)e.getCause();
|
||||
manager.runVagrant(cause.getVagrantFolder(), cause.getMachineName());
|
||||
}
|
||||
if (restartAction != null) {
|
||||
restartAction.run();
|
||||
catch (ExecutionException e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
if (restartAction != null) {
|
||||
restartAction.run();
|
||||
}
|
||||
};
|
||||
notificationMessage = e.getMessage() + "\n<a href=\"#\">Launch vagrant and refresh skeletons</a>";
|
||||
}
|
||||
@@ -541,13 +542,10 @@ public final class PythonSdkType extends SdkType {
|
||||
//noinspection ThrowableResultOfMethodCallIgnored
|
||||
final ExceptionFix fix = ExceptionUtil.findCause(e, ExceptionFix.class);
|
||||
notificationListener =
|
||||
new NotificationListener() {
|
||||
@Override
|
||||
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
|
||||
fix.apply();
|
||||
if (restartAction != null) {
|
||||
restartAction.run();
|
||||
}
|
||||
(notification, event) -> {
|
||||
fix.apply();
|
||||
if (restartAction != null) {
|
||||
restartAction.run();
|
||||
}
|
||||
};
|
||||
notificationMessage = fix.getNotificationMessage(e.getMessage());
|
||||
@@ -578,7 +576,7 @@ public final class PythonSdkType extends SdkType {
|
||||
if (suffix != null) {
|
||||
suffix = suffix.toLowerCase(); // Why on earth empty suffix is null and not ""?
|
||||
}
|
||||
if ((!path.isDirectory()) && ("zip".equals(suffix) || "egg".equals(suffix))) {
|
||||
if (!path.isDirectory() && ("zip".equals(suffix) || "egg".equals(suffix))) {
|
||||
// a .zip / .egg file must have its root extracted first
|
||||
final VirtualFile jar = JarFileSystem.getInstance().getJarRootForLocalFile(path);
|
||||
if (jar != null) {
|
||||
@@ -669,6 +667,7 @@ public final class PythonSdkType extends SdkType {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getVersionString(final String sdkHome) {
|
||||
final PythonSdkFlavor flavor = PythonSdkFlavor.getFlavor(sdkHome);
|
||||
@@ -730,10 +729,12 @@ public final class PythonSdkType extends SdkType {
|
||||
return LanguageLevel.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRootTypeApplicable(@NotNull final OrderRootType type) {
|
||||
return type == OrderRootType.CLASSES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sdkHasValidPath(@NotNull Sdk sdk) {
|
||||
if (PySdkUtil.isRemote(sdk)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user