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

The following examples show how to use com.intellij.util.ObjectUtils#assertNotNull() . 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: MultipleChangeListBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
public MultipleChangeListBrowser(@Nonnull Project project,
                                 @Nonnull List<? extends ChangeList> changeLists,
                                 @Nonnull List<Object> changes,
                                 @javax.annotation.Nullable ChangeList initialListSelection,
                                 boolean capableOfExcludingChanges,
                                 boolean highlightProblems,
                                 @Nullable Runnable rebuildListListener,
                                 @javax.annotation.Nullable Runnable inclusionListener,
                                 boolean unversionedFilesEnabled) {
  super(project, changes, capableOfExcludingChanges, highlightProblems, inclusionListener, ChangesBrowser.MyUseCase.LOCAL_CHANGES, null,
        Object.class);
  myRebuildListListener = rebuildListListener;
  myVcsConfiguration = ObjectUtils.assertNotNull(VcsConfiguration.getInstance(myProject));
  myUnversionedFilesEnabled = unversionedFilesEnabled;

  init();
  setInitialSelection(changeLists, changes, initialListSelection);

  myChangeListChooser = new ChangeListChooser();
  myChangeListChooser.updateLists(changeLists);
  myHeaderPanel.add(myChangeListChooser, BorderLayout.EAST);
  ChangeListManager.getInstance(myProject).addChangeListListener(myChangeListListener);

  setupRebuildListForActions();
  rebuildList();
}
 
Example 2
Source File: EditorTextFieldCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Pair<EditorTextField, EditorEx> createEditor(Project project, @Nullable FileType fileType, boolean inheritFontFromLaF) {
  EditorTextField field = new EditorTextField(new EditorTextFieldRendererDocument(), project, fileType, false, false);
  field.setSupplementary(true);
  field.setFontInheritedFromLAF(inheritFontFromLaF);
  field.addNotify(); // creates editor

  EditorEx editor = (EditorEx)ObjectUtils.assertNotNull(field.getEditor());
  editor.setRendererMode(true);

  editor.setColorsScheme(editor.createBoundColorSchemeDelegate(null));
  editor.getSettings().setCaretRowShown(false);

  editor.getScrollPane().setBorder(null);

  return Pair.create(field, editor);
}
 
Example 3
Source File: RectangleReferencePainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void customizePainter(@Nonnull JComponent component,
                             @Nonnull Collection<VcsRef> references,
                             @Nullable VcsLogRefManager manager,
                             @Nonnull Color background,
                             @Nonnull Color foreground) {
  FontMetrics metrics = component.getFontMetrics(getReferenceFont());
  myHeight = metrics.getHeight() + RectanglePainter.TOP_TEXT_PADDING + RectanglePainter.BOTTOM_TEXT_PADDING;
  myWidth = 2 * PaintParameters.LABEL_PADDING;

  myLabels = ContainerUtil.newArrayList();
  if (manager == null) return;

  List<VcsRef> sorted = ContainerUtil.sorted(references, manager.getLabelsOrderComparator());

  for (Map.Entry<VcsRefType, Collection<VcsRef>> entry : ContainerUtil.groupBy(sorted, VcsRef::getType).entrySet()) {
    VcsRef ref = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(entry.getValue()));
    String text = ref.getName() + (entry.getValue().size() > 1 ? " +" : "");
    myLabels.add(Pair.create(text, entry.getKey().getBackgroundColor()));

    myWidth += myLabelPainter.calculateSize(text, metrics).getWidth() + PaintParameters.LABEL_PADDING;
  }
}
 
Example 4
Source File: AddFileToTfIgnoreAction.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    ourLogger.info("Performing AddFileToTfIgnoreAction for " + myServerFilePath);

    Workspace partialWorkspace = CommandUtils.getPartialWorkspace(myProject, true);
    String filePath = ObjectUtils.assertNotNull(
            TfsFileUtil.translateServerItemToLocalItem(partialWorkspace.getMappings(), myServerFilePath, false));
    File localFile = new File(filePath);
    ourLogger.info("Local file path: " + localFile.getAbsolutePath());

    File tfIgnore = TfIgnoreUtil.findNearestOrRootTfIgnore(partialWorkspace.getMappings(), localFile);
    ourLogger.info(".tfignore location: " + (tfIgnore == null ? "null" : tfIgnore.getAbsolutePath()));

    if (tfIgnore != null) {
        CommandProcessor.getInstance().executeCommand(
                myProject,
                () -> ApplicationManager.getApplication().runWriteAction(() -> {
                    try {
                        TfIgnoreUtil.addToTfIgnore(this, tfIgnore, localFile);
                    } catch (IOException ex) {
                        ourLogger.error(ex);
                    }
                }),
                null,
                null);

        // Usually the TFVC is already in a bad state (i.e. all the changed files are lost) before this action gets
        // called, so we need to refresh the VCS changes afterwards.
        RefreshAction.doRefresh(myProject);
    }
}
 
Example 5
Source File: QuickEditAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public QuickEditHandler invokeImpl(@Nonnull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
  int offset = editor.getCaretModel().getOffset();
  Pair<PsiElement, TextRange> pair = ObjectUtils.assertNotNull(getRangePair(file, editor));

  PsiFile injectedFile = (PsiFile)pair.first;
  QuickEditHandler handler = getHandler(project, injectedFile, editor, file);

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injectedFile);
    if (documentWindow != null) {
      handler.navigate(InjectedLanguageUtil.hostToInjectedUnescaped(documentWindow, offset));
    }
  }
  return handler;
}
 
Example 6
Source File: Jsr223IdeScriptEngineManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private ScriptEngineManager getScriptEngineManager() {
  ScriptEngineManager manager = null;
  try {
    manager = myManagerFuture.get();
  }
  catch (Exception e) {
    LOG.error(e);
  }
  return ObjectUtils.assertNotNull(manager);
}
 
Example 7
Source File: ActionManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void unregisterAction(@Nonnull String actionId, boolean removeFromGroups) {
  synchronized (myLock) {
    if (!myId2Action.containsKey(actionId)) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("action with ID " + actionId + " wasn't registered");
      }
      return;
    }
    AnAction oldValue = myId2Action.remove(actionId);
    myAction2Id.remove(oldValue);
    myId2Index.remove(actionId);

    for (final Map.Entry<PluginId, Collection<String>> entry : myPlugin2Id.entrySet()) {
      Collection<String> pluginActions = entry.getValue();
      pluginActions.remove(actionId);
    }
    if (removeFromGroups) {
      //CustomActionsSchema customActionSchema = ApplicationManager.getApplication().getServiceIfCreated(CustomActionsSchema.class);
      for (String groupId : myId2GroupId.get(actionId)) {
        //if (customActionSchema != null) {
        //  customActionSchema.invalidateCustomizedActionGroup(groupId);
        //}
        DefaultActionGroup group = ObjectUtils.assertNotNull((DefaultActionGroup)getActionOrStub(groupId));
        group.remove(oldValue, actionId);
      }
    }
    if (oldValue instanceof ActionGroup) {
      myId2GroupId.values().remove(actionId);
    }
  }
}
 
Example 8
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static RunContentDescriptor getConsoleView(@Nonnull Project project, @Nonnull VirtualFile file) {
  PsiFile psiFile = ObjectUtils.assertNotNull(PsiManager.getInstance(project).findFile(file));
  WeakReference<RunContentDescriptor> ref = psiFile.getCopyableUserData(DESCRIPTOR_KEY);
  RunContentDescriptor descriptor = ref == null ? null : ref.get();
  if (descriptor == null || descriptor.getExecutionConsole() == null) {
    descriptor = createConsoleView(project, psiFile);
    psiFile.putCopyableUserData(DESCRIPTOR_KEY, new WeakReference<>(descriptor));
  }
  return descriptor;
}
 
Example 9
Source File: TfIgnoreUtil.java    From azure-devops-intellij with MIT License 5 votes vote down vote up
private static void addLineToFile(VirtualFile file, String line) {
    FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
    Document document = ObjectUtils.assertNotNull(fileDocumentManager.getDocument(file));
    CharSequence contents = document.getCharsSequence();
    if (!StringUtil.isEmpty(contents) && !StringUtil.endsWith(contents, "\n")) {
        document.insertString(contents.length(), "\n");
    }
    document.insertString(document.getTextLength(), line);
    fileDocumentManager.saveDocument(document);
}
 
Example 10
Source File: AnnotateDiffViewerAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showAnnotation(@Nonnull UnifiedDiffViewer viewer, @Nonnull Side side, @Nonnull AnnotationData data) {
  if (side != viewer.getMasterSide()) return;
  Project project = ObjectUtils.assertNotNull(viewer.getProject());
  UnifiedUpToDateLineNumberProvider lineNumberProvider = new UnifiedUpToDateLineNumberProvider(viewer, side);
  AnnotateToggleAction.doAnnotate(viewer.getEditor(), project, null, data.annotation, data.vcs, lineNumberProvider);
}
 
Example 11
Source File: ConsoleLog.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(Project project) {
    NotificationListener listener = myNotification.getListener();
    if(listener != null) {
        ConsoleLogConsole console = ObjectUtils.assertNotNull(getProjectComponent(project).getConsole(myNotification));
        JComponent component = console.getConsoleEditor().getContentComponent();
        listener.hyperlinkUpdate(myNotification, IJSwingUtilities.createHyperlinkEvent(myHref, component));
    }
}
 
Example 12
Source File: RunAnythingCompletionGroup.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public String getTitle() {
  return ObjectUtils.assertNotNull(getProvider().getCompletionGroupTitle());
}
 
Example 13
Source File: AnnotateDiffViewerAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showAnnotation(@Nonnull OnesideTextDiffViewer viewer, @Nonnull Side side, @Nonnull AnnotationData data) {
  if (side != viewer.getSide()) return;
  Project project = ObjectUtils.assertNotNull(viewer.getProject());
  AnnotateToggleAction.doAnnotate(viewer.getEditor(), project, null, data.annotation, data.vcs);
}
 
Example 14
Source File: AnnotateDiffViewerAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showAnnotation(@Nonnull ThreesideTextDiffViewerEx viewer, @Nonnull ThreeSide side, @Nonnull AnnotationData data) {
  Project project = ObjectUtils.assertNotNull(viewer.getProject());
  AnnotateToggleAction.doAnnotate(viewer.getEditor(side), project, null, data.annotation, data.vcs);
}
 
Example 15
Source File: FoldingDescriptor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FoldingDescriptor(@Nonnull PsiElement element, @Nonnull TextRange range) {
  this(ObjectUtils.assertNotNull(element.getNode()), range, null);
}
 
Example 16
Source File: RunAnythingUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Project fetchProject(@Nonnull DataContext dataContext) {
  return ObjectUtils.assertNotNull(dataContext.getData(CommonDataKeys.PROJECT));
}
 
Example 17
Source File: CompletionInitializationContext.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Language getPositionLanguage() {
  return ObjectUtils.assertNotNull(myPositionLanguage);
}
 
Example 18
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void selectContent(RunContentDescriptor descriptor) {
  Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  ConsoleViewImpl consoleView = ObjectUtils.assertNotNull((ConsoleViewImpl)descriptor.getExecutionConsole());
  ExecutionManager.getInstance(consoleView.getProject()).getContentManager().toFrontRunContent(executor, descriptor);
}
 
Example 19
Source File: VcsRepositoryManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static VcsRepositoryManager getInstance(@Nonnull Project project) {
  return ObjectUtils.assertNotNull(project.getComponent(VcsRepositoryManager.class));
}
 
Example 20
Source File: UnifiedDiffWriter.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void write(@Nullable Project project,
                         @Nullable String basePath,
                         Collection<FilePatch> patches,
                         Writer writer,
                         final String lineSeparator,
                         @Nonnull final PatchEP[] extensions,
                         final CommitContext commitContext) throws IOException {
  for(FilePatch filePatch: patches) {
    if (!(filePatch instanceof TextFilePatch)) continue;
    TextFilePatch patch = (TextFilePatch)filePatch;
    String path = ObjectUtils.assertNotNull(patch.getBeforeName() == null ? patch.getAfterName() : patch.getBeforeName());
    String pathRelatedToProjectDir =
            project == null ? path : getPathRelatedToDir(ObjectUtils.assertNotNull(project.getBasePath()), basePath, path);
    final Map<String, CharSequence> additionalMap = new HashMap<>();
    for (PatchEP extension : extensions) {
      final CharSequence charSequence = extension.provideContent(pathRelatedToProjectDir, commitContext);
      if (! StringUtil.isEmpty(charSequence)) {
        additionalMap.put(extension.getName(), charSequence);
      }
    }
    writeFileHeading(patch, writer, lineSeparator, additionalMap);
    for(PatchHunk hunk: patch.getHunks()) {
      writeHunkStart(writer, hunk.getStartLineBefore(), hunk.getEndLineBefore(), hunk.getStartLineAfter(), hunk.getEndLineAfter(),
                     lineSeparator);
      for(PatchLine line: hunk.getLines()) {
        char prefixChar = ' ';
        switch (line.getType()) {
          case ADD:
            prefixChar = '+';
            break;
          case REMOVE:
            prefixChar = '-';
            break;
          case CONTEXT:
            prefixChar = ' ';
            break;
        }
        String text = line.getText();
        text = StringUtil.trimEnd(text, "\n");
        writeLine(writer, text, prefixChar);
        if (line.isSuppressNewLine()) {
          writer.write(lineSeparator + NO_NEWLINE_SIGNATURE + lineSeparator);
        }
        else {
          writer.write(lineSeparator);
        }
      }
    }
  }
}