Java Code Examples for com.intellij.util.ObjectUtils#notNull()

The following examples show how to use com.intellij.util.ObjectUtils#notNull() . 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: ActionStepBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
ActionStepBuilder(@Nonnull DataContext dataContext,
                  boolean showNumbers,
                  boolean useAlphaAsNumbers,
                  boolean showDisabled,
                  boolean honorActionMnemonics,
                  @Nullable String actionPlace,
                  @Nullable PresentationFactory presentationFactory) {
  myUseAlphaAsNumbers = useAlphaAsNumbers;
  if (presentationFactory == null) {
    myPresentationFactory = new PresentationFactory();
  }
  else {
    myPresentationFactory = ObjectUtils.notNull(presentationFactory);
  }
  myListModel = new ArrayList<>();
  myDataContext = dataContext;
  myShowNumbers = showNumbers;
  myShowDisabled = showDisabled;
  myCurrentNumber = 0;
  myPrependWithSeparator = false;
  mySeparatorText = null;
  myHonorActionMnemonics = honorActionMnemonics;
  myActionPlace = ObjectUtils.notNull(actionPlace, ActionPlaces.UNKNOWN);
}
 
Example 2
Source File: JBTextArea.java    From consulo with Apache License 2.0 5 votes vote down vote up
public JBTextArea(Document doc, String text, int rows, int columns) {
  super(doc, text, rows, columns);

  myEmptyText = new TextComponentEmptyText(this) {
    @Override
    protected boolean isStatusVisible() {
      Object function = getClientProperty("StatusVisibleFunction");
      if (function instanceof BooleanFunction) {
        //noinspection unchecked
        return ((BooleanFunction<JTextComponent>)function).fun(JBTextArea.this);
      }
      return super.isStatusVisible();
    }

    @Override
    protected Rectangle getTextComponentBound() {
      Insets insets = ObjectUtils.notNull(getInsets(), JBUI.emptyInsets());
      Insets margin = ObjectUtils.notNull(getMargin(), JBUI.emptyInsets());
      Insets ipad = getComponent().getIpad();
      Dimension size = getSize();
      int left = insets.left + margin.left - ipad.left;
      int top = insets.top + margin.top - ipad.top;
      int right = size.width - (insets.right + margin.right - ipad.right);
      return new Rectangle(left, top, right - left, getRowHeight());
    }
  };

  getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@Nonnull DocumentEvent e) {
      invalidate();
      revalidate();
      repaint();
    }
  });
}
 
Example 3
Source File: EncodingPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected WidgetState getWidgetState(@Nullable VirtualFile file) {
  if (file == null) {
    return WidgetState.HIDDEN;
  }

  Pair<Charset, String> check = EncodingUtil.getCharsetAndTheReasonTooltip(file);
  String failReason = Pair.getSecond(check);
  Charset charset = ObjectUtils.notNull(Pair.getFirst(check), file.getCharset());
  String charsetName = ObjectUtils.notNull(charset.displayName(), "n/a");
  String toolTipText = failReason == null ? "File Encoding: " + charsetName : StringUtil.capitalize(failReason) + ".";
  return new WidgetState(toolTipText, charsetName, failReason == null);
}
 
Example 4
Source File: Jsr223IdeScriptEngineManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public IdeScriptEngine getEngineForFileExtension(@Nonnull final String extension, @Nullable ClassLoader loader) {
  ClassLoader l = ObjectUtils.notNull(loader, AllPluginsLoader.INSTANCE);
  return ClassLoaderUtil.runWithClassLoader(l, new Computable<IdeScriptEngine>() {
    @Override
    public IdeScriptEngine compute() {
      return createIdeScriptEngine(getScriptEngineManager().getEngineByExtension(extension));
    }
  });
}
 
Example 5
Source File: ViewStructureAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static StructureViewModel createStructureViewModel(@Nonnull Project project, @Nonnull FileEditor fileEditor, @Nonnull StructureView structureView) {
  StructureViewModel treeModel;
  VirtualFile virtualFile = fileEditor.getFile();
  if (structureView instanceof StructureViewComposite && virtualFile != null) {
    StructureViewComposite.StructureViewDescriptor[] views = ((StructureViewComposite)structureView).getStructureViews();
    PsiFile psiFile = ObjectUtils.notNull(PsiManager.getInstance(project).findFile(virtualFile));
    treeModel = new StructureViewCompositeModel(psiFile, EditorUtil.getEditorEx(fileEditor), Arrays.asList(views));
    Disposer.register(structureView, treeModel);
  }
  else {
    treeModel = structureView.getTreeModel();
  }
  return treeModel;
}
 
Example 6
Source File: EditorPainter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private TextAttributes getFoldRegionAttributes(FoldRegion foldRegion) {
  TextAttributes selectionAttributes = isSelected(foldRegion) ? myEditor.getSelectionModel().getTextAttributes() : null;
  TextAttributes defaultAttributes = getDefaultAttributes();
  if (myEditor.isInFocusMode(foldRegion)) {
    return ObjectUtils.notNull(myEditor.getUserData(FocusModeModel.FOCUS_MODE_ATTRIBUTES), getDefaultAttributes());
  }
  TextAttributes foldAttributes = myEditor.getFoldingModel().getPlaceholderAttributes();
  return mergeAttributes(mergeAttributes(selectionAttributes, foldAttributes), defaultAttributes);
}
 
Example 7
Source File: DocumentWindowImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public RangeMarker getRangeGuard(int startOffset, int endOffset) {
  ProperTextRange injRange = new ProperTextRange(startOffset, endOffset);
  // include prefixes/suffixes in guarded ranges - they can't be edited
  TextRange editable = ObjectUtils.notNull(intersectWithEditable(injRange), TextRange.EMPTY_RANGE);
  if (!injRange.equals(editable)) {
    ProperTextRange guarded = injRange.cutOut(editable.shiftLeft(editable.getStartOffset() - injRange.getStartOffset()));
    return createRangeMarker(guarded);
  }

  ProperTextRange hostRange = injectedToHost(injRange);
  return myDelegate.getRangeGuard(hostRange.getStartOffset(), hostRange.getEndOffset());
}
 
Example 8
Source File: TfvcIntegrationEnabler.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void enable(@NotNull Collection vcsRoots) {
    // This override does the same as base method, but tries to determine a workspace directory instead of using
    // project.getBaseDir().
    Collection<VcsRoot> typedRoots = (Collection<VcsRoot>)vcsRoots;
    Collection<VirtualFile> existingRoots = typedRoots.stream().filter(root -> {
        AbstractVcs vcs = root.getVcs();
        return vcs != null && vcs.getName().equals(myVcs.getName());
    }).map(VcsRoot::getPath).collect(toList());

    if (!existingRoots.isEmpty()) {
        super.enable(vcsRoots);
        return;
    }

    String basePath = myProject.getBasePath();
    if (basePath == null) {
        ourLogger.warn("Project base path is null");
        return;
    }

    Path workspacePath = determineWorkspaceDirectory(Paths.get(basePath));
    VirtualFile workspaceFile = ObjectUtils.notNull(
            LocalFileSystem.getInstance().findFileByIoFile(workspacePath.toFile()));

    if (initOrNotifyError(workspaceFile))
        addVcsRoot(workspaceFile);
}
 
Example 9
Source File: ConsoleExecutionEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public EditorEx getCurrentEditor() {
  return ObjectUtils.notNull(myCurrentEditor, myConsoleEditor);
}
 
Example 10
Source File: ActionUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static List<AnAction> getActions(@Nonnull JComponent component) {
  return ObjectUtils.notNull(UIUtil.getClientProperty(component, AnAction.ACTIONS_KEY), Collections.emptyList());
}
 
Example 11
Source File: UndoManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return "UndoManager for " + ObjectUtils.notNull(myProject, "application");
}
 
Example 12
Source File: TreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
BuilderFacade(AbstractTreeBuilder builder) {
  super(ObjectUtils.notNull(builder.getTree()));
  myBuilder = builder;
}
 
Example 13
Source File: LRUPopupBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private String[] restoreLRUItems() {
  return ObjectUtils.notNull(myPropertiesComponent.getValues(getLRUKey()), ArrayUtilRt.EMPTY_STRING_ARRAY);
}
 
Example 14
Source File: RefElementImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public synchronized Collection<RefElement> getInReferences() {
  return ObjectUtils.notNull(myInReferences, ContainerUtil.emptyList());
}
 
Example 15
Source File: RefEntityImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public synchronized List<RefEntity> getChildren() {
  return ObjectUtils.notNull(myChildren, ContainerUtil.emptyList());
}
 
Example 16
Source File: AbstractGotoSEContributor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void processScopes(@Nonnull DataContext dataContext, @Nonnull Processor<? super ScopeDescriptor> processor) {
  Project project = ObjectUtils.notNull(dataContext.getData(CommonDataKeys.PROJECT));
  ScopeChooserCombo.processScopes(project, dataContext, ScopeChooserCombo.OPT_LIBRARIES | ScopeChooserCombo.OPT_EMPTY_SCOPES, processor);
}
 
Example 17
Source File: JavaColorSettings.java    From Custom-Syntax-Highlighter with MIT License 4 votes vote down vote up
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
  final Language lang = ObjectUtils.notNull(Language.findLanguageByID("JAVA"), Language.ANY);
  return getSyntaxHighlighterWithFallback(lang);
}
 
Example 18
Source File: RangeMarkerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
RangeMarkerImpl(@Nonnull DocumentEx document, int start, int end, boolean register, boolean forceDocumentStrongReference) {
  this(forceDocumentStrongReference ? document : ObjectUtils.notNull(FileDocumentManager.getInstance().getFile(document), document), document.getTextLength(), start, end, register, false, false);
}
 
Example 19
Source File: EncodingManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setDefaultCharsetName(@Nonnull String name) {
  myDefaultEncoding = name.isEmpty() ? ChooseFileEncodingAction.NO_ENCODING : ObjectUtils.notNull(CharsetToolkit.forName(name), CharsetToolkit.getDefaultSystemCharset());
}
 
Example 20
Source File: JSColorSettings.java    From Custom-Syntax-Highlighter with MIT License 4 votes vote down vote up
@NotNull
@Override
public SyntaxHighlighter getHighlighter() {
  final Language lang = ObjectUtils.notNull(Language.findLanguageByID("JavaScript"), Language.ANY);
  return getSyntaxHighlighterWithFallback(lang);
}