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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#nullize() . 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: WSLDistribution.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @return identification data of WSL distribution.
 */
@Nullable
public String readReleaseInfo() {
  try {
    final String key = "PRETTY_NAME";
    final String releaseInfo = "/etc/os-release"; // available for all distributions
    final ProcessOutput output = executeOnWsl(10000, "cat", releaseInfo);
    if (LOG.isDebugEnabled()) LOG.debug("Reading release info: " + getId());
    if (!output.checkSuccess(LOG)) return null;
    for (String line : output.getStdoutLines(true)) {
      if (line.startsWith(key) && line.length() >= (key.length() + 1)) {
        final String prettyName = line.substring(key.length() + 1);
        return StringUtil.nullize(StringUtil.unquoteString(prettyName));
      }
    }
  }
  catch (ExecutionException e) {
    LOG.warn(e);
  }
  return null;
}
 
Example 2
Source File: PantsTargetReferenceSet.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
public static PartialTargetAddress parse(String value) {
  final int colonIndex = value.indexOf(':');
  final int valueLength = value.length();

  //substringAfter may return empty string if colon is the last character, so null is need in this case
  final String explicitTarget = StringUtil.nullize(StringUtil.substringAfter(value, ":"));
  //substringBefore may return null if colon does not exist, so rawPath is value in this case
  final String rawPath = ObjectUtils.notNull(StringUtil.substringBefore(value, ":"), value);

  String normalizedPath;
  if (rawPath.isEmpty()) {
    normalizedPath = rawPath;
  }
  else {
    final String normalized = PathUtil.toSystemIndependentName(rawPath);
    normalizedPath = normalized.charAt(normalized.length() - 1) == '/' ? normalized : normalized + "/";
  }

  return new PartialTargetAddress(explicitTarget, normalizedPath, valueLength, colonIndex);
}
 
Example 3
Source File: HttpProxySettingsUi.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(@Nonnull HttpConfigurable settings) {
  if (!isValid()) {
    return;
  }

  if (isModified(settings)) {
    settings.AUTHENTICATION_CANCELLED = false;
  }

  settings.USE_PROXY_PAC = myAutoDetectProxyRb.isSelected();
  settings.USE_PAC_URL = myPacUrlCheckBox.isSelected();
  settings.PAC_URL = getText(myPacUrlTextField);
  settings.USE_HTTP_PROXY = myUseHTTPProxyRb.isSelected();
  settings.PROXY_TYPE_IS_SOCKS = mySocks.isSelected();
  settings.PROXY_AUTHENTICATION = myProxyAuthCheckBox.isSelected();
  settings.KEEP_PROXY_PASSWORD = myRememberProxyPasswordCheckBox.isSelected();

  settings.setProxyLogin(getText(myProxyLoginTextField));
  settings.setPlainProxyPassword(new String(myProxyPasswordTextField.getPassword()));
  settings.PROXY_EXCEPTIONS = StringUtil.nullize(myProxyExceptions.getText(), true);

  settings.PROXY_PORT = myProxyPortTextField.getNumber();
  settings.PROXY_HOST = getText(myProxyHostTextField);
}
 
Example 4
Source File: Urls.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Url parseUrl(@Nonnull String url) {
  String urlToParse;
  if (url.startsWith("jar:file://")) {
    urlToParse = url.substring("jar:".length());
  }
  else {
    urlToParse = url;
  }

  Matcher matcher = URI_PATTERN.matcher(urlToParse);
  if (!matcher.matches()) {
    return null;
  }
  String scheme = matcher.group(1);
  if (urlToParse != url) {
    scheme = "jar:" + scheme;
  }

  String authority = StringUtil.nullize(matcher.group(3));

  String path = StringUtil.nullize(matcher.group(4));
  if (path != null) {
    path = FileUtil.toCanonicalUriPath(path);
  }

  if (authority != null && (URLUtil.FILE_PROTOCOL.equals(scheme) || StringUtil.isEmpty(matcher.group(2)))) {
    path = path == null ? authority : (authority + path);
    authority = null;
  }
  return new UrlImpl(scheme, authority, path, matcher.group(5));
}
 
Example 5
Source File: GotoActionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private String getActualPathName(@Nonnull List<? extends ActionGroup> path, @Nonnull DataContext context) {
  String name = "";
  for (ActionGroup group : path) {
    Presentation presentation = updateActionBeforeShow(group, context).getPresentation();
    if (!presentation.isVisible()) return null;
    name = appendGroupName(name, group, presentation);
  }
  return StringUtil.nullize(name);
}
 
Example 6
Source File: ConfigurableWebBrowser.java    From consulo with Apache License 2.0 5 votes vote down vote up
ConfigurableWebBrowser(@Nonnull UUID id, @Nonnull BrowserFamily family, @Nonnull String name, @Nullable String path, boolean active, @Nullable BrowserSpecificSettings specificSettings) {
  this.id = id;
  this.family = family;
  this.name = name;

  this.path = StringUtil.nullize(path);
  this.active = active;
  this.specificSettings = specificSettings;
}
 
Example 7
Source File: PhpInjectFileReferenceIndex.java    From idea-php-advanced-autocomplete with MIT License 5 votes vote down vote up
private static PhpInjectFileReference read(DataInput in) throws IOException {
    boolean isDir = in.readBoolean();
    int argumentIndex = in.readInt();
    PhpInjectFileReference.RelativeMode relativeMode = PhpInjectFileReference.RelativeMode.values()[in.readInt()];
    String prefix = StringUtil.nullize(in.readUTF());
    return isDir
        ? new PhpInjectDirectoryReference(argumentIndex, relativeMode, prefix)
        : new PhpInjectFileReference(argumentIndex, relativeMode, prefix);
}
 
Example 8
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static String getProfileText(@Nonnull VirtualFile file) {
  try {
    VirtualFile folder = file.getParent();
    VirtualFile profileChild = folder == null ? null : folder.findChild(".profile." + file.getExtension());
    return profileChild == null ? null : StringUtil.nullize(VfsUtilCore.loadText(profileChild));
  }
  catch (IOException ignored) {
  }
  return null;
}
 
Example 9
Source File: GotoActionModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private String getPathName(@Nonnull List<? extends ActionGroup> path) {
  String name = "";
  for (ActionGroup group : path) {
    name = appendGroupName(name, group, group.getTemplatePresentation());
  }
  return StringUtil.nullize(name);
}
 
Example 10
Source File: WebServicesConfiguration.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setOAuthKey(WebServiceApi api, String key) {
  key = StringUtil.nullize(key, true);
  if (key == null) {
    myState.oauthKeys.remove(api);
  }
  else {
    myState.oauthKeys.put(api, key);
  }
}
 
Example 11
Source File: HttpProxySettingsUi.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private static String getText(@Nonnull JTextField field) {
  return StringUtil.nullize(field.getText(), true);
}
 
Example 12
Source File: RecentProjectsManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void setLastProjectCreationLocation(@Nullable String lastProjectLocation) {
  myState.lastProjectLocation = StringUtil.nullize(lastProjectLocation, true);
}
 
Example 13
Source File: ChromeSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setCommandLineOptions(@Nullable String value) {
  myCommandLineOptions = StringUtil.nullize(value);
}
 
Example 14
Source File: FirefoxSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setProfile(@Nullable String value) {
  myProfile = StringUtil.nullize(value);
}
 
Example 15
Source File: FirefoxSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FirefoxSettings(@Nullable String profilesIniPath, @Nullable String profile) {
  myProfilesIniPath = StringUtil.nullize(profilesIniPath);
  myProfile = StringUtil.nullize(profile);
}
 
Example 16
Source File: FlutterBazelConfigurationEditorForm.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
private String getTextValue(@NotNull JTextField textField) {
  return StringUtil.nullize(textField.getText().trim(), true);
}
 
Example 17
Source File: DesktopTextBoxImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getValue() {
  return StringUtil.nullize(toAWTComponent().getText());
}
 
Example 18
Source File: FileSelectorWithStoredHistory.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
public String getText() {
  String text = getChildComponent().getText();
  return StringUtil.nullize(text);
}
 
Example 19
Source File: FlutterBazelTestConfigurationEditorForm.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nullable
private String getTextValue(@NotNull String textFieldContents) {
  return StringUtil.nullize(textFieldContents.trim(), true);
}
 
Example 20
Source File: UrlImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public UrlImpl(@Nullable String scheme, @Nullable String authority, @Nullable String path, @Nullable String parameters) {
  this.scheme = scheme;
  this.authority = StringUtil.nullize(authority);
  this.path = StringUtil.isEmpty(path) ? "/" : path;
  this.parameters = StringUtil.nullize(parameters);
}