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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#containsAnyChar() . 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: TypoTolerantMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int findNextPatternCharOccurrence(int startAt, int patternIndex, boolean allowSpecialChars, boolean wordStartsOnly, @Nonnull ErrorState errorState) {
  int next = wordStartsOnly ? indexOfWordStart(patternIndex, startAt, errorState) : indexOfIgnoreCase(startAt + 1, patternIndex, errorState);

  // pattern humps are allowed to match in words separated by " ()", lowercase characters aren't
  if (!allowSpecialChars && !myHasSeparators && !myHasHumps && StringUtil.containsAnyChar(myName, myHardSeparators, startAt, next)) {
    return -1;
  }
  // if the user has typed a dot, don't skip other dots between humps
  // but one pattern dot may match several name dots
  if (!allowSpecialChars && myHasDots && !isPatternChar(patternIndex - 1, '.', errorState) && StringUtil.contains(myName, startAt, next, '.')) {
    return -1;
  }

  return next;
}
 
Example 2
Source File: MinusculeMatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private int checkForSpecialChars(String name, int start, int end, int patternIndex) {
  if (end < 0) return -1;

  // pattern humps are allowed to match in words separated by " ()", lowercase characters aren't
  if (!myHasSeparators && !myHasHumps && StringUtil.containsAnyChar(name, myHardSeparators, start, end)) {
    return -1;
  }
  // if the user has typed a dot, don't skip other dots between humps
  // but one pattern dot may match several name dots
  if (myHasDots && !isPatternChar(patternIndex - 1, '.') && StringUtil.contains(name, start, end, '.')) {
    return -1;
  }
  return end;
}
 
Example 3
Source File: FileNameCache.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void assertShortFileName(@Nonnull String name) {
  if (name.length() <= 1) return;
  int start = 0;
  if (SystemInfo.isWindows && name.startsWith("//")) {  // Windows UNC: //Network/Ubuntu
    final int idx = name.indexOf('/', 2);
    start = idx == -1 ? 2 : idx + 1;
  }
  if (StringUtil.containsAnyChar(name, FS_SEPARATORS, start, name.length())) {
    throw new IllegalArgumentException("Must not intern long path: '" + name + "'");
  }
}
 
Example 4
Source File: CommandLineUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<String> toCommandLine(@Nonnull String command, @Nonnull List<String> parameters, @Nonnull FilePathSeparator filePathSeparator) {
  List<String> commandLine = ContainerUtil.newArrayListWithCapacity(parameters.size() + 1);

  commandLine.add(FileUtilRt.toSystemDependentName(command, filePathSeparator.fileSeparator));

  boolean isWindows = filePathSeparator == FilePathSeparator.WINDOWS;
  boolean winShell = isWindows && isWinShell(command);

  for (String parameter : parameters) {
    if (isWindows) {
      if (parameter.contains("\"")) {
        parameter = StringUtil.replace(parameter, "\"", "\\\"");
      }
      else if (parameter.isEmpty()) {
        parameter = "\"\"";
      }
    }

    if (winShell && StringUtil.containsAnyChar(parameter, WIN_SHELL_SPECIALS)) {
      parameter = quote(parameter, SPECIAL_QUOTE);
    }

    if (isQuoted(parameter, SPECIAL_QUOTE)) {
      parameter = quote(parameter.substring(1, parameter.length() - 1), '"');
    }

    commandLine.add(parameter);
  }

  return commandLine;
}
 
Example 5
Source File: PackageDirectoryCache.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private PackageInfo getPackageInfo(@Nonnull final String packageName) {
  PackageInfo info = myDirectoriesByPackageNameCache.get(packageName);
  if (info == null) {
    if (myNonExistentPackages.contains(packageName)) return null;

    if (packageName.length() > Registry.intValue("java.max.package.name.length") || StringUtil.containsAnyChar(packageName, ";[/")) {
      return null;
    }

    List<VirtualFile> result = ContainerUtil.newSmartList();

    if (StringUtil.isNotEmpty(packageName) && !StringUtil.startsWithChar(packageName, '.')) {
      int i = packageName.lastIndexOf('.');
      while (true) {
        PackageInfo parentInfo = getPackageInfo(i > 0 ? packageName.substring(0, i) : "");
        if (parentInfo != null) {
          result.addAll(parentInfo.getSubPackageDirectories(packageName.substring(i + 1)));
        }
        if (i < 0) break;
        i = packageName.lastIndexOf('.', i - 1);
        ProgressManager.checkCanceled();
      }
    }

    for (VirtualFile file : myRootsByPackagePrefix.get(packageName)) {
      if (file.isDirectory()) {
        result.add(file);
      }
    }

    if (!result.isEmpty()) {
      myDirectoriesByPackageNameCache.put(packageName, info = new PackageInfo(packageName, result));
    } else {
      myNonExistentPackages.add(packageName);
    }
  }

  return info;
}
 
Example 6
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Pair<Point, Short> getBestPointPosition(LightweightHint hint, final PsiElement list, int offset, VisualPosition pos, short preferredPosition) {
  if (list != null) {
    TextRange range = list.getTextRange();
    TextRange rangeWithoutParens = TextRange.from(range.getStartOffset() + 1, Math.max(range.getLength() - 2, 0));
    if (!rangeWithoutParens.contains(offset)) {
      offset = offset < rangeWithoutParens.getStartOffset() ? rangeWithoutParens.getStartOffset() : rangeWithoutParens.getEndOffset();
      pos = null;
    }
  }
  if (previousOffset == offset) return Pair.create(previousBestPoint, previousBestPosition);

  final boolean isMultiline = list != null && StringUtil.containsAnyChar(list.getText(), "\n\r");
  if (pos == null) pos = EditorUtil.inlayAwareOffsetToVisualPosition(myEditor, offset);
  Pair<Point, Short> position;

  if (!isMultiline) {
    position = chooseBestHintPosition(myEditor, pos, hint, preferredPosition, false);
  }
  else {
    Point p = HintManagerImpl.getHintPosition(hint, myEditor, pos, HintManager.ABOVE);
    position = new Pair<>(p, HintManager.ABOVE);
  }
  previousBestPoint = position.getFirst();
  previousBestPosition = position.getSecond();
  previousOffset = offset;
  return position;
}
 
Example 7
Source File: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String filterControlSymbols(@Nonnull String pattern) {
  if (StringUtil.containsAnyChar(pattern, ":,;@[( #") || pattern.contains(" line ") || pattern.contains("?l=")) { // quick test if reg exp should be used
    return applyPatternFilter(pattern, ourPatternToDetectLinesAndColumns);
  }

  return pattern;
}
 
Example 8
Source File: CreateDirectoryOrPackageHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canClose(final String subDirName) {

  if (subDirName.length() == 0) {
    showErrorDialog(IdeBundle.message("error.name.should.be.specified"));
    return false;
  }

  final boolean multiCreation = StringUtil.containsAnyChar(subDirName, myDelimiters);
  if (!multiCreation) {
    try {
      myDirectory.checkCreateSubdirectory(subDirName);
    }
    catch (IncorrectOperationException ex) {
      showErrorDialog(CreateElementActionBase.filterMessage(ex.getMessage()));
      return false;
    }
  }

  final Boolean createFile = suggestCreatingFileInstead(subDirName);
  if (createFile == null) {
    return false;
  }

  doCreateElement(subDirName, createFile);

  return myCreatedElement != null;
}
 
Example 9
Source File: ChooseByNamePopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getTransformedPattern(@Nonnull String pattern, @Nonnull ChooseByNameModel model) {
  String rawPattern = pattern;

  Pattern regex = null;
  if (StringUtil.containsAnyChar(pattern, ":,;@[( #") || pattern.contains(" line ") || pattern.contains("?l=")) { // quick test if reg exp should be used
    regex = patternToDetectLinesAndColumns;
  }

  if (model instanceof GotoClassModel2 || model instanceof GotoSymbolModel2) {
    if (pattern.indexOf('#') != -1) {
      regex = model instanceof GotoClassModel2 ? patternToDetectMembers : patternToDetectSignatures;
    }

    if (pattern.indexOf('$') != -1) {
      regex = patternToDetectAnonymousClasses;
    }
  }

  if (regex != null) {
    final Matcher matcher = regex.matcher(pattern);
    if (matcher.matches()) {
      pattern = matcher.group(1);
    }
  }

  if (rawPattern.endsWith(fullMatchSearchSuffix)) {
    pattern += fullMatchSearchSuffix;
  }

  return pattern;
}
 
Example 10
Source File: FlowRenameDialog.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
protected boolean areButtonsValid() {
    String newName = this.getNewName();
    return !StringUtil.containsAnyChar(newName, "\t ;*'\"\\/,()^&<>={}");
}
 
Example 11
Source File: VcsLogUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean maybeRegexp(@Nonnull String text) {
  return StringUtil.containsAnyChar(text, "()[]{}.*?+^$\\|");
}