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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#parseInt() . 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: 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 2
Source File: BazelVersion.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private static BazelVersion parseVersion(String[] numbers) {
  if (numbers.length < 1) {
    return null;
  }
  int major = StringUtil.parseInt(numbers[0], -1);
  if (major < 0) {
    return null;
  }
  int minor = numbers.length > 1 ? StringUtil.parseInt(numbers[1], 0) : 0;
  int bugfix = numbers.length > 2 ? StringUtil.parseInt(numbers[2], 0) : 0;
  return new BazelVersion(major, minor, bugfix);
}
 
Example 3
Source File: BuiltInServerManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isOnBuiltInWebServerByAuthority(@Nonnull String authority) {
  int portIndex = authority.indexOf(':');
  if (portIndex < 0 || portIndex == authority.length() - 1) {
    return false;
  }

  int port = StringUtil.parseInt(authority.substring(portIndex + 1), -1);
  if (port == -1) {
    return false;
  }

  BuiltInServerOptions options = BuiltInServerOptions.getInstance();
  int idePort = BuiltInServerManager.getInstance().getPort();
  if (options.builtInServerPort != port && idePort != port) {
    return false;
  }

  String host = authority.substring(0, portIndex);
  if (NetUtils.isLocalhost(host)) {
    return true;
  }

  try {
    InetAddress inetAddress = InetAddress.getByName(host);
    return inetAddress.isLoopbackAddress() ||
           inetAddress.isAnyLocalAddress() ||
           (options.builtInServerAvailableExternally && idePort != port && NetworkInterface.getByInetAddress(inetAddress) != null);
  }
  catch (IOException e) {
    return false;
  }
}
 
Example 4
Source File: GotoLineNumberDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
protected final Coordinates getCoordinates() {
  Matcher m = myPattern.matcher(getText());
  if (!m.matches()) return null;

  int l = StringUtil.parseInt(m.group(1), getLine() + 1);
  int c = StringUtil.parseInt(m.group(2), -1);
  return l > 0 ? new Coordinates(l - 1, Math.max(0, c - 1)) : null;
}
 
Example 5
Source File: XQueryPsiImplUtil.java    From intellij-xquery with Apache License 2.0 4 votes vote down vote up
public static int getArity(XQueryNamedFunctionRef functionCall) {
    return StringUtil.parseInt(functionCall.getFunctionArity().getText(), 0);
}
 
Example 6
Source File: FileUrlProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public List<Location> getLocation(@Nonnull String protocol, @Nonnull String path, @Nonnull Project project, @Nonnull GlobalSearchScope scope) {
  if (!URLUtil.FILE_PROTOCOL.equals(protocol)) {
    return Collections.emptyList();
  }

  final String filePath;
  final int lineNumber;
  final int columnNumber;

  int lastColonIndex = path.lastIndexOf(':');
  if (lastColonIndex > 3) {   // on Windows, paths start with /C: and that colon is not a line number separator
    int lastValue = StringUtil.parseInt(path.substring(lastColonIndex + 1), -1);
    int penultimateColonIndex = path.lastIndexOf(':', lastColonIndex - 1);
    if (penultimateColonIndex > 3) {
      int penultimateValue = StringUtil.parseInt(path.substring(penultimateColonIndex + 1, lastColonIndex), -1);
      filePath = path.substring(0, penultimateColonIndex);
      lineNumber = penultimateValue;
      columnNumber = lineNumber <= 0 ? -1 : lastValue;
    }
    else {
      filePath = path.substring(0, lastColonIndex);
      lineNumber = lastValue;
      columnNumber = -1;
    }
  }
  else {
    filePath = path;
    lineNumber = -1;
    columnNumber = -1;
  }
  // Now we should search file with most suitable path
  // here path may be absolute or relative
  final String systemIndependentPath = FileUtil.toSystemIndependentName(filePath);
  final List<VirtualFile> virtualFiles = TestsLocationProviderUtil.findSuitableFilesFor(systemIndependentPath, project);
  if (virtualFiles.isEmpty()) {
    return Collections.emptyList();
  }

  final List<Location> locations = new ArrayList<>(2);
  for (VirtualFile file : virtualFiles) {
    locations.add(createLocationFor(project, file, lineNumber, columnNumber));
  }
  return locations;
}
 
Example 7
Source File: RemoteCredentialsHolder.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Sets string representation of port and its int value, which is equal to string one if it's a valid integer,
 * and is 0 otherwise.
 */
@Override
public void setLiteralPort(String portText){
  myLiteralPort = portText;
  myPort = StringUtil.parseInt(portText, 0);
}
 
Example 8
Source File: Version.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int parseNumber(String num, int def) {
  return StringUtil.parseInt(num.replaceFirst("(\\d+).*", "$1"), def);
}
 
Example 9
Source File: PassExecutorService.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static int getThreadNum() {
  Matcher matcher = Pattern.compile("JobScheduler FJ pool (\\d*)/(\\d*)").matcher(Thread.currentThread().getName());
  String num = matcher.matches() ? matcher.group(1) : null;
  return StringUtil.parseInt(num, 0);
}