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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#splitByLines() . 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: WindowsDefenderChecker.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Boolean parseWindowsDefenderProductState(ProcessOutput output) {
  final String[] lines = StringUtil.splitByLines(output.getStdout());
  for (String line : lines) {
    if (line.startsWith("Windows Defender")) {
      final String productStateString = StringUtil.substringAfterLast(line, " ");
      int productState;
      try {
        productState = Integer.parseInt(productStateString);
        return (productState & 0x1000) != 0;
      }
      catch (NumberFormatException e) {
        LOG.info("Unexpected wmic output format: " + line);
        return null;
      }
    }
  }
  return false;
}
 
Example 2
Source File: CustomProjectIntegrationTests.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private static Collection<Object[]> getTargetsFromFile(String projectConfigFileName) {
  final File projectConfigFile = new File(projectConfigFileName);
  assertExists(projectConfigFile);
  try{
    final String[] testProjectList = StringUtil.splitByLines(FileUtil.loadFile(projectConfigFile));
    return getTargets(testProjectList);
  } catch (IOException e) {
    fail("Exception loading file " + projectConfigFileName + " due to " + e.getMessage());
  }
  return null;
}
 
Example 3
Source File: UnityDebugProcess.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private void print(String text, String stacktrace, ConsoleView view, ConsoleViewContentType contentType)
{
	view.print(text + "\n", contentType);
	if(contentType == ConsoleViewContentType.ERROR_OUTPUT && !StringUtil.isEmpty(stacktrace))
	{
		StringBuilder builder = new StringBuilder();
		String[] strings = StringUtil.splitByLines(stacktrace);
		for(String line : strings)
		{
			builder.append("  at ").append(line).append("\n");
		}

		view.print(builder.toString(), contentType);
	}
}
 
Example 4
Source File: PlainTextFormatter.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void writeInspectionDescription(@Nonnull final Writer w,
                                          @Nonnull final InspectionToolWrapper toolWrapper,
                                          @Nonnull final Transformer transformer)
  throws IOException, ConversionException {

  final StringWriter descrWriter = new StringWriter();
  String descr = toolWrapper.loadDescription();
  if (descr == null) {
    return;
  }
  // convert line ends to xml form
  descr = descr.replace("<br>", "<br/>");

  try {

    transformer.transform(new StreamSource(new StringReader(descr)), new StreamResult(descrWriter));
  }
  catch (TransformerException e) {
    // Not critical problem, just inspection error cannot be loaded
    warn("ERROR:  Cannot load description for inspection: " + getToolPresentableName(toolWrapper) + ".\n        Error message: " + e.getMessage());
    return;
  }

  final String trimmedDesc = descrWriter.toString().trim();
  final String[] descLines = StringUtil.splitByLines(trimmedDesc);
  if (descLines.length > 0) {
    for (String descLine : descLines) {
      w.append("  ").append(descLine.trim()).append("\n");
    }
  }
}
 
Example 5
Source File: ExecutionHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addMessages(final int messageCategory,
                                @Nonnull final List<? extends Exception> exceptions,
                                @Nonnull ErrorViewPanel errorTreeView,
                                @Nullable final VirtualFile file,
                                @Nonnull final String defaultMessage) {
  for (final Exception exception : exceptions) {
    String[] messages = StringUtil.splitByLines(exception.getMessage());
    if (messages.length == 0) {
      messages = new String[]{defaultMessage};
    }
    errorTreeView.addMessage(messageCategory, messages, file, -1, -1, null);
  }
}
 
Example 6
Source File: AccessibleContextUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Given a multi-line string, return an single line string where new line separators
 * are replaced with a punctuation character. This is useful for returning text to
 * screen readers, as they tend to ignore new line separators during speech, but
 * they do pause at punctuation characters.
 */
public static @Nonnull
String replaceLineSeparatorsWithPunctuation(@Nullable String text) {
  if (StringUtil.isEmpty(text))
    return "";

  // Split by new line, removing empty lines and white-spaces at end of lines.
  String[] lines = StringUtil.splitByLines(text);

  // Join lines, ensuring each line end with a punctuation.
  final StringBuilder result = new StringBuilder();
  boolean first = true;
  for (String line : lines) {
    line = line.trim();
    if (!StringUtil.isEmpty(line)) {
      if (first)
        first = false;
      else
        result.append(PUNCTUATION_SEPARATOR);
      result.append(line);
      if (!line.endsWith(PUNCTUATION_CHARACTER)) {
        result.append(PUNCTUATION_CHARACTER);
      }
    }
  }
  return result.toString();
}
 
Example 7
Source File: UnityTestStatePostHandler.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public JsonResponse handle(@Nonnull UnityTestStatePostRequest request)
{
	UUID uuid = UUID.fromString(request.uuid);
	Unity3dTestSession session = Unity3dTestSessionManager.getInstance().findSession(uuid);
	if(session == null)
	{
		return JsonResponse.asError("no session");
	}

	GeneralTestEventsProcessor processor = session.getProcessor();
	ProcessHandler processHandler = session.getProcessHandler();

	String name = request.name;
	switch(request.type)
	{
		case TestStarted:
			processor.onTestStarted(new TestStartedEvent(name, null));
			break;
		case TestIgnored:
			processor.onTestIgnored(new TestIgnoredEvent(name, StringUtil.notNullize(request.message), request.stackTrace));
			break;
		case TestFailed:
			processor.onTestFailure(new TestFailedEvent(name, StringUtil.notNullize(request.message), request.stackTrace, false, null, null));
			break;
		case TestOutput:
			boolean stdOut = "Log".equals(request.messageType) || "Warning".equals(request.messageType);
			StringBuilder builder = new StringBuilder(request.message);
			if(!stdOut)
			{
				builder.append("\n");
				String[] strings = StringUtil.splitByLines(request.stackTrace);
				for(String line : strings)
				{
					builder.append("  at ").append(line).append("\n");
				}
			}
			processor.onTestOutput(new TestOutputEvent(name, builder.toString(), stdOut));
			break;
		case TestFinished:
			long time = (long) (request.time * 1000L);
			processor.onTestFinished(new TestFinishedEvent(name, time));
			break;
		case SuiteStarted:
			processor.onSuiteStarted(new TestSuiteStartedEvent(name, null));
			break;
		case SuiteFinished:
			processor.onSuiteFinished(new TestSuiteFinishedEvent(name));
			break;
		case RunFinished:
			processor.onFinishTesting();
			processHandler.destroyProcess();
			break;
	}

	return JsonResponse.asSuccess(null);
}
 
Example 8
Source File: GhcMod.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
@Nullable
public static String[] simpleExecToLines(@NotNull Module module, @NotNull String workingDirectory,
                                         @NotNull String ghcModFlags, @NotNull String command, String... params) {
    final String result = simpleExec(module, workingDirectory, ghcModFlags, command, params);
    return result == null ? null : StringUtil.splitByLines(result);
}
 
Example 9
Source File: GhcModi.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
/**
 * Same as simpleExec, except returns an array of Strings for each line in the output.
 */
@Nullable
public String[] simpleExecToLines(@NotNull String command) throws GhcModiError {
    final String result = simpleExec(command);
    return result == null ? null : StringUtil.splitByLines(result);
}
 
Example 10
Source File: SMTRunnerConsoleProperties.java    From consulo with Apache License 2.0 4 votes vote down vote up
@javax.annotation.Nullable
@Override
public Navigatable getErrorNavigatable(@Nonnull final Project project, final @Nonnull String stacktrace) {
  if (myCustomFilter.isEmpty()) {
    return null;
  }

  // iterate stacktrace lines find first navigatable line using
  // stacktrace filters
  final int stacktraceLength = stacktrace.length();
  final String[] lines = StringUtil.splitByLines(stacktrace);
  for (String line : lines) {
    Filter.Result result;
    try {
      result = myCustomFilter.applyFilter(line, stacktraceLength);
    }
    catch (Throwable t) {
      throw new RuntimeException("Error while applying " + myCustomFilter + " to '" + line + "'", t);
    }
    final HyperlinkInfo info = result != null ? result.getFirstHyperlinkInfo() : null;
    if (info != null) {

      // covers 99% use existing cases
      if (info instanceof FileHyperlinkInfo) {
        return ((FileHyperlinkInfo)info).getDescriptor();
      }

      // otherwise
      return new Navigatable() {
        @Override
        public void navigate(boolean requestFocus) {
          info.navigate(project);
        }

        @Override
        public boolean canNavigate() {
          return true;
        }

        @Override
        public boolean canNavigateToSource() {
          return true;
        }
      };
    }
  }
  return null;
}