private static List<LookupElement> sortByPresentation(
     Iterable<LookupElement> source, Lookup lookup) {
   ArrayList<LookupElement> startMatches = ContainerUtil.newArrayList();
   ArrayList<LookupElement> middleMatches = ContainerUtil.newArrayList();
   for (LookupElement element : source) {
     (CompletionServiceImpl.isStartMatch(element, lookup) ? startMatches : middleMatches)
         .add(element);
   }
   ContainerUtil.sort(startMatches, BY_PRESENTATION_COMPARATOR);
   ContainerUtil.sort(middleMatches, BY_PRESENTATION_COMPARATOR);
   startMatches.addAll(middleMatches);
   return startMatches;
 }
Exemplo n.º 2
0
 private static <E extends ArrangementEntry> void sortByName(@NotNull List<E> entries) {
   if (entries.size() < 2) {
     return;
   }
   final TObjectIntHashMap<E> weights = new TObjectIntHashMap<E>();
   int i = 0;
   for (E e : entries) {
     weights.put(e, ++i);
   }
   ContainerUtil.sort(
       entries,
       new Comparator<E>() {
         @Override
         public int compare(E e1, E e2) {
           String name1 =
               e1 instanceof NameAwareArrangementEntry
                   ? ((NameAwareArrangementEntry) e1).getName()
                   : null;
           String name2 =
               e2 instanceof NameAwareArrangementEntry
                   ? ((NameAwareArrangementEntry) e2).getName()
                   : null;
           if (name1 != null && name2 != null) {
             return name1.compareTo(name2);
           } else if (name1 == null && name2 == null) {
             return weights.get(e1) - weights.get(e2);
           } else if (name2 == null) {
             return -1;
           } else {
             return 1;
           }
         }
       });
 }
Exemplo n.º 3
0
  @NotNull
  @Override
  public Collection<TestMethodModel> getTestMethods() {
    if (testMethods == null) {
      final List<TestMethodModel> result = Lists.newArrayList();

      result.add(new TestAllFilesPresentMethodModel());

      FileUtil.processFilesRecursively(
          rootFile,
          new Processor<File>() {
            @Override
            public boolean process(File file) {
              if (!file.isDirectory() && filenamePattern.matcher(file.getName()).matches()) {
                result.addAll(getTestMethodsFromFile(file));
              }

              return true;
            }
          });

      ContainerUtil.sort(
          result,
          new Comparator<TestMethodModel>() {
            @Override
            public int compare(@NotNull TestMethodModel o1, @NotNull TestMethodModel o2) {
              return StringUtil.compare(o1.getName(), o2.getName(), true);
            }
          });

      testMethods = result;
    }

    return testMethods;
  }
Exemplo n.º 4
0
 @NotNull
 private List<String> createCurrentSeverityNames() {
   List<String> list = new ArrayList<String>();
   list.addAll(STANDARD_SEVERITIES.keySet());
   list.addAll(myMap.keySet());
   ContainerUtil.sort(list);
   return list;
 }
 @Override
 public PsiElement resolveInner() {
   GlobalSearchScope scope = getSearchScope();
   List<ErlangModule> modules =
       ErlangModuleIndex.getModulesByName(myElement.getProject(), myReferenceName, scope);
   if (modules.size() > 1) {
     ContainerUtil.sort(modules, new ModuleResolutionComparator());
   }
   return ContainerUtil.getFirstItem(modules);
 }
 private void sortCommitsByRow(
     @NotNull List<T> result, @NotNull final TIntIntHashMap rowsForCommits) {
   ContainerUtil.sort(
       result,
       (details1, details2) -> {
         int row1 =
             rowsForCommits.get(myHashMap.getCommitIndex(details1.getId(), details1.getRoot()));
         int row2 =
             rowsForCommits.get(myHashMap.getCommitIndex(details2.getId(), details2.getRoot()));
         return Comparing.compare(row1, row2);
       });
 }
Exemplo n.º 7
0
 @NotNull
 private List<HighlightSeverity> getDefaultOrder() {
   Collection<SeverityBasedTextAttributes> values = myMap.values();
   List<HighlightSeverity> order =
       new ArrayList<HighlightSeverity>(STANDARD_SEVERITIES.size() + values.size());
   for (HighlightInfoType type : STANDARD_SEVERITIES.values()) {
     order.add(type.getSeverity(null));
   }
   for (SeverityBasedTextAttributes attributes : values) {
     order.add(attributes.getSeverity());
   }
   ContainerUtil.sort(order);
   return order;
 }
Exemplo n.º 8
0
  private void dumpEditorMarkupAndSelection(PrintStream dumpStream) {
    dumpStream.println(mySearchResults.getFindModel());
    if (myReplacementPreviewText != null) {
      dumpStream.println("--");
      dumpStream.println("Replacement Preview: " + myReplacementPreviewText);
    }
    dumpStream.println("--");

    Editor editor = mySearchResults.getEditor();

    RangeHighlighter[] highlighters = editor.getMarkupModel().getAllHighlighters();
    List<Pair<Integer, Character>> ranges = new ArrayList<Pair<Integer, Character>>();
    for (RangeHighlighter highlighter : highlighters) {
      ranges.add(new Pair<Integer, Character>(highlighter.getStartOffset(), '['));
      ranges.add(new Pair<Integer, Character>(highlighter.getEndOffset(), ']'));
    }

    SelectionModel selectionModel = editor.getSelectionModel();

    if (selectionModel.getSelectionStart() != selectionModel.getSelectionEnd()) {
      ranges.add(new Pair<Integer, Character>(selectionModel.getSelectionStart(), '<'));
      ranges.add(new Pair<Integer, Character>(selectionModel.getSelectionEnd(), '>'));
    }
    ranges.add(new Pair<Integer, Character>(-1, '\n'));
    ranges.add(new Pair<Integer, Character>(editor.getDocument().getTextLength() + 1, '\n'));
    ContainerUtil.sort(
        ranges,
        new Comparator<Pair<Integer, Character>>() {
          @Override
          public int compare(Pair<Integer, Character> pair, Pair<Integer, Character> pair2) {
            int res = pair.first - pair2.first;
            if (res == 0) {

              Character c1 = pair.second;
              Character c2 = pair2.second;
              if (c1 == '<' && c2 == '[') {
                return 1;
              } else if (c1 == '[' && c2 == '<') {
                return -1;
              }
              return c1.compareTo(c2);
            }
            return res;
          }
        });

    Document document = editor.getDocument();
    for (int i = 0; i < ranges.size() - 1; ++i) {
      Pair<Integer, Character> pair = ranges.get(i);
      Pair<Integer, Character> pair1 = ranges.get(i + 1);
      dumpStream.print(
          pair.second
              + document.getText(
                  TextRange.create(
                      Math.max(pair.first, 0), Math.min(pair1.first, document.getTextLength()))));
    }
    dumpStream.println("\n--");

    if (NotFound) {
      dumpStream.println("Not Found");
      dumpStream.println("--");
      NotFound = false;
    }

    for (RangeHighlighter highlighter : highlighters) {
      dumpStream.println(highlighter + " : " + highlighter.getTextAttributes());
    }
    dumpStream.println("------------");
  }