IDEA-188810 use stream foldLeft and docs change

This commit is contained in:
Dmitry.Krasilschikov
2018-04-19 14:13:48 +03:00
parent dbbbd9e421
commit bce05603fa
3 changed files with 18 additions and 26 deletions
@@ -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;
@@ -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));
}
}
@@ -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)