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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#pluralize() . 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: ConfigCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Nullable
private LookupElementBuilder getNodeTagLookupElement(Node node, boolean isShortcut) {

    String nodeName = getNodeName(node);
    boolean prototype = isPrototype(node);

    // prototype "connection" must be "connections" so pluralize
    if(prototype) {
        nodeName = StringUtil.pluralize(nodeName);
    }

    LookupElementBuilder lookupElementBuilder = LookupElementBuilder.create(nodeName).withIcon(Symfony2Icons.CONFIG_PROTOTYPE);

    if(prototype) {
        lookupElementBuilder = lookupElementBuilder.withTypeText("Prototype", true);
    }

    if(isShortcut) {
        lookupElementBuilder = lookupElementBuilder.withIcon(Symfony2Icons.CONFIG_VALUE_SHORTCUT);
    }

    return lookupElementBuilder;
}
 
Example 2
Source File: CommitHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
private String reportResult(GeneralCommitProcessor processor) {
  final List<Change> changesFailedToCommit = processor.getChangesFailedToCommit();

  int failed = changesFailedToCommit.size();
  int committed = myIncludedChanges.size() - failed;

  String text = committed + " " + StringUtil.pluralize("file", committed) + " committed";
  if (failed > 0) {
    text += ", " + failed + " " + StringUtil.pluralize("file", failed) + " failed to commit";
  }
  StringBuilder content = new StringBuilder(StringUtil.isEmpty(myCommitMessage) ? text : text + ": " + escape(myCommitMessage));
  for (String s : myFeedback) {
    content.append("\n");
    content.append(s);
  }
  NotificationType notificationType = resolveNotificationType(processor);
  VcsBalloonProblemNotifier.NOTIFICATION_GROUP.createNotification(content.toString(), notificationType).notify(myProject);
  return text;
}
 
Example 3
Source File: ThreesideTextDiffViewerEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private String makeCounterWord(int number, @Nonnull String word) {
  if (number == 0) {
    return "No " + StringUtil.pluralize(word);
  }
  return number + " " + StringUtil.pluralize(word, number);
}
 
Example 4
Source File: ReadOnlyStatusDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String getTheseFilesMessage(Collection<VirtualFile> files) {
  boolean dirsOnly = true;
  for (VirtualFile each : files) {
    if (!each.isDirectory()) {
      dirsOnly = false;
      break;

    }
  }

  int size = files.size();
  return StringUtil.pluralize("this", size) + " " + StringUtil.pluralize((dirsOnly ? "directory" : "file"), size);
}
 
Example 5
Source File: MergePanel2.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String makeCounterWord(int number, @Nonnull String word) {
  if (number == 0) {
    return "No " + StringUtil.pluralize(word);
  }
  return number + " " + StringUtil.pluralize(word, number);
}
 
Example 6
Source File: ProjectLoadingErrorsNotifierImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String getInvalidElementsString(ConfigurationErrorType type, Collection<ConfigurationErrorDescription> descriptions) {
  if (descriptions.size() == 1) {
    final ConfigurationErrorDescription description = ContainerUtil.getFirstItem(descriptions);
    return type.getElementKind() + " <b>" + description.getElementName() + "</b>";
  }

  return descriptions.size() + " " + StringUtil.pluralize(type.getElementKind());
}
 
Example 7
Source File: DetectedRootsChooserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void init(List<SuggestedChildRootInfo> suggestedRoots) {
  myDescription = "<html><body>" + ApplicationNamesInfo.getInstance().getFullProductName() +
                  " just scanned files and detected the following " + StringUtil.pluralize("root", suggestedRoots.size()) + ".<br>" +
                  "Select items in the tree below or press Cancel to cancel operation.</body></html>";
  myTreeTable = createTreeTable(suggestedRoots);
  myPane = ScrollPaneFactory.createScrollPane(myTreeTable);
  setTitle("Detected Roots");
  init();
}
 
Example 8
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 9
Source File: TriggerAdditionOrDeletion.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void notifyAndLogFiles(@Nonnull String topic, @Nonnull List<FilePath> incorrectFilePath) {
  String message = "The following " + StringUtil.pluralize("file", incorrectFilePath.size()) + " may be processed incorrectly by VCS.\n" +
                   "Please check it manually: " + incorrectFilePath;
  LOG.warn(message);
  VcsNotifier.getInstance(myProject).notifyImportantWarning(topic, message);
}
 
Example 10
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 11
Source File: LibraryProjectStructureElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
public RemoveInvalidRootsQuickFix(Library library, OrderRootType type, List<String> invalidUrls) {
  super("Remove invalid " + StringUtil.pluralize("root", invalidUrls.size()));
  myLibrary = library;
  myType = type;
  myInvalidUrls = invalidUrls;
}