@Override
 protected Process createProcess() throws ExecutionException {
   if (PySdkUtil.isRemote(mySdk)) {
     PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
     if (manager != null) {
       return createRemoteConsoleProcess(
           manager,
           myCommandLineArgumentsProvider.getArguments(),
           myCommandLineArgumentsProvider.getAdditionalEnvs());
     }
     throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
   } else {
     myCommandLine = myCommandLineArgumentsProvider.getCommandLineString();
     Map<String, String> envs = myCommandLineArgumentsProvider.getAdditionalEnvs();
     if (envs != null) {
       EncodingEnvironmentUtil.fixDefaultEncodingIfMac(envs, getProject());
     }
     final Process server =
         ProcessRunner.createProcess(
             getWorkingDir(), envs, myCommandLineArgumentsProvider.getArguments());
     try {
       myPydevConsoleCommunication =
           new PydevConsoleCommunication(getProject(), myPorts[0], server, myPorts[1]);
     } catch (Exception e) {
       throw new ExecutionException(e.getMessage());
     }
     return server;
   }
 }
 /**
  * This is hack. AWT doesn't allow to create KeyStroke with specified key code and key char
  * simultaneously. Therefore we are using reflection.
  */
 private static KeyStroke getKeyStrokeWithoutMouseModifiers(KeyStroke originalKeyStroke) {
   int modifier =
       originalKeyStroke.getModifiers()
           & ~InputEvent.BUTTON1_DOWN_MASK
           & ~InputEvent.BUTTON1_MASK
           & ~InputEvent.BUTTON2_DOWN_MASK
           & ~InputEvent.BUTTON2_MASK
           & ~InputEvent.BUTTON3_DOWN_MASK
           & ~InputEvent.BUTTON3_MASK;
   try {
     Method[] methods = AWTKeyStroke.class.getDeclaredMethods();
     Method getCachedStrokeMethod = null;
     for (Method method : methods) {
       if (GET_CACHED_STROKE_METHOD_NAME.equals(method.getName())) {
         getCachedStrokeMethod = method;
         getCachedStrokeMethod.setAccessible(true);
         break;
       }
     }
     if (getCachedStrokeMethod == null) {
       throw new IllegalStateException("not found method with name getCachedStrokeMethod");
     }
     Object[] getCachedStrokeMethodArgs =
         new Object[] {
           originalKeyStroke.getKeyChar(),
           originalKeyStroke.getKeyCode(),
           modifier,
           originalKeyStroke.isOnKeyRelease()
         };
     return (KeyStroke) getCachedStrokeMethod.invoke(originalKeyStroke, getCachedStrokeMethodArgs);
   } catch (Exception exc) {
     throw new IllegalStateException(exc.getMessage());
   }
 }
  private Process createRemoteConsoleProcess(
      PythonRemoteInterpreterManager manager, String[] command, Map<String, String> env)
      throws ExecutionException {
    PyRemoteSdkAdditionalDataBase data =
        (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
    assert data != null;

    GeneralCommandLine commandLine = new GeneralCommandLine(command);

    commandLine.getEnvironment().putAll(env);

    commandLine
        .getParametersList()
        .set(
            1,
            PythonRemoteInterpreterManager.toSystemDependent(
                new File(data.getHelpersPath(), PYDEV_PYDEVCONSOLE_PY).getPath(),
                PySourcePosition.isWindowsPath(data.getInterpreterPath())));
    commandLine.getParametersList().set(2, "0");
    commandLine.getParametersList().set(3, "0");

    myCommandLine = commandLine.getCommandLineString();

    try {
      myRemoteCredentials = data.getRemoteSdkCredentials(true);
      PathMappingSettings mappings = manager.setupMappings(getProject(), data, null);

      RemoteSshProcess remoteProcess =
          manager.createRemoteProcess(
              getProject(), myRemoteCredentials, mappings, commandLine, true);

      Couple<Integer> remotePorts = getRemotePortsFromProcess(remoteProcess);

      remoteProcess.addLocalTunnel(myPorts[0], myRemoteCredentials.getHost(), remotePorts.first);
      remoteProcess.addRemoteTunnel(remotePorts.second, "localhost", myPorts[1]);

      myPydevConsoleCommunication =
          new PydevRemoteConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
      return remoteProcess;
    } catch (Exception e) {
      throw new ExecutionException(e.getMessage());
    }
  }
 private void onTextChange() {
   if (!myIsInUpdate) {
     myUpdateAlarm.cancelAllRequests();
     myTextChanged = true;
     final String text = myPatternField.getText();
     myCurrentScope = new InvalidPackageSet(text);
     try {
       if (!StringUtil.isEmpty(text)) {
         myCurrentScope = PackageSetFactory.getInstance().compile(text);
       }
       myErrorMessage = null;
     } catch (Exception e) {
       myErrorMessage = e.getMessage();
       showErrorMessage();
     }
     rebuild(false);
   } else if (!invalidScopeInside(myCurrentScope)) {
     myErrorMessage = null;
   }
 }
  protected void doOKAction() {
    if (!isOKActionEnabled()) {
      return;
    }

    if (isTextFieldActive()) {
      final String text = myPathTextField.getTextFieldText();
      final LookupFile file = myPathTextField.getFile();
      if (text == null || file == null || !file.exists()) {
        setErrorText("Specified path cannot be found");
        return;
      }
    }

    final List<VirtualFile> selectedFiles = Arrays.asList(getSelectedFilesInt());
    final VirtualFile[] files =
        VfsUtilCore.toVirtualFileArray(
            FileChooserUtil.getChosenFiles(myChooserDescriptor, selectedFiles));
    if (files.length == 0) {
      myChosenFiles = VirtualFile.EMPTY_ARRAY;
      close(CANCEL_EXIT_CODE);
      return;
    }

    try {
      myChooserDescriptor.validateSelectedFiles(files);
    } catch (Exception e) {
      Messages.showErrorDialog(getContentPane(), e.getMessage(), getTitle());
      return;
    }

    myChosenFiles = files;
    storeSelection(files[files.length - 1]);

    super.doOKAction();
  }
  @Override
  public void actionPerformed(AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);

    LOG.assertTrue(project != null);

    final FileChooserDescriptor descriptor =
        new FileChooserDescriptor(false, true, false, false, false, false) {
          @Override
          public Icon getIcon(VirtualFile file) {
            if (file.isDirectory()) {
              if (file.findChild(
                      InspectionApplication.DESCRIPTIONS
                          + "."
                          + StdFileTypes.XML.getDefaultExtension())
                  != null) {
                return AllIcons.Nodes.InspectionResults;
              }
            }
            return super.getIcon(file);
          }
        };
    descriptor.setTitle("Select Path");
    descriptor.setDescription("Select directory which contains exported inspections results");
    final VirtualFile virtualFile = FileChooser.chooseFile(descriptor, project, null);
    if (virtualFile == null || !virtualFile.isDirectory()) return;

    final Map<String, Map<String, Set<OfflineProblemDescriptor>>> resMap = new HashMap<>();
    final String[] profileName = new String[1];
    final Runnable process =
        () -> {
          final VirtualFile[] files = virtualFile.getChildren();
          try {
            for (final VirtualFile inspectionFile : files) {
              if (inspectionFile.isDirectory()) continue;
              final String shortName = inspectionFile.getNameWithoutExtension();
              final String extension = inspectionFile.getExtension();
              if (shortName.equals(InspectionApplication.DESCRIPTIONS)) {
                profileName[0] =
                    ApplicationManager.getApplication()
                        .runReadAction(
                            (Computable<String>)
                                () ->
                                    OfflineViewParseUtil.parseProfileName(
                                        LoadTextUtil.loadText(inspectionFile).toString()));
              } else if (XML_EXTENSION.equals(extension)) {
                resMap.put(
                    shortName,
                    ApplicationManager.getApplication()
                        .runReadAction(
                            new Computable<Map<String, Set<OfflineProblemDescriptor>>>() {
                              @Override
                              public Map<String, Set<OfflineProblemDescriptor>> compute() {
                                return OfflineViewParseUtil.parse(
                                    LoadTextUtil.loadText(inspectionFile).toString());
                              }
                            }));
              }
            }
          } catch (final Exception e) { // all parse exceptions
            SwingUtilities.invokeLater(
                () ->
                    Messages.showInfoMessage(
                        e.getMessage(),
                        InspectionsBundle.message("offline.view.parse.exception.title")));
            throw new ProcessCanceledException(); // cancel process
          }
        };
    ProgressManager.getInstance()
        .runProcessWithProgressAsynchronously(
            project,
            InspectionsBundle.message("parsing.inspections.dump.progress.title"),
            process,
            () ->
                SwingUtilities.invokeLater(
                    () -> {
                      final String name = profileName[0];
                      showOfflineView(
                          project,
                          name,
                          resMap,
                          InspectionsBundle.message("offline.view.title")
                              + " ("
                              + (name != null
                                  ? name
                                  : InspectionsBundle.message("offline.view.editor.settings.title"))
                              + ")");
                    }),
            null,
            new PerformAnalysisInBackgroundOption(project));
  }