Java Code Examples for com.intellij.openapi.util.text.StringUtil#join()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VcsLogBranchFilterImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
  String result = "";
  if (!myPatterns.isEmpty()) {
    result += "on patterns: " + StringUtil.join(myPatterns, ", ");
  }
  if (!myBranches.isEmpty()) {
    if (!result.isEmpty()) result += "; ";
    result += "on branches: " + StringUtil.join(myBranches, ", ");
  }
  if (!myExcludedPatterns.isEmpty()) {
    if (result.isEmpty()) result += "; ";
    result += "not on patterns: " + StringUtil.join(myExcludedPatterns, ", ");
  }
  if (!myExcludedBranches.isEmpty()) {
    if (result.isEmpty()) result += "; ";
    result += "not on branches: " + StringUtil.join(myExcludedBranches, ", ");
  }
  return result;
}
 
Example 2
Source File: IgnoreTemplatesFactory.java    From idea-gitignore with MIT License 6 votes vote down vote up
/**
 * Creates new Gitignore file or uses an existing one.
 *
 * @param directory working directory
 * @return file
 */
@Nullable
public PsiFile createFromTemplate(final PsiDirectory directory) throws IncorrectOperationException {
    final String filename = fileType.getIgnoreLanguage().getFilename();
    final PsiFile currentFile = directory.findFile(filename);
    if (currentFile != null) {
        return currentFile;
    }
    final PsiFileFactory factory = PsiFileFactory.getInstance(directory.getProject());
    final IgnoreLanguage language = fileType.getIgnoreLanguage();

    String content = StringUtil.join(TEMPLATE_NOTE, Constants.NEWLINE);
    if (language.isSyntaxSupported() && !IgnoreBundle.Syntax.GLOB.equals(language.getDefaultSyntax())) {
        content = StringUtil.join(
                content,
                IgnoreBundle.Syntax.GLOB.getPresentation(),
                Constants.NEWLINE,
                Constants.NEWLINE
        );
    }
    final PsiFile file = factory.createFileFromText(filename, fileType, content);
    return (PsiFile) directory.add(file);
}
 
Example 3
Source File: NotificationMessageElement.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected JEditorPane installJep(@Nonnull JEditorPane myEditorPane) {
  String message = StringUtil.join(this.getText(), "<br>");
  myEditorPane.setEditable(false);
  myEditorPane.setOpaque(false);
  myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
  myEditorPane.setHighlighter(null);

  final StyleSheet styleSheet = ((HTMLDocument)myEditorPane.getDocument()).getStyleSheet();
  final Style style = styleSheet.addStyle(MSG_STYLE, null);
  styleSheet.addStyle(LINK_STYLE, style);
  myEditorPane.setText(message);

  return myEditorPane;
}
 
Example 4
Source File: ActionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String getActionUnavailableMessage(@Nonnull List<String> actionNames) {
  String message;
  final String beAvailableUntil = " available while " + ApplicationNamesInfo.getInstance().getProductName() + " is updating indices";
  if (actionNames.isEmpty()) {
    message = "This action is not" + beAvailableUntil;
  }
  else if (actionNames.size() == 1) {
    message = "'" + actionNames.get(0) + "' action is not" + beAvailableUntil;
  }
  else {
    message = "None of the following actions are" + beAvailableUntil + ": " + StringUtil.join(actionNames, ", ");
  }
  return message;
}
 
Example 5
Source File: VcsGeneralConfigurationPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String composeText(final List<AbstractVcs> applicableVcses) {
  final TreeSet<String> result = new TreeSet<String>();
  for (AbstractVcs abstractVcs : applicableVcses) {
    result.add(abstractVcs.getDisplayName());
  }
  return StringUtil.join(result, ", ");
}
 
Example 6
Source File: OSProcessUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ProcessInfo[] getProcessList() {
  JavaSysMon javaSysMon = new JavaSysMon();
  com.jezhumble.javasysmon.ProcessInfo[] processInfos = javaSysMon.processTable();
  ProcessInfo[] infos = new ProcessInfo[processInfos.length];
  for (int i = 0; i < processInfos.length; i++) {
    com.jezhumble.javasysmon.ProcessInfo info = processInfos[i];

    String executable;
    String args;
    List<String> commandLineList = StringUtil.splitHonorQuotes(info.getCommand(), ' ');
    if (commandLineList.isEmpty()) {
      executable = info.getName();
      args = "";
    }
    else {
      executable = commandLineList.get(0);
      if (commandLineList.size() > 1) {
        args = StringUtil.join(commandLineList.subList(1, commandLineList.size()), " ");
      }
      else {
        args = "";
      }
    }

    infos[i] = new ProcessInfo(info.getPid(), info.getCommand(), StringUtil.unquoteString(executable, '\"'), args);
  }
  return infos;
}
 
Example 7
Source File: UndoRedo.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void reportCannotUndo(String message, Collection<DocumentReference> problemFiles) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    throw new RuntimeException(
            message + "\n" + StringUtil.join(problemFiles, StringUtil.createToStringFunction(DocumentReference.class), "\n"));
  }
  new CannotUndoReportDialog(myManager.getProject(), message, problemFiles).show();
}
 
Example 8
Source File: GraphStrUtils.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String edgesToStr(@Nonnull Set<GraphEdge> edges) {
  if (edges.isEmpty()) return "none";

  List<GraphEdge> sortedEdges = new ArrayList<>(edges);
  Collections.sort(sortedEdges, GRAPH_ELEMENT_COMPARATOR);

  return StringUtil.join(sortedEdges, new Function<GraphEdge, String>() {
    @Override
    public String fun(GraphEdge graphEdge) {
      return graphEdge.getUpNodeIndex() + "_" + graphEdge.getDownNodeIndex() + "_" + toChar(graphEdge.getType());
    }
  }, " ");
}
 
Example 9
Source File: MuleDeployProperties.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
public static void addConfigFile(String appPath, String configFile)
{
    final String deployPropertiesFilePath = appPath + "/" + MULE_DEPLOY_PROPERTIES_FILE_NAME;
    final List<String> configFiles = new ArrayList<String>();
    try
    {
        if (new File(deployPropertiesFilePath).exists())
        {
            final Properties deployProperties = new Properties();
            deployProperties.load(new FileInputStream(deployPropertiesFilePath));
            String cfg = deployProperties.getProperty("config.resources");
            if (cfg != null && !"".equals(cfg.trim()))
            {
                String[] configs = cfg.trim().split(",");
                configFiles.addAll(Arrays.asList(configs));
            }
            if (!configFiles.contains(configFile))
            {//Avoid duplicates
                configFiles.add(configFile);
                final String configResourcesProperty = StringUtil.join(configFiles, ",");
                deployProperties.setProperty("config.resources", configResourcesProperty);
                final FileOutputStream out = new FileOutputStream(deployPropertiesFilePath);
                deployProperties.store(out, "Deployment properties are managed by the IntelliJ IDEA Mule Plugin; do not modify!");
            }
        }
    }
    catch (IOException e)
    {
        logger.error("Unable to add config resource to deployment properties: ", e);
    }
}
 
Example 10
Source File: VcsCherryPickAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String concatActionNamesForAllAvailable(@Nonnull final List<VcsCherryPicker> pickers) {
  return StringUtil.join(pickers, VcsCherryPicker::getActionTitle, "/");
}
 
Example 11
Source File: MessagesEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String filePaths(String[] files) {
  return StringUtil.join(files, ",\n");
}
 
Example 12
Source File: PathsList.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getPathsString() {
  return StringUtil.join(getPathList(), File.pathSeparator);
}
 
Example 13
Source File: Block.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public String getBlockContent() {
  return StringUtil.join(getLines(), "\n");
}
 
Example 14
Source File: BlazeConfigurationNameBuilder.java    From intellij with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a name of the form "{build system name} {command name} {target string}". Any null
 * components are omitted, and there is always one space inserted between each included component.
 */
public String build() {
  // Use this instead of String.join to omit null terms.
  return StringUtil.join(Arrays.asList(buildSystemName, commandName, targetString), " ");
}
 
Example 15
Source File: ExternalTaskExecutionInfo.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return StringUtil.join(mySettings.getTaskNames(), " ");
}
 
Example 16
Source File: TestClientRunner.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ProcessOutput runClient(@Nonnull String exeName, @javax.annotation.Nullable String stdin, @javax.annotation.Nullable final File workingDir, String... commandLine) throws IOException {
  final List<String> arguments = new ArrayList<String>();

  final File client = new File(myClientBinaryPath, SystemInfo.isWindows ? exeName + ".exe" : exeName);
  if (client.exists()) {
    arguments.add(client.toString());
  }
  else {
    // assume client is in path
    arguments.add(exeName);
  }
  Collections.addAll(arguments, commandLine);

  if (myTraceClient) {
    LOG.info("*** running:\n" + arguments);
    if (StringUtil.isNotEmpty(stdin)) {
      LOG.info("*** stdin:\n" + stdin);
    }
  }

  final ProcessBuilder builder = new ProcessBuilder().command(arguments);
  if (workingDir != null) {
    builder.directory(workingDir);
  }
  if (myClientEnvironment != null) {
    builder.environment().putAll(myClientEnvironment);
  }
  final Process clientProcess = builder.start();

  if (stdin != null) {
    final OutputStream outputStream = clientProcess.getOutputStream();
    try {
      final byte[] bytes = stdin.getBytes();
      outputStream.write(bytes);
    }
    finally {
      outputStream.close();
    }
  }

  final CapturingProcessHandler handler =
          new CapturingProcessHandler(clientProcess, CharsetToolkit.getDefaultSystemCharset(), StringUtil.join(arguments, " "));
  final ProcessOutput result = handler.runProcess(100 * 1000, false);
  if (myTraceClient || result.isTimeout()) {
    LOG.debug("*** result: " + result.getExitCode());
    final String out = result.getStdout().trim();
    if (out.length() > 0) {
      LOG.debug("*** output:\n" + out);
    }
    final String err = result.getStderr().trim();
    if (err.length() > 0) {
      LOG.debug("*** error:\n" + err);
    }
  }

  if (result.isTimeout()) {
    String processList = LogUtil.getProcessList();
    handler.destroyProcess();
    throw new RuntimeException("Timeout waiting for VCS client to finish execution:\n" + processList);
  }

  return result;
}
 
Example 17
Source File: VcsException.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getMessage() {
  return StringUtil.join(myMessages, ", ");
}
 
Example 18
Source File: GeneratedParserUtilBase.java    From intellij-latte with MIT License 4 votes vote down vote up
@Nullable
public String convertItem(Object o) {
	return o instanceof Object[] ? StringUtil.join((Object[]) o, this, " ") : o.toString();
}
 
Example 19
Source File: FileDocumentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void handleErrorsOnSave(@Nonnull Map<Document, IOException> failures) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    IOException ioException = ContainerUtil.getFirstItem(failures.values());
    if (ioException != null) {
      throw new RuntimeException(ioException);
    }
    return;
  }
  for (IOException exception : failures.values()) {
    LOG.warn(exception);
  }

  final String text = StringUtil.join(failures.values(), Throwable::getMessage, "\n");

  final DialogWrapper dialog = new DialogWrapper(null) {
    {
      init();
      setTitle(UIBundle.message("cannot.save.files.dialog.title"));
    }

    @Override
    protected void createDefaultActions() {
      super.createDefaultActions();
      myOKAction.putValue(Action.NAME, UIBundle.message(myOnClose ? "cannot.save.files.dialog.ignore.changes" : "cannot.save.files.dialog.revert.changes"));
      myOKAction.putValue(DEFAULT_ACTION, null);

      if (!myOnClose) {
        myCancelAction.putValue(Action.NAME, CommonBundle.getCloseButtonText());
      }
    }

    @Override
    protected JComponent createCenterPanel() {
      final JPanel panel = new JPanel(new BorderLayout(0, 5));

      panel.add(new JLabel(UIBundle.message("cannot.save.files.dialog.message")), BorderLayout.NORTH);

      final JTextPane area = new JTextPane();
      area.setText(text);
      area.setEditable(false);
      area.setMinimumSize(new Dimension(area.getMinimumSize().width, 50));
      panel.add(new JBScrollPane(area, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);

      return panel;
    }
  };

  if (dialog.showAndGet()) {
    for (Document document : failures.keySet()) {
      reloadFromDisk(document);
    }
  }
}
 
Example 20
Source File: MethodFQN.java    From intellij-reference-diagram with Apache License 2.0 4 votes vote down vote up
@NotNull
public static String createParameterRepresentation(List<String> parameters) {
    return StringUtil.join(parameters, ",");
}