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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#defaultIfEmpty() . 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: HaxeLookupElementFactory.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Nullable
public static LookupElementBuilder create(@NotNull HaxeModel model, @Nullable String alias) {
  PsiElement basePsi = model.getBasePsi();
  HaxeNamedComponent namedComponent = getNamedComponent(basePsi);

  if (namedComponent == null) return null;

  String name = StringUtil.defaultIfEmpty(alias, model.getName());
  String presentableText = null;
  String tailText = getParentPath(model);
  Icon icon = null;

  ItemPresentation presentation = namedComponent.getPresentation();
  if (presentation != null) {
    icon = presentation.getIcon(false);
    presentableText = presentation.getPresentableText();
  }

  LookupElementBuilder lookupElement = LookupElementBuilder.create(basePsi, name);

  if (presentableText != null) {
    if (alias != null && presentableText.startsWith(model.getName())) {
      presentableText = presentableText.replace(model.getName(), alias);
    }
    lookupElement = lookupElement.withPresentableText(presentableText);
  }

  if (icon != null) lookupElement = lookupElement.withIcon(icon);

  if (tailText != null) {
    if (alias != null) {
      tailText = HaxeBundle.message("haxe.lookup.alias", tailText + "." + model.getName());
    }
    tailText = " " + tailText;
    lookupElement = lookupElement.withTailText(tailText, true);
  }

  return lookupElement;
}
 
Example 2
Source File: GotoActionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String calcHit(@Nonnull OptionDescription value) {
  //if (value instanceof RegistryTextOptionDescriptor) {
  //  return value.getHit() + " = " + value.getValue();
  //}
  String hit = StringUtil.defaultIfEmpty(value.getHit(), value.getOption());
  return StringUtil.unescapeXmlEntities(StringUtil.notNullize(hit)).replace(BundleBase.MNEMONIC_STRING, "").replace("  ", " "); // avoid extra spaces from mnemonics and xml conversion
}
 
Example 3
Source File: ShowFilePathAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static String getXdgDataDirectories() {
  String dataHome = System.getenv("XDG_DATA_HOME");
  String dataDirs = System.getenv("XDG_DATA_DIRS");
  return StringUtil.defaultIfEmpty(dataHome, SystemProperties.getUserHome() + "/.local/share") + ':' + StringUtil.defaultIfEmpty(dataDirs, "/usr/local/share:/usr/share");
}