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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#split() . 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: XQueryUtil.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
public static List<XQueryFile> findXQueryFileByName(Project project, final String filename,
                                                    PsiFile containingFile) {
    final String name = unifyNameFormatAndRemoveProtocol(filename);
    if (isNotAbsolutePath(name)) {
        PsiFile fileFoundRelatively = getFileByRelativePath(project, filename, containingFile);
        if (fileFoundRelatively != null) {
            List<XQueryFile> filteredList = getOnlyXQueryFiles(asList(fileFoundRelatively));
            if (filteredList.size() > 0) {
                return filteredList;
            }
        }
    }
    List<String> splitFilename = StringUtil.split(name, "/");
    String lastPartOfTheFilename = ContainerUtil.iterateAndGetLastItem(splitFilename);
    PsiFile[] filesByName = getFilesByName(project, lastPartOfTheFilename);
    List<PsiFile> filesThatEndWithFullName = getOnlyFilesThatEndWithFullName(name, filesByName);

    return getOnlyXQueryFiles(filesThatEndWithFullName);
}
 
Example 2
Source File: PackageManifestReader.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static ArtifactLocation fromProto(Common.ArtifactLocation location) {
  String relativePath = location.getRelativePath();
  String rootExecutionPathFragment = location.getRootExecutionPathFragment();
  if (!location.getIsNewExternalVersion() && location.getIsExternal()) {
    // fix up incorrect paths created with older aspect version
    // Note: bazel always uses the '/' separator here, even on windows.
    List<String> components = StringUtil.split(relativePath, "/");
    if (components.size() > 2) {
      relativePath = Joiner.on('/').join(components.subList(2, components.size()));
      String prefix = components.get(0) + "/" + components.get(1);
      rootExecutionPathFragment =
          rootExecutionPathFragment.isEmpty() ? prefix : rootExecutionPathFragment + "/" + prefix;
    }
  }
  return ArtifactLocation.builder()
      .setRootExecutionPathFragment(rootExecutionPathFragment)
      .setRelativePath(relativePath)
      .setIsSource(location.getIsSource())
      .setIsExternal(location.getIsExternal())
      .build();
}
 
Example 3
Source File: HLint.java    From intellij-haskforce with Apache License 2.0 6 votes vote down vote up
/**
 * Parse a single problem from the old hlint output if json is not supported.
 */
@Nullable
public static Problem parseProblemFallback(String lint) {
    List<String> split = StringUtil.split(lint, ":");
    if (split.size() < 5) {
        return null;
    }
    int line = StringUtil.parseInt(split.get(1), 0);
    if (line == 0) {
        return null;
    }
    int column = StringUtil.parseInt(split.get(2), 0);
    if (column == 0) {
        return null;
    }
    String hint = StringUtil.split(split.get(4), "\n").get(0);
    split = StringUtil.split(lint, "\n");
    split = ContainerUtil.subList(split, 2);
    split = StringUtil.split(StringUtil.join(split, "\n"), "Why not:");
    if (split.size() != 2) {
        return null;
    }
    final String from = split.get(0).trim();
    final String to = split.get(1).trim();
    return Problem.forFallback("", "", hint, from, to, "", new String[]{}, "", line, column);
}
 
Example 4
Source File: Unity3dProjectImportUtil.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static Version parseVersion(@Nullable String versionString)
{
	if(versionString == null)
	{
		return new Version(0, 0, 0);
	}
	List<String> list = StringUtil.split(versionString, ".");
	if(list.size() >= 3)
	{
		try
		{
			return new Version(Integer.parseInt(list.get(0)), Integer.parseInt(list.get(1)), Integer.parseInt(list.get(2)));
		}
		catch(NumberFormatException ignored)
		{
		}
	}
	return new Version(0, 0, 0);
}
 
Example 5
Source File: OutputToGeneralTestsEventsConverterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doCheckOutptut(String outputStr, String expected, boolean splitByLines) {
  final List<String> lines;
  if (splitByLines) {
    lines = StringUtil.split(outputStr, "\n", false);
  } else {
    lines = Collections.singletonList(outputStr);
  }
  for (String line : lines) {
    myOutputConsumer.process(line, ProcessOutputTypes.STDOUT);
  }
  myOutputConsumer.flushBufferOnProcessTermination(0);

  assertEquals(expected, myEnventsProcessor.getOutput());
}
 
Example 6
Source File: DartVmServiceEvaluator.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NotNull
public static String getPresentableError(@NotNull final String rawError) {
  //Error: Unhandled exception:
  //No top-level getter 'foo' declared.
  //
  //NoSuchMethodError: method not found: 'foo'
  //Receiver: top-level
  //Arguments: [...]
  //#0      NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:176)
  //#1      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:260)
  //#2      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:142)

  //Error: '': error: line 1 pos 9: receiver 'this' is not in scope
  //() => 1+this.foo();
  //        ^
  final List<String> lines = StringUtil.split(StringUtil.convertLineSeparators(rawError), "\n");

  if (!lines.isEmpty()) {
    if ((lines.get(0).equals("Error: Unhandled exception:") || lines.get(0).equals("Unhandled exception:")) && lines.size() > 1) {
      return lines.get(1);
    }
    final Matcher matcher = ERROR_PATTERN.matcher(lines.get(0));
    if (matcher.find()) {
      return matcher.group(1);
    }
  }

  return "Cannot evaluate";
}
 
Example 7
Source File: VfsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static VirtualFile createDirectoryIfMissing(VirtualFile parent, String relativePath) throws IOException {
  for (String each : StringUtil.split(relativePath, "/")) {
    VirtualFile child = parent.findChild(each);
    if (child == null) {
      child = parent.createChildDirectory(LocalFileSystem.getInstance(), each);
    }
    parent = child;
  }
  return parent;
}
 
Example 8
Source File: HLint.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
/**
 * Parse problems from the old hlint output if json is not supported.
 */
@NotNull
public static Problems parseProblemsFallback(String stdout) {
    final List<String> lints = StringUtil.split(stdout, "\n\n");
    Problems problems = new Problems();
    for (String lint : lints) {
        ContainerUtil.addIfNotNull(problems, parseProblemFallback(lint));
    }
    return problems;
}
 
Example 9
Source File: NoteSerializable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public NoteNode deserializeMe(Project project, String ois) throws IOException {
  final List<String> strings = StringUtil.split(ois, "<>", true);
  if (strings.size() == 2) {
    return new NoteNode(StringUtil.unescapeXml(strings.get(0)), Boolean.parseBoolean(strings.get(1)));
  }
  return null;
}
 
Example 10
Source File: FindPopupPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void createFileMaskRegExp(@Nullable String filter) throws PatternSyntaxException {
  if (filter == null) {
    return;
  }
  String pattern;
  final List<String> strings = StringUtil.split(filter, ",");
  if (strings.size() == 1) {
    pattern = PatternUtil.convertToRegex(filter.trim());
  }
  else {
    pattern = StringUtil.join(strings, s -> "(" + PatternUtil.convertToRegex(s.trim()) + ")", "|");
  }
  Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
}
 
Example 11
Source File: DarculaLaf.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected Object parseValue(String key, @Nonnull String value) {
  if (key.endsWith("Insets") || key.endsWith("padding")) {
    final List<String> numbers = StringUtil.split(value, ",");
    return new InsetsUIResource(Integer.parseInt(numbers.get(0)),
                                Integer.parseInt(numbers.get(1)),
                                Integer.parseInt(numbers.get(2)),
                                Integer.parseInt(numbers.get(3)));
  } else if (key.endsWith(".border")) {
    try {
      return Class.forName(value).newInstance();
    } catch (Exception e) {log(e);}
  } else {
    final Color color = parseColor(value);
    final Integer invVal = getInteger(value);
    final Boolean boolVal = "true".equals(value) ? Boolean.TRUE : "false".equals(value) ? Boolean.FALSE : null;
    Icon icon = value.startsWith("AllIcons.") ? IconLoader.getIcon(value) : null;
    if (icon == null && (value.endsWith(".png") || value.endsWith(".svg"))) {
      icon = IconLoader.findIcon(value, getClass(), true);
    }
    if (color != null) {
      return  new ColorUIResource(color);
    } else if (invVal != null) {
      return invVal;
    } else if (icon != null) {
      return new IconUIResource(icon);
    } else if (boolVal != null) {
      return boolVal;
    }
  }
  return value;
}
 
Example 12
Source File: PsiElementCommentSource.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
private String cleanupComment(String text) {
    List<String> lines = StringUtil.split(text, "\n");

    StringBuilder result = new StringBuilder();
    for (String line : lines) {
        String cleanedLine = StringUtil.trimStart(line.substring(1), " ");
        result.append(StringEscapeUtils.escapeHtml(cleanedLine));

        result.append("<br/>");
    }

    return result.toString();
}
 
Example 13
Source File: JetBrainsProtocolHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void processJetBrainsLauncherParameters(String url) {
  System.setProperty(JetBrainsProtocolHandler.class.getName(), url);
  url = url.substring(PROTOCOL.length());
  List<String> urlParts = StringUtil.split(url, "/");
  if (urlParts.size() < 2) {
    System.err.print("Wrong URL: " + PROTOCOL + url);
    return;
  }
  String platformPrefix = urlParts.get(0);
  ourMainParameter = null;
  ourParameters.clear();
  ourCommand = urlParts.get(1);
  if (urlParts.size() > 2) {
    url = url.substring(platformPrefix.length() + 1 + ourCommand.length() + 1);
    List<String> strings = StringUtil.split(url, "?");
    ourMainParameter = strings.get(0);

    if (strings.size() > 1) {
      List<String> keyValues = StringUtil.split(StringUtil.join(ContainerUtil.subList(strings, 1), "?"), "&");
      for (String keyValue : keyValues) {
        if (keyValue.contains("=")) {
          int ind = keyValue.indexOf('=');
          String key = keyValue.substring(0, ind);
          String value = keyValue.substring(ind + 1);
          if (REQUIRED_PLUGINS_KEY.equals(key)) {
            System.setProperty(key, value);
          } else {
            ourParameters.put(key, value);
          }
        } else {
          ourParameters.put(keyValue, "");
        }
      }
    }
  }

  initialized = true;
}
 
Example 14
Source File: LayoutTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public PackagingElementNode<?> findCompositeNodeByPath(String parentPath) {
  PackagingElementNode<?> node = getRootPackagingNode();
  for (String name : StringUtil.split(parentPath, "/")) {
    if (node == null) {
      return null;
    }
    node = node.findCompositeChild(name);
  }
  return node;
}
 
Example 15
Source File: AuthenticationSchemeProperties.java    From teamcity-oauth with Apache License 2.0 4 votes vote down vote up
@Nullable
public List<String> getEmailDomains() {
    return StringUtil.split(getProperty(ConfigKey.emailDomain), " ");
}
 
Example 16
Source File: IconLoader.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isReflectivePath(@Nonnull String path) {
  List<String> paths = StringUtil.split(path, ".");
  return paths.size() > 1 && paths.get(0).endsWith("Icons");
}
 
Example 17
Source File: PlatformTestUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void assertTreeEqualIgnoringNodesOrder(JTree tree, String expected, boolean checkSelected) {
  final Collection<String> actualNodesPresentation = printAsList(tree, checkSelected, null);
  final List<String> expectedNodes = StringUtil.split(expected, "\n");
  UsefulTestCase.assertSameElements(actualNodesPresentation, expectedNodes);
}
 
Example 18
Source File: DaemonTooltipRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected List<String> getProblems(@Nonnull String tooltipText) {
  return StringUtil.split(UIUtil.getHtmlBody(new Html(tooltipText).setKeepFont(true)), UIUtil.BORDER_LINE);
}
 
Example 19
Source File: AWTIconLoaderFacade.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static boolean isReflectivePath(@Nonnull String path) {
  List<String> paths = StringUtil.split(path, ".");
  return paths.size() > 1 && paths.get(0).endsWith("Icons");
}
 
Example 20
Source File: ProcessOutput.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static List<String> splitLines(String s, boolean excludeEmptyLines) {
  String converted = StringUtil.convertLineSeparators(s);
  return StringUtil.split(converted, "\n", true, excludeEmptyLines);
}