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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#toLowerCase() . 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: LookupImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static String getCaseCorrectedLookupString(LookupElement item, PrefixMatcher prefixMatcher, String prefix) {
  String lookupString = item.getLookupString();
  if (item.isCaseSensitive()) {
    return lookupString;
  }

  final int length = prefix.length();
  if (length == 0 || !prefixMatcher.prefixMatches(prefix)) return lookupString;
  boolean isAllLower = true;
  boolean isAllUpper = true;
  boolean sameCase = true;
  for (int i = 0; i < length && (isAllLower || isAllUpper || sameCase); i++) {
    final char c = prefix.charAt(i);
    boolean isLower = Character.isLowerCase(c);
    boolean isUpper = Character.isUpperCase(c);
    // do not take this kind of symbols into account ('_', '@', etc.)
    if (!isLower && !isUpper) continue;
    isAllLower = isAllLower && isLower;
    isAllUpper = isAllUpper && isUpper;
    sameCase = sameCase && i < lookupString.length() && isLower == Character.isLowerCase(lookupString.charAt(i));
  }
  if (sameCase) return lookupString;
  if (isAllLower) return StringUtil.toLowerCase(lookupString);
  if (isAllUpper) return StringUtil.toUpperCase(lookupString);
  return lookupString;
}
 
Example 2
Source File: CommonsImagingImageReaderSpi.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CommonsImagingImageReaderSpi() {
  super();
  vendorName = "consulo.io";
  version = "1.0";

  // todo standard GIF/BMP formats can be optionally skipped as well
  // JPEG is skipped due to Exception: cannot read or write JPEG images. (JpegImageParser.java:92)
  // tiff reader seems to be broken
  // PNG reader has bugs with well-compressed PNG images, use standard one instead
  myFormats = new ArrayList<>(Arrays.asList(ImageFormats.values()));
  myFormats.removeAll(Arrays.asList(ImageFormats.UNKNOWN, ImageFormats.JPEG, ImageFormats.TIFF, ImageFormats.PNG));

  names = new String[myFormats.size() * 2];
  suffixes = new String[myFormats.size()];
  MIMETypes = new String[myFormats.size()];
  pluginClassName = MyImageReader.class.getName();
  inputTypes = new Class[]{ImageInputStream.class};
  for (int i = 0, allFormatsLength = myFormats.size(); i < allFormatsLength; i++) {
    final ImageFormat format = myFormats.get(i);
    names[2 * i] = StringUtil.toLowerCase(format.getExtension());
    names[2 * i + 1] = StringUtil.toLowerCase(format.getExtension());
    suffixes[i] = names[2 * i];
    MIMETypes[i] = "image/" + names[2 * i];
  }
}
 
Example 3
Source File: TypoTolerantMatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a matcher by a given pattern.
 *
 * @param pattern        the pattern
 * @param options        case sensitivity settings
 * @param hardSeparators A string of characters (empty by default). Lowercase humps don't work for parts separated by any of these characters.
 *                       Need either an explicit uppercase letter or the same separator character in prefix
 */
TypoTolerantMatcher(@Nonnull String pattern, @Nonnull NameUtil.MatchingCaseSensitivity options, @Nonnull String hardSeparators) {
  myOptions = options;
  myPattern = StringUtil.trimEnd(pattern, "* ").toCharArray();
  myHardSeparators = hardSeparators;
  isLowerCase = new boolean[myPattern.length];
  isUpperCase = new boolean[myPattern.length];
  isWordSeparator = new boolean[myPattern.length];
  toUpperCase = new char[myPattern.length];
  toLowerCase = new char[myPattern.length];
  StringBuilder meaningful = new StringBuilder();
  for (int k = 0; k < myPattern.length; k++) {
    char c = myPattern[k];
    isLowerCase[k] = Character.isLowerCase(c);
    isUpperCase[k] = Character.isUpperCase(c);
    isWordSeparator[k] = isWordSeparator(c);
    toUpperCase[k] = StringUtil.toUpperCase(c);
    toLowerCase[k] = StringUtil.toLowerCase(c);
    if (!isWildcard(k)) {
      meaningful.append(toLowerCase[k]);
      meaningful.append(toUpperCase[k]);
    }
  }
  int i = 0;
  while (isWildcard(i)) i++;
  myHasHumps = hasFlag(i + 1, isUpperCase) && hasFlag(i, isLowerCase);
  myHasSeparators = hasFlag(i, isWordSeparator);
  myHasDots = hasDots(i);
  myMeaningfulCharacters = meaningful.toString().toCharArray();
  myMinNameLength = myMeaningfulCharacters.length / 2;
}
 
Example 4
Source File: MinusculeMatcherImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a matcher by a given pattern.
 *
 * @param pattern        the pattern
 * @param options        case sensitivity settings
 * @param hardSeparators A string of characters (empty by default). Lowercase humps don't work for parts separated by any of these characters.
 *                       Need either an explicit uppercase letter or the same separator character in prefix
 */
MinusculeMatcherImpl(@Nonnull String pattern, @Nonnull NameUtil.MatchingCaseSensitivity options, @Nonnull String hardSeparators) {
  myOptions = options;
  myPattern = StringUtil.trimEnd(pattern, "* ").toCharArray();
  myHardSeparators = hardSeparators;
  isLowerCase = new boolean[myPattern.length];
  isUpperCase = new boolean[myPattern.length];
  isWordSeparator = new boolean[myPattern.length];
  toUpperCase = new char[myPattern.length];
  toLowerCase = new char[myPattern.length];
  StringBuilder meaningful = new StringBuilder();
  for (int k = 0; k < myPattern.length; k++) {
    char c = myPattern[k];
    isLowerCase[k] = Character.isLowerCase(c);
    isUpperCase[k] = Character.isUpperCase(c);
    isWordSeparator[k] = isWordSeparator(c);
    toUpperCase[k] = StringUtil.toUpperCase(c);
    toLowerCase[k] = StringUtil.toLowerCase(c);
    if (!isWildcard(k)) {
      meaningful.append(toLowerCase[k]);
      meaningful.append(toUpperCase[k]);
    }
  }
  int i = 0;
  while (isWildcard(i)) i++;
  myHasHumps = hasFlag(i + 1, isUpperCase) && hasFlag(i, isLowerCase);
  myHasSeparators = hasFlag(i, isWordSeparator);
  myHasDots = hasDots(i);
  myMeaningfulCharacters = meaningful.toString().toCharArray();
  myMinNameLength = myMeaningfulCharacters.length / 2;
}
 
Example 5
Source File: StringSearcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private char normalizedCharAt(@Nonnull CharSequence text, @Nullable char[] textArray, int index) {
  char lastChar = textArray != null ? textArray[index] : text.charAt(index);
  if (myCaseSensitive) {
    return lastChar;
  }
  return myLowecaseTransform ? StringUtil.toLowerCase(lastChar) : StringUtil.toUpperCase(lastChar);
}
 
Example 6
Source File: StubProvidedIndexExtension.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public DataExternalizer<SerializedStubTree> createValueExternalizer() {
  File path = getIndexPath();
  SerializationManagerImpl manager = new SerializationManagerImpl(new File(new File(path, StringUtil.toLowerCase(StubUpdatingIndex.INDEX_ID.getName())), "rep.names"), true);
  Disposer.register(ApplicationManager.getApplication(), manager);
  return new SerializedStubTreeDataExternalizer(false, manager);
}
 
Example 7
Source File: StubProvidedIndexExtension.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public <K> ProvidedIndexExtension<K, Void> findProvidedStubIndex(@Nonnull StubIndexExtension<K, ?> extension) {
  String name = extension.getKey().getName();
  File path = getIndexPath();

  File indexPath = new File(path, StringUtil.toLowerCase(name));
  if (!indexPath.exists()) return null;

  return new ProvidedIndexExtension<K, Void>() {
    @Nonnull
    @Override
    public File getIndexPath() {
      return myIndexFile;
    }

    @Nonnull
    @Override
    public ID<K, Void> getIndexId() {
      return (ID)extension.getKey();
    }

    @Nonnull
    @Override
    public KeyDescriptor<K> createKeyDescriptor() {
      return extension.getKeyDescriptor();
    }

    @Nonnull
    @Override
    public DataExternalizer<Void> createValueExternalizer() {
      return VoidDataExternalizer.INSTANCE;
    }
  };
}
 
Example 8
Source File: ExtensionFileNameMatcher.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ExtensionFileNameMatcher(@Nonnull @NonNls String extension) {
  myExtension = StringUtil.toLowerCase(extension);
  myDotExtension = "." + myExtension;
}
 
Example 9
Source File: NameUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String compoundSuggestion(@Nonnull String prefix, boolean upperCaseStyle, @Nonnull String[] words, int wordCount, @Nonnull String startWord, char c, boolean isArray, boolean skip_) {
  StringBuilder buffer = new StringBuilder();

  buffer.append(prefix);

  if (upperCaseStyle) {
    startWord = StringUtil.toUpperCase(startWord);
  }
  else {
    if (prefix.isEmpty() || StringUtil.endsWithChar(prefix, '_')) {
      startWord = StringUtil.toLowerCase(startWord);
    }
    else {
      startWord = Character.toUpperCase(c) + startWord.substring(1);
    }
  }
  buffer.append(startWord);

  for (int i = words.length - wordCount + 1; i < words.length; i++) {
    String word = words[i];
    String prevWord = words[i - 1];
    if (upperCaseStyle) {
      word = StringUtil.toUpperCase(word);
      if (prevWord.charAt(prevWord.length() - 1) != '_' && word.charAt(0) != '_') {
        word = "_" + word;
      }
    }
    else {
      if (prevWord.charAt(prevWord.length() - 1) == '_') {
        word = StringUtil.toLowerCase(word);
      }

      if (skip_) {
        if (word.equals("_")) continue;
        if (prevWord.equals("_")) {
          word = StringUtil.capitalize(word);
        }
      }
    }
    buffer.append(word);
  }

  String suggestion = buffer.toString();
  if (isArray) {
    suggestion = StringUtil.pluralize(suggestion);
    if (upperCaseStyle) {
      suggestion = StringUtil.toUpperCase(suggestion);
    }
  }
  return suggestion;
}
 
Example 10
Source File: ChangesBrowserFileNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ChangesBrowserFileNode(Project project, @Nonnull VirtualFile userObject) {
  super(userObject);
  myName = StringUtil.toLowerCase(userObject.getName());
  myProject = project;
}
 
Example 11
Source File: TrafficLightRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public AnalyzerStatus getStatus(@Nonnull Editor editor) {
  if (PowerSaveMode.isEnabled()) {
    return new AnalyzerStatus(AllIcons.General.InspectionsPowerSaveMode, "Code analysis is disabled in power save mode", "", () -> createUIController(editor));
  }
  else {
    DaemonCodeAnalyzerStatus status = getDaemonCodeAnalyzerStatus(mySeverityRegistrar);
    List<StatusItem> statusItems = new ArrayList<>();
    Icon mainIcon = null;

    String title = "";
    String details = "";
    boolean isDumb = DumbService.isDumb(myProject);
    if (status.errorAnalyzingFinished) {
      if (isDumb) {
        title = DaemonBundle.message("shallow.analysis.completed");
        details = DaemonBundle.message("shallow.analysis.completed.details");
      }
    }
    else {
      title = DaemonBundle.message("performing.code.analysis");
    }

    int[] errorCount = status.errorCount;
    for (int i = errorCount.length - 1; i >= 0; i--) {
      int count = errorCount[i];
      if (count > 0) {
        HighlightSeverity severity = mySeverityRegistrar.getSeverityByIndex(i);
        String name = StringUtil.toLowerCase(severity.getName());
        if (count > 1) {
          name = StringUtil.pluralize(name);
        }

        Icon icon = mySeverityRegistrar.getRendererIconByIndex(i);
        statusItems.add(new StatusItem(Integer.toString(count), icon, name));

        if (mainIcon == null) {
          mainIcon = icon;
        }
      }
    }

    if (!statusItems.isEmpty()) {
      if (mainIcon == null) {
        mainIcon = AllIcons.General.InspectionsOK;
      }
      AnalyzerStatus result = new AnalyzerStatus(mainIcon, title, "", () -> createUIController(editor)).
              withNavigation().
              withExpandedStatus(statusItems);

      //noinspection ConstantConditions
      return status.errorAnalyzingFinished ? result : result.withAnalyzingType(AnalyzingType.PARTIAL).
              withPasses(ContainerUtil.map(status.passes, p -> new PassWrapper(p.getPresentableName(), p.getProgress(), p.isFinished())));
    }
    if (StringUtil.isNotEmpty(status.reasonWhyDisabled)) {
      return new AnalyzerStatus(AllIcons.General.InspectionsTrafficOff, DaemonBundle.message("no.analysis.performed"), status.reasonWhyDisabled, () -> createUIController(editor))
              .withTextStatus(DaemonBundle.message("iw.status.off"));
    }
    if (StringUtil.isNotEmpty(status.reasonWhySuspended)) {
      return new AnalyzerStatus(AllIcons.General.InspectionsPause, DaemonBundle.message("analysis.suspended"), status.reasonWhySuspended, () -> createUIController(editor)).
              withTextStatus(status.heavyProcessType != null ? status.heavyProcessType.toString() : DaemonBundle.message("iw.status.paused"));
    }
    if (status.errorAnalyzingFinished) {
      return isDumb
             ? new AnalyzerStatus(AllIcons.General.InspectionsPause, title, details, () -> createUIController(editor)).
              withTextStatus(DaemonBundle.message("heavyProcess.type.indexing"))
             : new AnalyzerStatus(AllIcons.General.InspectionsOK, DaemonBundle.message("no.errors.or.warnings.found"), details, () -> createUIController(editor));
    }

    //noinspection ConstantConditions
    return new AnalyzerStatus(AllIcons.General.InspectionsEye, title, details, () -> createUIController(editor)).
            withTextStatus(DaemonBundle.message("iw.status.analyzing")).
            withAnalyzingType(AnalyzingType.EMPTY).
            withPasses(ContainerUtil.map(status.passes, p -> new PassWrapper(p.getPresentableName(), p.getProgress(), p.isFinished())));
  }
}
 
Example 12
Source File: ChooseByNameBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static String patternToLowerCase(@Nonnull String pattern) {
  return StringUtil.toLowerCase(pattern);
}