Java Code Examples for com.intellij.openapi.util.Couple#of()

The following examples show how to use com.intellij.openapi.util.Couple#of() . 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: VisualStudioTfvcClient.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
/**
 * @return a pair of stdout and stderr.
 */
static Couple<List<String>> executeClientAndGetOutput(
        @NotNull Path clientPath,
        @Nullable Path workingDirectory,
        @NotNull List<String> arguments) throws IOException, InterruptedException {
    ourLogger.info("Executing VS client: " + clientPath + ", args: " + StringUtils.join(arguments, ','));
    List<String> command = new ArrayList<>(arguments.size() + 1);
    command.add(clientPath.toString());
    command.addAll(arguments);

    Process client = new ProcessBuilder()
            .command(command)
            .directory(workingDirectory == null ? null : workingDirectory.toFile())
            .start();

    List<String> output = readLines(client.getInputStream(), "stdout");
    List<String> errors = readLines(client.getErrorStream(), "stderr");

    int exitCode = client.waitFor();
    ourLogger.info("VS client exit code: " + exitCode);

    return Couple.of(output, errors);
}
 
Example 2
Source File: TreeUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static Couple<ASTNode> findTopmostSiblingParents(ASTNode one, ASTNode two) {
  if (one == two) return Couple.of(null, null);

  LinkedList<ASTNode> oneParents = new LinkedList<>();
  while (one != null) {
    oneParents.add(one);
    one = one.getTreeParent();
  }
  LinkedList<ASTNode> twoParents = new LinkedList<>();
  while (two != null) {
    twoParents.add(two);
    two = two.getTreeParent();
  }

  do {
    one = oneParents.pollLast();
    two = twoParents.pollLast();
  }
  while (one == two && one != null);

  return Couple.of(one, two);
}
 
Example 3
Source File: FormatterImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static Couple<Block> getBlockAtOffset(@Nullable Block parent, @Nonnull Block block, int offset) {
  TextRange textRange = block.getTextRange();
  int startOffset = textRange.getStartOffset();
  int endOffset = textRange.getEndOffset();
  if (startOffset == offset) {
    return Couple.of(parent, block);
  }
  if (startOffset > offset || endOffset < offset || block.isLeaf()) {
    return null;
  }
  for (Block subBlock : block.getSubBlocks()) {
    Couple<Block> result = getBlockAtOffset(block, subBlock, offset);
    if (result != null) {
      return result;
    }
  }
  return null;
}
 
Example 4
Source File: ByWord.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Couple<List<Range>> splitIterable2Side(@Nonnull FairDiffIterable changes, int offset) {
  final List<Range> ranges1 = new ArrayList<>();
  final List<Range> ranges2 = new ArrayList<>();
  for (Range ch : changes.iterateUnchanged()) {
    if (ch.end2 <= offset) {
      ranges1.add(new Range(ch.start1, ch.end1, ch.start2, ch.end2));
    }
    else if (ch.start2 >= offset) {
      ranges2.add(new Range(ch.start1, ch.end1, ch.start2 - offset, ch.end2 - offset));
    }
    else {
      int len2 = offset - ch.start2;
      ranges1.add(new Range(ch.start1, ch.start1 + len2, ch.start2, offset));
      ranges2.add(new Range(ch.start1 + len2, ch.end1, 0, ch.end2 - offset));
    }
  }
  return Couple.of(ranges1, ranges2);
}
 
Example 5
Source File: PluginsAdvertiserDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  PluginAdvertiserPluginModel model = new PluginAdvertiserPluginModel(myDownloadState, myToInstallPlugins);
  model.addTableModelListener(e -> setOKActionEnabled(myDownloadState.values().stream().filter(it -> it).findAny().isPresent()));
  PluginTable pluginTable = new PluginTable(model);

  JPanel rightPanel = new JPanel(new BorderLayout());
  rightPanel.setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor(), 1));
  PluginHeaderPanel headerPanel = new PluginHeaderPanel(null, pluginTable);

  JEditorPane descriptionPanel = new JEditorPane();
  descriptionPanel.setEditorKit(UIUtil.getHTMLEditorKit());
  descriptionPanel.setEditable(false);
  descriptionPanel.addHyperlinkListener(new PluginManagerMain.MyHyperlinkListener());

  JPanel panel = headerPanel.getPanel();
  panel.setBorder(JBUI.Borders.empty(5));
  rightPanel.add(panel, BorderLayout.NORTH);
  rightPanel.add(descriptionPanel, BorderLayout.CENTER);

  pluginTable.getSelectionModel().addListSelectionListener(e -> {
    final int selectedRow = pluginTable.getSelectedRow();
    if (selectedRow != -1) {
      final PluginDescriptor selection = model.getObjectAt(selectedRow);
      if (selection != null) {
        PluginManagerMain.pluginInfoUpdate(selection, null, descriptionPanel, headerPanel, null);
      }
    }
  });

  TableUtil.ensureSelectionExists(pluginTable);
  return Couple.<JComponent>of(ScrollPaneFactory.createScrollPane(pluginTable, true), rightPanel);
}
 
Example 6
Source File: ChangeListWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Couple<String> keyForChange(final Change change) {
  final FilePath beforePath = ChangesUtil.getBeforePath(change);
  final String beforeKey = beforePath == null ? null : beforePath.getPath();
  final FilePath afterPath = ChangesUtil.getAfterPath(change);
  final String afterKey = afterPath == null ? null : afterPath.getPath();
  return Couple.of(beforeKey, afterKey);
}
 
Example 7
Source File: AboutNewDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  JTextArea area = new JTextArea();
  area.setEditable(false);
  area.setText(buildAboutInfo());

  setOKButtonText(CommonBundle.getCloseButtonText());

  JButton okButton = createJButtonForAction(getOKAction());

  JPanel eastPanel = new JPanel(new VerticalFlowLayout());
  eastPanel.add(okButton);

  JButton copyToClipboard = new JButton("Copy to clipboard");
  copyToClipboard.addActionListener(e -> {
    CopyPasteManager.getInstance().setContents(new TextTransferable(area.getText(), area.getText()));

    copyToClipboard.setEnabled(false);

    JobScheduler.getScheduler().schedule(() -> UIUtil.invokeLaterIfNeeded(() -> copyToClipboard.setEnabled(true)), 2, TimeUnit.SECONDS);
  });

  eastPanel.add(copyToClipboard);

  return Couple.of(ScrollPaneFactory.createScrollPane(area, true), eastPanel);
}
 
Example 8
Source File: EditConfigurationsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  RunConfigurable configurable = getConfigurable();
  configurable.createComponent();
  configurable.setWholePanel(rootPanel);
  Splitter splitter = configurable.getSplitter();
  return Couple.of(splitter.getFirstComponent(), splitter.getSecondComponent());
}
 
Example 9
Source File: BaseStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents() {
  reInitWholePanelIfNeeded();

  updateSelectionFromTree();

  return Couple.of(mySplitter.getFirstComponent(), mySplitter.getSecondComponent());
}
 
Example 10
Source File: VcsUserUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static Couple<String> getFirstAndLastName(@Nonnull String name) {
  Matcher matcher = NAME_PATTERN.matcher(name);
  if (matcher.matches()) {
    return Couple.of(matcher.group(1), matcher.group(2));
  }
  return null;
}
 
Example 11
Source File: SuppressionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
public static Couple<String> getBlockPrefixSuffixPair(PsiElement comment) {
  final Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(comment.getLanguage());
  if (commenter != null) {
    final String prefix = commenter.getBlockCommentPrefix();
    final String suffix = commenter.getBlockCommentSuffix();
    if (prefix != null || suffix != null) {
      return Couple.of(StringUtil.notNullize(prefix), StringUtil.notNullize(suffix));
    }
  }
  return null;
}
 
Example 12
Source File: BaseStructureConfigurableNoDaemon.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents() {
  reInitWholePanelIfNeeded();

  updateSelectionFromTree();

  return Couple.of(mySplitter.getFirstComponent(), mySplitter.getSecondComponent());
}
 
Example 13
Source File: ByWord.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Couple<FairDiffIterable> comparePunctuation2Side(@Nonnull CharSequence text1,
                                                                @Nonnull CharSequence text21,
                                                                @Nonnull CharSequence text22,
                                                                @Nonnull ProgressIndicator indicator) {
  CharSequence text2 = new MergingCharSequence(text21, text22);
  FairDiffIterable changes = ByChar.comparePunctuation(text1, text2, indicator);

  Couple<List<Range>> ranges = splitIterable2Side(changes, text21.length());

  FairDiffIterable iterable1 = fair(createUnchanged(ranges.first, text1.length(), text21.length()));
  FairDiffIterable iterable2 = fair(createUnchanged(ranges.second, text1.length(), text22.length()));
  return Couple.of(iterable1, iterable2);
}
 
Example 14
Source File: LambdaBlockStatementCanReplacedByExpressionInspection.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
private Couple<PsiElement> getRemovingInfo(CSharpLambdaExpressionImpl expression)
{
	CSharpCodeBodyProxy codeBlock = expression.getCodeBlock();

	PsiElement element = codeBlock.getElement();

	if(element instanceof CSharpBlockStatementImpl)
	{
		DotNetStatement[] statements = ((CSharpBlockStatementImpl) element).getStatements();

		if(statements.length == 1)
		{
			DotNetStatement statement = statements[0];

			if(statement instanceof CSharpReturnStatementImpl)
			{
				DotNetExpression returnExpression = ((CSharpReturnStatementImpl) statement).getExpression();
				if(returnExpression == null)
				{
					return null;
				}

				return Couple.of(element, returnExpression);
			}
			else if(statement instanceof CSharpExpressionStatementImpl)
			{
				DotNetExpression innerExpression = ((CSharpExpressionStatementImpl) statement).getExpression();
				return Couple.of(element, innerExpression);
			}
		}
	}

	return null;
}
 
Example 15
Source File: OperatorEvaluator.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static <P1, P2> void register(Class<P1> p1Class, Class<P2> p2Class, IElementType elementType, PairFunction<P1, P2, Object> function)
{
	Couple<Class> key = Couple.<Class>of(p1Class, p2Class);
	Map<IElementType, PairFunction<Object, Object, Object>> map = ourOperators.get(key);
	if(map == null)
	{
		ourOperators.put(key, map = new HashMap<IElementType, PairFunction<Object, Object, Object>>());
	}
	map.put(elementType, (PairFunction<Object, Object, Object>) function);
}
 
Example 16
Source File: ProtoFoldingBuilder.java    From protobuf-jetbrains-plugin with Apache License 2.0 4 votes vote down vote up
@NotNull
private static Couple<PsiElement> expandLineCommentsRange(@NotNull PsiElement anchor) {
    return Couple.of(findFurthestSiblingOfSameType(anchor, false), findFurthestSiblingOfSameType(anchor, true));
}
 
Example 17
Source File: DFSTBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void strongConnect(@Nonnull List<List<Node>> sccs) {
  int successor = -1;
  nextNode:
  while (!frames.isEmpty()) {
    Frame pair = frames.peek();
    int i = pair.nodeI;

    // we have returned to the node
    if (index[i] == -1) {
      // actually we visit node first time, prepare
      index[i] = dfsIndex;
      lowLink[i] = dfsIndex;
      dfsIndex++;
      nodesOnStack.push(i);
      isOnStack[i] = true;
    }
    if (ArrayUtil.indexOf(pair.out, successor) != -1) {
      lowLink[i] = Math.min(lowLink[i], lowLink[successor]);
    }
    successor = i;

    // if unexplored children left, dfs there
    while (pair.nextUnexploredIndex < pair.out.length) {
      int nextI = pair.out[pair.nextUnexploredIndex++];
      if (index[nextI] == -1) {
        frames.push(new Frame(nextI));
        continue nextNode;
      }
      if (isOnStack[nextI]) {
        lowLink[i] = Math.min(lowLink[i], index[nextI]);

        if (myBackEdge == null) {
          myBackEdge = Couple.of(myAllNodes[nextI], myAllNodes[i]);
        }
      }
    }
    frames.pop();
    topo.add(i);
    // we are really back, pop a scc
    if (lowLink[i] == index[i]) {
      // found yer
      List<Node> scc = new ArrayList<Node>();
      int pushedI;
      do {
        pushedI = nodesOnStack.pop();
        Node pushed = myAllNodes[pushedI];
        isOnStack[pushedI] = false;
        scc.add(pushed);
      }
      while (pushedI != i);
      sccs.add(scc);
    }
  }
}
 
Example 18
Source File: BlockSupportImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * Find ast node that could be reparsed incrementally
 *
 * @return Pair (target reparseable node, new replacement node)
 * or {@code null} if can't parse incrementally.
 */
@Nullable
public static Couple<ASTNode> findReparseableRoots(@Nonnull PsiFileImpl file, @Nonnull FileASTNode oldFileNode, @Nonnull TextRange changedPsiRange, @Nonnull CharSequence newFileText) {
  final FileElement fileElement = (FileElement)oldFileNode;
  final CharTable charTable = fileElement.getCharTable();
  int lengthShift = newFileText.length() - fileElement.getTextLength();

  if (fileElement.getElementType() instanceof ITemplateDataElementType || isTooDeep(file)) {
    // unable to perform incremental reparse for template data in JSP, or in exceptionally deep trees
    return null;
  }

  final ASTNode leafAtStart = fileElement.findLeafElementAt(Math.max(0, changedPsiRange.getStartOffset() - 1));
  final ASTNode leafAtEnd = fileElement.findLeafElementAt(Math.min(changedPsiRange.getEndOffset(), fileElement.getTextLength() - 1));
  ASTNode node = leafAtStart != null && leafAtEnd != null ? TreeUtil.findCommonParent(leafAtStart, leafAtEnd) : fileElement;
  Language baseLanguage = file.getViewProvider().getBaseLanguage();

  while (node != null && !(node instanceof FileElement)) {
    IElementType elementType = node.getElementType();
    if (elementType instanceof IReparseableElementTypeBase || elementType instanceof IReparseableLeafElementType) {
      final TextRange textRange = node.getTextRange();

      if (textRange.getLength() + lengthShift > 0 && (baseLanguage.isKindOf(elementType.getLanguage()) || !TreeUtil.containsOuterLanguageElements(node))) {
        final int start = textRange.getStartOffset();
        final int end = start + textRange.getLength() + lengthShift;
        if (end > newFileText.length()) {
          reportInconsistentLength(file, newFileText, node, start, end);
          break;
        }

        CharSequence newTextStr = newFileText.subSequence(start, end);

        ASTNode newNode;
        if (elementType instanceof IReparseableElementTypeBase) {
          newNode = tryReparseNode((IReparseableElementTypeBase)elementType, node, newTextStr, file.getManager(), baseLanguage, charTable);
        }
        else {
          newNode = tryReparseLeaf((IReparseableLeafElementType)elementType, node, newTextStr);
        }

        if (newNode != null) {
          if (newNode.getTextLength() != newTextStr.length()) {
            String details = ApplicationManager.getApplication().isInternal() ? "text=" + newTextStr + "; treeText=" + newNode.getText() + ";" : "";
            LOG.error("Inconsistent reparse: " + details + " type=" + elementType);
          }

          return Couple.of(node, newNode);
        }
      }
    }
    node = node.getTreeParent();
  }
  return null;
}
 
Example 19
Source File: BreakpointsDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
@Nonnull
@Override
public Couple<JComponent> createSplitterComponents(JPanel rootPanel) {
  return Couple.of(createMasterView(), createDetailView());
}
 
Example 20
Source File: AbstractFilePatchInProgress.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Couple<String> getKey() {
  return Couple.of(myPatch.getBeforeName(), myPatch.getAfterName());
}