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

The following examples show how to use com.intellij.openapi.util.text.StringUtil#notNullize() . 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: OnXAnnotationHandler.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static boolean isOnXParameterAnnotation(HighlightInfo highlightInfo, PsiFile file) {
  final String description = StringUtil.notNullize(highlightInfo.getDescription());
  if (!(ANNOTATION_TYPE_EXPECTED.equals(description)
    || CANNOT_RESOLVE_SYMBOL_UNDERSCORES_MESSAGE.matcher(description).matches()
    || CANNOT_RESOLVE_METHOD_UNDERSCORES_MESSAGE.matcher(description).matches())) {
    return false;
  }

  PsiElement highlightedElement = file.findElementAt(highlightInfo.getStartOffset());

  PsiNameValuePair nameValuePair = findContainingNameValuePair(highlightedElement);
  if (nameValuePair == null || !(nameValuePair.getContext() instanceof PsiAnnotationParameterList)) {
    return false;
  }

  String parameterName = nameValuePair.getName();
  if (null != parameterName && parameterName.contains("_")) {
    parameterName = parameterName.substring(0, parameterName.indexOf('_'));
  }
  if (!ONX_PARAMETERS.contains(parameterName)) {
    return false;
  }

  PsiElement containingAnnotation = nameValuePair.getContext().getContext();
  return containingAnnotation instanceof PsiAnnotation && ONXABLE_ANNOTATIONS.contains(((PsiAnnotation) containingAnnotation).getQualifiedName());
}
 
Example 2
Source File: TextPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
public final void setText(@Nullable String text) {
  text = StringUtil.notNullize(text);
  if (text.equals(myText)) {
    return;
  }

  String oldAccessibleName = null;
  if (accessibleContext != null) {
    oldAccessibleName = accessibleContext.getAccessibleName();
  }

  myText = text;

  if ((accessibleContext != null) && !StringUtil.equals(accessibleContext.getAccessibleName(), oldAccessibleName)) {
    accessibleContext.firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, oldAccessibleName, accessibleContext.getAccessibleName());
  }

  setPreferredSize(getPanelDimensionFromFontMetrics(myText));
  revalidate();
  repaint();
}
 
Example 3
Source File: ScratchFileActions.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
static ScratchFileCreationHelper.Context createContext(@Nonnull AnActionEvent e, @Nonnull Project project) {
  PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
  Editor editor = e.getData(CommonDataKeys.EDITOR);
  if (file == null && editor != null) {
    // see data provider in com.intellij.diff.tools.holders.TextEditorHolder
    file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  }

  ScratchFileCreationHelper.Context context = new ScratchFileCreationHelper.Context();
  context.text = StringUtil.notNullize(getSelectionText(editor));
  if (!context.text.isEmpty()) {
    context.language = getLanguageFromCaret(project, editor, file);
    checkLanguageAndTryToFixText(project, context, e.getDataContext());
  }
  else {
    context.text = StringUtil.notNullize(e.getData(PlatformDataKeys.PREDEFINED_TEXT));
  }
  context.ideView = e.getData(LangDataKeys.IDE_VIEW);
  return context;
}
 
Example 4
Source File: FileReference.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public String decode(@Nonnull String text) {
  if (SystemInfo.isMac) {
    text = Normalizer.normalize(text, Normalizer.Form.NFC);
  }

  // strip http get parameters
  String _text = text;
  int paramIndex = text.lastIndexOf('?');
  if (paramIndex >= 0) {
    _text = text.substring(0, paramIndex);
  }

  if (myFileReferenceSet.isUrlEncoded()) {
    try {
      return StringUtil.notNullize(new URI(_text).getPath(), text);
    }
    catch (Exception ignored) {
      return text;
    }
  }

  return _text;
}
 
Example 5
Source File: WrapEditorAction.java    From idea-latex with MIT License 6 votes vote down vote up
/**
 * Wraps selection.
 *
 * @param editor Current editor.
 */
private void wrap(@NotNull TextEditor editor) {
    final Document document = editor.getEditor().getDocument();
    final SelectionModel selectionModel = editor.getEditor().getSelectionModel();
    final CaretModel caretModel = editor.getEditor().getCaretModel();

    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    final String text = StringUtil.notNullize(selectionModel.getSelectedText());

    String newText = getLeftText() + text + getRightText();
    int newStart = start + getLeftText().length();
    int newEnd = StringUtil.isEmpty(text) ? newStart : end + getLeftText().length();

    document.replaceString(start, end, newText);
    selectionModel.setSelection(newStart, newEnd);
    caretModel.moveToOffset(newEnd);
}
 
Example 6
Source File: DocumentationOrderRootTypeUIFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void onSpecifyUrlButtonClicked() {
  final String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(((SdkType)mySdk.getSdkType()).getDefaultDocumentationUrl(mySdk), "");
  VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myComponent, defaultDocsUrl);
  if (virtualFile != null) {
    addElement(virtualFile);
    setModified(true);
    requestDefaultFocus();
    setSelectedRoots(new Object[]{virtualFile});
  }
}
 
Example 7
Source File: HaskellConidBaseImpl.java    From intellij-haskforce with Apache License 2.0 5 votes vote down vote up
@Override
@NotNull
public String getName() {
  HaskellConidStub stub = getStub();
  if (stub != null) return StringUtil.notNullize(stub.getName());
  return this.getText();
}
 
Example 8
Source File: ListWithFilter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ListWithFilter(@Nonnull JList<T> list, @Nonnull JScrollPane scrollPane, @Nullable Function<? super T, String> namer, boolean highlightAllOccurrences) {
  super(new BorderLayout());

  if (list instanceof ComponentWithEmptyText) {
    ((ComponentWithEmptyText)list).getEmptyText().setText(UIBundle.message("message.noMatchesFound"));
  }

  myList = list;
  myScrollPane = scrollPane;

  mySearchField.getTextEditor().setFocusable(false);
  mySearchField.setVisible(false);

  add(mySearchField, BorderLayout.NORTH);
  add(myScrollPane, BorderLayout.CENTER);

  mySpeedSearch = new MySpeedSearch(highlightAllOccurrences);
  mySpeedSearch.setEnabled(namer != null);

  myList.addKeyListener(mySpeedSearch);
  int selectedIndex = myList.getSelectedIndex();
  int modelSize = myList.getModel().getSize();
  myModel = new NameFilteringListModel<>(myList.getModel(), namer, mySpeedSearch::shouldBeShowing, () -> StringUtil.notNullize(mySpeedSearch.getFilter()));
  myList.setModel(myModel);
  if (myModel.getSize() == modelSize) {
    myList.setSelectedIndex(selectedIndex);
  }

  setBackground(list.getBackground());
  //setFocusable(true);
}
 
Example 9
Source File: GutterIntentionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
boolean isAvailable(@Nonnull DataContext dataContext) {
  if (myText == null) {
    AnActionEvent event = createActionEvent(dataContext);
    myAction.update(event);
    if (event.getPresentation().isEnabled() && event.getPresentation().isVisible()) {
      String text = event.getPresentation().getText();
      myText = text != null ? text : StringUtil.notNullize(myAction.getTemplatePresentation().getText());
    }
    else {
      myText = "";
    }
  }
  return StringUtil.isNotEmpty(myText);
}
 
Example 10
Source File: MergeUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<String> notNullizeContentTitles(@Nonnull List<String> mergeContentTitles) {
  String left = StringUtil.notNullize(ThreeSide.LEFT.select(mergeContentTitles), "Your Version");
  String base = StringUtil.notNullize(ThreeSide.BASE.select(mergeContentTitles), "Base Version");
  String right = StringUtil.notNullize(ThreeSide.RIGHT.select(mergeContentTitles), "Server Version");
  return ContainerUtil.list(left, base, right);
}
 
Example 11
Source File: BookmarkManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void readExternal(Element element) {
  for (final Object o : element.getChildren()) {
    Element bookmarkElement = (Element)o;

    if ("bookmark".equals(bookmarkElement.getName())) {
      String url = bookmarkElement.getAttributeValue("url");
      String line = bookmarkElement.getAttributeValue("line");
      String description = StringUtil.notNullize(bookmarkElement.getAttributeValue("description"));
      String mnemonic = bookmarkElement.getAttributeValue("mnemonic");

      Bookmark b = null;
      VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url);
      if (file != null) {
        if (line != null) {
          try {
            int lineIndex = Integer.parseInt(line);
            b = addTextBookmark(file, lineIndex, description);
          }
          catch (NumberFormatException e) {
            // Ignore. Will miss bookmark if line number cannot be parsed
          }
        }
        else {
          b = addFileBookmark(file, description);
        }
      }

      if (b != null && mnemonic != null && mnemonic.length() == 1) {
        setMnemonic(b, mnemonic.charAt(0));
      }
    }
  }
}
 
Example 12
Source File: TextCompareProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public List<LineFragment> process(@Nullable String text1, @Nullable String text2) throws FilesTooBigForDiffException {
  if (myHighlightMode == HighlightMode.NO_HIGHLIGHTING) {
    return Collections.emptyList();
  }

  text1 = StringUtil.notNullize(text1);
  text2 = StringUtil.notNullize(text2);
  if (text1.isEmpty() || text2.isEmpty()) {
    return new DummyDiffFragmentsProcessor().process(text1, text2);
  }

  DiffString diffText1 = DiffString.create(text1);
  DiffString diffText2 = DiffString.create(text2);

  DiffFragment[] woFormattingBlocks = myDiffPolicy.buildFragments(diffText1, diffText2);
  DiffFragment[] step1lineFragments = new DiffCorrection.TrueLineBlocks(myComparisonPolicy).correctAndNormalize(woFormattingBlocks);
  ArrayList<LineFragment> lineBlocks = new DiffFragmentsProcessor().process(step1lineFragments);

  int badLinesCount = 0;
  if (myHighlightMode == HighlightMode.BY_WORD) {
    for (LineFragment lineBlock : lineBlocks) {
      if (lineBlock.isOneSide() || lineBlock.isEqual()) continue;
      try {
        DiffString subText1 = lineBlock.getText(diffText1, FragmentSide.SIDE1);
        DiffString subText2 = lineBlock.getText(diffText2, FragmentSide.SIDE2);
        ArrayList<LineFragment> subFragments = findSubFragments(subText1, subText2);
        lineBlock.setChildren(new ArrayList<Fragment>(subFragments));
        lineBlock.adjustTypeFromChildrenTypes();
      }
      catch (FilesTooBigForDiffException ignore) {
        // If we can't by-word compare two lines - this is not a reason to break entire diff.
        badLinesCount++;
        if (badLinesCount > FilesTooBigForDiffException.MAX_BAD_LINES) break;
      }
    }
  }
  return lineBlocks;
}
 
Example 13
Source File: EqualsAndHashCodeProcessor.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public LombokPsiElementUsage checkFieldUsage(@NotNull PsiField psiField, @NotNull PsiAnnotation psiAnnotation) {
  final PsiClass containingClass = psiField.getContainingClass();
  if (null != containingClass) {
    final String psiFieldName = StringUtil.notNullize(psiField.getName());
    if (getEqualsAndHashCodeToStringHandler().filterFields(containingClass, psiAnnotation, true, INCLUDE_ANNOTATION_METHOD).stream()
      .map(MemberInfo::getName).anyMatch(psiFieldName::equals)) {
      return LombokPsiElementUsage.READ;
    }
  }
  return LombokPsiElementUsage.NONE;
}
 
Example 14
Source File: ReplacementView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ReplacementView(@Nullable String replacement) {
  String textToShow = StringUtil.notNullize(replacement, MALFORMED_REPLACEMENT_STRING);
  textToShow = StringUtil.escapeXmlEntities(StringUtil.shortenTextWithEllipsis(textToShow, 500, 0, true)).replaceAll("\n+", "\n").replace("\n", "<br>");
  //noinspection HardCodedStringLiteral
  JLabel jLabel = new JBLabel("<html>" + textToShow).setAllowAutoWrapping(true);
  jLabel.setForeground(replacement != null ? new JBColor(Gray._240, Gray._200) : JBColor.RED);
  add(jLabel);
}
 
Example 15
Source File: TemplateState.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String presentTemplate(@Nullable TemplateImpl template) {
  if (template == null) {
    return "no template";
  }

  String message = StringUtil.notNullize(template.getKey());
  message += "\n\nTemplate#string: " + StringUtil.notNullize(template.getString());
  message += "\n\nTemplate#text: " + StringUtil.notNullize(template.getTemplateText());
  return message;
}
 
Example 16
Source File: PlatformBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String arch() {
  return StringUtil.notNullize(System.getProperty("os.arch"));
}
 
Example 17
Source File: SimpleDiffRequestChain.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getName() {
  return StringUtil.notNullize(myRequest.getTitle(), "Change");
}
 
Example 18
Source File: PropertyTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
public GroupProperty(@Nullable String name) {
  super(null, StringUtil.notNullize(name));
}
 
Example 19
Source File: Notification.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Notification setContent(@Nullable String content) {
  myContent = StringUtil.notNullize(content);
  return this;
}
 
Example 20
Source File: DaemonEvent.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@NotNull
String getType() {
  return StringUtil.notNullize(progressId);
}