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

The following are Jave code examples for showing how to use getFirst() of the com.intellij.openapi.util.Couple class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: intellij-ce-playground   File: PathMacroTable.java   View Source Code Vote up 6 votes
public void editMacro() {
  if (getSelectedRowCount() != 1) {
    return;
  }
  final int selectedRow = getSelectedRow();
  final Couple<String> pair = myMacros.get(selectedRow);
  final String title = ApplicationBundle.message("title.edit.variable");
  final String macroName = pair.getFirst();
  final PathMacroEditor macroEditor = new PathMacroEditor(title, macroName, pair.getSecond(), new EditValidator());
  if (macroEditor.showAndGet()) {
    myMacros.remove(selectedRow);
    myMacros.add(Couple.of(macroEditor.getName(), macroEditor.getValue()));
    Collections.sort(myMacros, MACRO_COMPARATOR);
    myTableModel.fireTableDataChanged();
  }
}
 
Example 2
Project: intellij-ce-playground   File: KeyCodeTypeCommand.java   View Source Code Vote up 6 votes
public static String unparseKeyCodes(Couple<List<Integer>> pairs) {
  StringBuilder result = new StringBuilder();

  List<Integer> codes = pairs.getFirst();
  List<Integer> modifiers = pairs.getSecond();

  for (int i = 0; i < codes.size(); i++) {
    Integer each = codes.get(i);
    result.append(each.toString());
    result.append(MODIFIER_DELIMITER);
    result.append(modifiers.get(i));
    if (i < codes.size() - 1) {
      result.append(CODE_DELIMITER);
    }
  }

  return result.toString();
}
 
Example 3
Project: intellij-ce-playground   File: PyMoveFileHandler.java   View Source Code Vote up 6 votes
/**
 * Replace import source with leading dots (if any) with reference expression created from given qualified name.
 * Basically it does the same thing as {@link #replaceWithQualifiedExpression}, but also removes leading dots.
 *
 * @param importStatement import statement to update
 * @param qualifiedName   qualified name of new import source
 * @return updated import statement
 * @see #replaceWithQualifiedExpression(com.intellij.psi.PsiElement, com.intellij.psi.util.QualifiedName)
 */
@NotNull
private static PsiElement replaceRelativeImportSourceWithQualifiedExpression(@NotNull PyFromImportStatement importStatement,
                                                                             @Nullable QualifiedName qualifiedName) {
  final Couple<PsiElement> range = getRelativeImportSourceRange(importStatement);
  if (range != null && qualifiedName != null) {
    if (range.getFirst() == range.getSecond()) {
      replaceWithQualifiedExpression(range.getFirst(), qualifiedName);
    }
    else {
      importStatement.deleteChildRange(range.getFirst().getNextSibling(), range.getSecond());
      replaceWithQualifiedExpression(range.getFirst(), qualifiedName);
    }
  }
  return importStatement;
}
 
Example 4
Project: intellij-ce-playground   File: PsiCodeBlockImpl.java   View Source Code Vote up 5 votes
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
  processor.handleEvent(PsiScopeProcessor.Event.SET_DECLARATION_HOLDER, this);
  if (lastParent == null) {
    // Parent element should not see our vars
    return true;
  }
  Couple<Set<String>> pair = buildMaps();
  boolean conflict = pair == null;
  final Set<String> classesSet = conflict ? null : pair.getFirst();
  final Set<String> variablesSet = conflict ? null : pair.getSecond();
  final NameHint hint = processor.getHint(NameHint.KEY);
  if (hint != null && !conflict) {
    final ElementClassHint elementClassHint = processor.getHint(ElementClassHint.KEY);
    final String name = hint.getName(state);
    if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.CLASS)) && classesSet.contains(name)) {
      return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
    if ((elementClassHint == null || elementClassHint.shouldProcess(ElementClassHint.DeclarationKind.VARIABLE)) && variablesSet.contains(name)) {
      return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
    }
  }
  else {
    return PsiScopesUtil.walkChildrenScopes(this, processor, state, lastParent, place);
  }
  return true;
}
 
Example 5
Project: intellij-ce-playground   File: PathMacroTable.java   View Source Code Vote up 5 votes
public Object getValueAt(int rowIndex, int columnIndex) {
  final Couple<String> pair = myMacros.get(rowIndex);
  switch (columnIndex) {
    case NAME_COLUMN: return pair.getFirst();
    case VALUE_COLUMN: return pair.getSecond();
  }
  LOG.error("Wrong indices");
  return null;
}
 
Example 6
Project: intellij-ce-playground   File: FragmentBoundRenderer.java   View Source Code Vote up 5 votes
public void ensureLastX(final int x) {
  if (myPoints.isEmpty() || myPoints.get(myPoints.size() - 1).getFirst() < x) {
    if (myPoints.isEmpty()) {
      myPoints.add(Couple.of(0, 0));
      myPoints.addAll(generateLine(0,0,x,0,myYDiff,0));
    } else {
      final Couple<Integer> lastPoint = myPoints.get(myPoints.size() - 1);
      int finalX = (x - lastPoint.getFirst()) < 5 ? x + 10 : x;
      myPoints.addAll(generateLine(lastPoint.getFirst(),lastPoint.getSecond(),finalX,0,myYDiff,lastPoint.getSecond()));
    }
    //myPoints.set(myPoints.size() - 1, new Pair<Integer, Integer>(x, 0));
  }
}
 
Example 7
Project: intellij-ce-playground   File: KeyChooserDialog.java   View Source Code Vote up 5 votes
/**
 * @return resolved string descriptor. If user chose nothing then the
 * method returns <code>null</code>.
 */
@Nullable StringDescriptor getDescriptor() {
  final int selectedRow = myTable.getSelectedRow();
  if(selectedRow < 0 || selectedRow >= myTable.getRowCount()){
    return null;
  }
  else{
    final Couple<String> pair = myPairs.get(selectedRow);
    final StringDescriptor descriptor = new StringDescriptor(myBundleName, pair.getFirst());
    descriptor.setResolvedValue(pair.getSecond());
    return descriptor;
  }
}
 
Example 8
Project: intellij-ce-playground   File: GitHttpGuiAuthenticator.java   View Source Code Vote up 5 votes
/**
 * Makes the password database key for the URL: inserts the login after the scheme: http://[email protected]
 */
@NotNull
private static String makeKey(@NotNull String url, @Nullable String login) {
  if (login == null) {
    return url;
  }
  Couple<String> pair = UriUtil.splitScheme(url);
  String scheme = pair.getFirst();
  if (!StringUtil.isEmpty(scheme)) {
    return scheme + URLUtil.SCHEME_SEPARATOR + login + "@" + pair.getSecond();
  }
  return login + "@" + url;
}
 
Example 9
Project: intellij-ce-playground   File: GitDeleteRemoteBranchOperation.java   View Source Code Vote up 5 votes
private boolean doDeleteRemote(@NotNull String branchName, @NotNull Collection<GitRepository> repositories) {
  Couple<String> pair = splitNameOfRemoteBranch(branchName);
  String remoteName = pair.getFirst();
  String branch = pair.getSecond();

  GitCompoundResult result = new GitCompoundResult(myProject);
  for (GitRepository repository : repositories) {
    GitCommandResult res;
    GitRemote remote = getRemoteByName(repository, remoteName);
    if (remote == null) {
      String error = "Couldn't find remote by name: " + remoteName;
      LOG.error(error);
      res = GitCommandResult.error(error);
    }
    else {
      res = pushDeletion(repository, remote, branch);
      if (!res.success() && isAlreadyDeletedError(res.getErrorOutputAsJoinedString())) {
        res = myGit.remotePrune(repository, remote);
      }
    }
    result.append(repository, res);
    repository.update();
  }
  if (!result.totalSuccess()) {
    VcsNotifier.getInstance(myProject).notifyError("Failed to delete remote branch " + branchName,
                                                     result.getErrorOutputWithReposIndication());
  }
  return result.totalSuccess();
}
 
Example 10
Project: intellij-ce-playground   File: HgRevisionNumber.java   View Source Code Vote up 5 votes
public HgRevisionNumber(@NotNull String revision,
                        @NotNull String changeset,
                        @NotNull String authorInfo,
                        @NotNull String commitMessage,
                        @NotNull List<HgRevisionNumber> parents) {
  this.commitMessage = commitMessage;
  Couple<String> authorArgs = HgUtil.parseUserNameAndEmail(authorInfo);
  this.author = authorArgs.getFirst();
  this.email = authorArgs.getSecond();
  this.parents = parents;
  this.revision = revision.trim();
  this.changeset = changeset.trim();
  isWorkingVersion = changeset.endsWith("+");
  mySubject = HgBaseLogParser.extractSubject(commitMessage);
}
 
Example 11
Project: intellij-ce-playground   File: InheritorsStatisticalDataSearch.java   View Source Code Vote up 4 votes
/**
 * search for most used inheritors of superClass in scope
 *
 * @param aClass          - class that excluded from inheritors of superClass
 * @param minPercentRatio - head volume
 * @return - search results in relevant ordering (frequency descent)
 */
public static List<InheritorsStatisticsSearchResult> search(final @NotNull PsiClass superClass,
                                        final @NotNull PsiClass aClass,
                                        final @NotNull GlobalSearchScope scope,
                                        final int minPercentRatio) {
  final String superClassName = superClass.getName();
  final String aClassName = aClass.getName();
  final Set<String> disabledNames = new HashSet<String>();
  disabledNames.add(aClassName);
  disabledNames.add(superClassName);
  final Set<InheritorsCountData> collector = new TreeSet<InheritorsCountData>();
  final Couple<Integer> collectingResult = collectInheritorsInfo(superClass, collector, disabledNames);
  final int allAnonymousInheritors = collectingResult.getSecond();
  final int allInheritors = collectingResult.getFirst() + allAnonymousInheritors - 1;

  final List<InheritorsStatisticsSearchResult> result = new ArrayList<InheritorsStatisticsSearchResult>();

  Integer firstPercent = null;
  for (final InheritorsCountData data : collector) {
    final int inheritorsCount = data.getInheritorsCount();
    if (inheritorsCount < allAnonymousInheritors) {
      break;
    }
    final int percent = (inheritorsCount * 100) / allInheritors;
    if (percent < 1) {
      break;
    }
    if (firstPercent == null) {
      firstPercent = percent;
    }
    else if (percent * minPercentRatio < firstPercent) {
      break;
    }

    final PsiClass psiClass = data.getPsiClass();
    final VirtualFile file = psiClass.getContainingFile().getVirtualFile();
    if (file != null && scope.contains(file)) {
      result.add(new InheritorsStatisticsSearchResult(psiClass, percent));
    }
  }
  return result;
}