mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-188810 use stream foldLeft and docs change
This commit is contained in:
@@ -19,7 +19,6 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.keymap.MacKeymapUtil;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.util.*;
|
||||
@@ -343,7 +342,6 @@ public class RunAnythingUtil {
|
||||
@NotNull String pattern,
|
||||
@NotNull VirtualFile workDirectory) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||
Module module = LangDataKeys.MODULE.getData(dataContext);
|
||||
|
||||
if (pattern.isEmpty()) return;
|
||||
|
||||
|
||||
+14
-23
@@ -5,6 +5,7 @@ import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -16,51 +17,41 @@ public abstract class RunAnythingCommandCustomizer {
|
||||
ExtensionPointName.create("com.intellij.runAnything.commandCustomizer");
|
||||
|
||||
/**
|
||||
* Customizes command line and pass it to others customizers
|
||||
* Customizes command line to be executed
|
||||
*
|
||||
* @param workDirectory the working directory the command will be executed in
|
||||
* @param dataContext {@link DataContext} to fetch module, project etc.
|
||||
* @param commandLine command line to be executed
|
||||
* @return customized command line
|
||||
* @param commandLine command line to be customized
|
||||
* @return patched command line
|
||||
*/
|
||||
@NotNull
|
||||
public GeneralCommandLine customizeCommandLine(@NotNull VirtualFile workDirectory,
|
||||
@NotNull DataContext dataContext,
|
||||
@NotNull GeneralCommandLine commandLine) {
|
||||
protected GeneralCommandLine customizeCommandLine(@NotNull VirtualFile workDirectory,
|
||||
@NotNull DataContext dataContext,
|
||||
@NotNull GeneralCommandLine commandLine) {
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customizes data context and pass it to others providers
|
||||
* Customizes data context command line to be executed on
|
||||
*
|
||||
* @param dataContext {@link DataContext} to fetch module, project etc.
|
||||
* @param dataContext original {@link DataContext}
|
||||
* @return customized {@link DataContext}
|
||||
*/
|
||||
@NotNull
|
||||
public DataContext customizeDataContext(@NotNull DataContext dataContext) {
|
||||
protected DataContext customizeDataContext(@NotNull DataContext dataContext) {
|
||||
return dataContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GeneralCommandLine customizeCommandLine(@NotNull DataContext dataContext,
|
||||
@NotNull VirtualFile workDirectory,
|
||||
@NotNull String command) {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine(command)
|
||||
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE);
|
||||
|
||||
for (RunAnythingCommandCustomizer customizer : EP_NAME.getExtensions()) {
|
||||
commandLine = customizer.customizeCommandLine(workDirectory, dataContext, commandLine);
|
||||
}
|
||||
|
||||
return commandLine;
|
||||
@NotNull GeneralCommandLine commandLine) {
|
||||
return StreamEx.of(EP_NAME.getExtensions())
|
||||
.foldLeft(commandLine, (cmdLine, customizer) -> customizer.customizeCommandLine(workDirectory, dataContext, cmdLine));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static DataContext customizeContext(@NotNull DataContext dataContext) {
|
||||
for (RunAnythingCommandCustomizer customizer : EP_NAME.getExtensions()) {
|
||||
dataContext = customizer.customizeDataContext(dataContext);
|
||||
}
|
||||
|
||||
return dataContext;
|
||||
return StreamEx.of(EP_NAME.getExtensions()).foldLeft(dataContext, (context, customizer) -> customizer.customizeDataContext(context));
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -70,7 +70,10 @@ public class RunAnythingCommandItem extends RunAnythingItem<String> {
|
||||
commands.add(commandString);
|
||||
|
||||
dataContext = RunAnythingCommandCustomizer.customizeContext(dataContext);
|
||||
GeneralCommandLine commandLine = RunAnythingCommandCustomizer.customizeCommandLine(dataContext, workDirectory, commandString);
|
||||
|
||||
GeneralCommandLine initialCommandLine =
|
||||
new GeneralCommandLine(commandString).withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE);
|
||||
GeneralCommandLine commandLine = RunAnythingCommandCustomizer.customizeCommandLine(dataContext, workDirectory, initialCommandLine);
|
||||
try {
|
||||
ExecutionEnvironmentBuilder.create(project, executor, new RunAnythingRunProfile(commandLine, commandString))
|
||||
.dataContext(dataContext)
|
||||
|
||||
Reference in New Issue
Block a user