use of com.intellij.openapi.util.Pair in project intellij-plugins by StepicOrg.
the class StudyProjectComponent method addShortcut.
private void addShortcut(@NotNull final String actionIdString, @NotNull final String[] shortcuts) {
KeymapManagerEx keymapManager = KeymapManagerEx.getInstanceEx();
for (Keymap keymap : keymapManager.getAllKeymaps()) {
List<Pair<String, String>> pairs = deletedShortcuts.computeIfAbsent(keymap, k -> new ArrayList<>());
for (String shortcutString : shortcuts) {
Shortcut studyActionShortcut = new KeyboardShortcut(KeyStroke.getKeyStroke(shortcutString), null);
String[] actionsIds = keymap.getActionIds(studyActionShortcut);
for (String actionId : actionsIds) {
pairs.add(Pair.create(actionId, shortcutString));
keymap.removeShortcut(actionId, studyActionShortcut);
}
keymap.addShortcut(actionIdString, studyActionShortcut);
}
}
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class MavenPluginParamInfo method getParamInfoList.
public static ParamInfoList getParamInfoList(@NotNull XmlTag paramTag) {
XmlTag configurationTag = paramTag;
DomElement domElement;
Map m = getMap().get(paramTag.getName());
while (true) {
if (m == null)
return ParamInfoList.EMPTY;
configurationTag = configurationTag.getParentTag();
if (configurationTag == null)
return ParamInfoList.EMPTY;
String tagName = configurationTag.getName();
if ("configuration".equals(tagName)) {
domElement = DomManager.getDomManager(configurationTag.getProject()).getDomElement(configurationTag);
if (domElement instanceof MavenDomConfiguration) {
break;
}
if (domElement != null)
return ParamInfoList.EMPTY;
}
m = (Map) m.get(tagName);
}
Map<Pair<String, String>, Map<String, ParamInfo>> pluginsMap = m;
MavenDomConfiguration domCfg = (MavenDomConfiguration) domElement;
MavenDomPlugin domPlugin = domCfg.getParentOfType(MavenDomPlugin.class, true);
if (domPlugin == null)
return ParamInfoList.EMPTY;
String pluginGroupId = domPlugin.getGroupId().getStringValue();
String pluginArtifactId = domPlugin.getArtifactId().getStringValue();
Map<String, ParamInfo> goalsMap;
if (pluginGroupId == null) {
goalsMap = pluginsMap.get(Pair.create("org.apache.maven.plugins", pluginArtifactId));
if (goalsMap == null) {
goalsMap = pluginsMap.get(Pair.create("org.codehaus.mojo", pluginArtifactId));
}
} else {
goalsMap = pluginsMap.get(Pair.create(pluginGroupId, pluginArtifactId));
}
if (goalsMap == null)
return ParamInfoList.EMPTY;
DomElement parent = domCfg.getParent();
if (parent instanceof MavenDomPluginExecution) {
SmartList<ParamInfo> infos = null;
MavenDomGoals goals = ((MavenDomPluginExecution) parent).getGoals();
for (MavenDomGoal goal : goals.getGoals()) {
ParamInfo info = goalsMap.get(goal.getStringValue());
if (info != null) {
if (infos == null) {
infos = new SmartList<>();
}
infos.add(info);
}
}
if (infos != null) {
ParamInfo defaultInfo = goalsMap.get(null);
if (defaultInfo != null) {
infos.add(defaultInfo);
}
return new ParamInfoList(domCfg, infos);
}
}
ParamInfo defaultInfo = goalsMap.get(null);
if (defaultInfo != null) {
return new ParamInfoList(domCfg, Collections.singletonList(defaultInfo));
}
return ParamInfoList.EMPTY;
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class MavenProjectImporter method collectIncompatibleModulesWithProjects.
/**
* Collects modules that need to change module type
* @return the first List in returned Pair contains already mavenized modules, the second List - not mavenized
*/
private Pair<List<Pair<MavenProject, Module>>, List<Pair<MavenProject, Module>>> collectIncompatibleModulesWithProjects() {
List<Pair<MavenProject, Module>> incompatibleMavenized = new ArrayList<>();
List<Pair<MavenProject, Module>> incompatibleNotMavenized = new ArrayList<>();
MavenProjectsManager manager = MavenProjectsManager.getInstance(myProject);
for (MavenProject each : myAllProjects) {
Module module = myFileToModuleMapping.get(each.getFile());
if (module == null)
continue;
if (shouldCreateModuleFor(each) && !(ModuleType.get(module).equals(each.getModuleType()))) {
(manager.isMavenizedModule(module) ? incompatibleMavenized : incompatibleNotMavenized).add(Pair.create(each, module));
}
}
return Pair.create(incompatibleMavenized, incompatibleNotMavenized);
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class PydevConsoleCommunication method execInterpreter.
/**
* Executes a given line in the interpreter.
*
* @param command the command to be executed in the client
*/
public void execInterpreter(final ConsoleCodeFragment command, final Function<InterpreterResponse, Object> onResponseReceived) {
if (myDebugCommunication != null && myDebugCommunication.isSuspended()) {
myDebugCommunication.execInterpreter(command, onResponseReceived);
//TODO: handle text input and other cases
return;
}
nextResponse = null;
if (waitingForInput) {
inputReceived = command.getText();
waitingForInput = false;
//the thread that we started in the last exec is still alive if we were waiting for an input.
} else {
//create a thread that'll keep locked until an answer is received from the server.
new Task.Backgroundable(myProject, "REPL Communication", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
boolean needInput = false;
try {
Pair<String, Boolean> executed = null;
//the 1st time we'll do a connection attempt, we can try to connect n times (until the 1st time the connection
//is accepted) -- that's mostly because the server may take a while to get started.
int commAttempts = 0;
while (true) {
if (indicator.isCanceled()) {
return;
}
executed = exec(command);
//executed.o1 is not null only if we had an error
String refusedConnPattern = "Failed to read servers response";
// the XML-RPC library)
if (executed.first != null && executed.first.indexOf(refusedConnPattern) != -1) {
if (firstCommWorked) {
break;
} else {
if (commAttempts < MAX_ATTEMPTS) {
commAttempts += 1;
Thread.sleep(250);
executed = Pair.create("", executed.second);
} else {
break;
}
}
} else {
break;
}
//unreachable code!! -- commented because eclipse will complain about it
//throw new RuntimeException("Can never get here!");
}
firstCommWorked = true;
boolean more = executed.second;
nextResponse = new InterpreterResponse(more, needInput);
} catch (Exception e) {
nextResponse = new InterpreterResponse(false, needInput);
}
}
}.queue();
//busy loop waiting for the answer (or having the console die).
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setText("Waiting for REPL response with " + (int) (TIMEOUT / 10e8) + "s timeout");
final long startTime = System.nanoTime();
while (nextResponse == null) {
if (progressIndicator.isCanceled()) {
LOG.debug("Canceled");
nextResponse = new InterpreterResponse(false, false);
}
final long time = System.nanoTime() - startTime;
progressIndicator.setFraction(((double) time) / TIMEOUT);
if (time > TIMEOUT) {
LOG.debug("Timeout exceeded");
nextResponse = new InterpreterResponse(false, false);
}
synchronized (lock2) {
try {
lock2.wait(20);
} catch (InterruptedException e) {
LOG.error(e);
}
}
}
if (nextResponse.more) {
myNeedsMore = true;
notifyCommandExecuted(true);
}
onResponseReceived.fun(nextResponse);
}, "Waiting for REPL response", true, myProject);
}
}
use of com.intellij.openapi.util.Pair in project intellij-community by JetBrains.
the class PythonDebugConsoleCommunication method execInterpreter.
public void execInterpreter(ConsoleCodeFragment code, final Function<InterpreterResponse, Object> callback) {
if (waitingForInput) {
final OutputStream processInput = myDebugProcess.getProcessHandler().getProcessInput();
if (processInput != null) {
try {
final Charset defaultCharset = EncodingProjectManager.getInstance(myDebugProcess.getProject()).getDefaultCharset();
processInput.write((code.getText()).getBytes(defaultCharset));
processInput.flush();
} catch (IOException e) {
LOG.error(e.getMessage());
}
}
myNeedsMore = false;
waitingForInput = false;
notifyCommandExecuted(waitingForInput);
} else {
exec(new ConsoleCodeFragment(code.getText(), false), new PyDebugCallback<Pair<String, Boolean>>() {
@Override
public void ok(Pair<String, Boolean> executed) {
boolean more = executed.second;
myNeedsMore = more;
notifyCommandExecuted(more);
callback.fun(new InterpreterResponse(more, isWaitingForInput()));
}
@Override
public void error(PyDebuggerException exception) {
myNeedsMore = false;
notifyCommandExecuted(false);
callback.fun(new InterpreterResponse(false, isWaitingForInput()));
}
});
}
}
Aggregations