Exemple #1
0
  public ASTNode getDefaultAnchor(
      @NotNull PsiImportList list, @NotNull PsiImportStatementBase statement) {
    PsiJavaCodeReferenceElement ref = statement.getImportReference();
    if (ref == null) return null;

    int entryIndex = findEntryIndex(statement);
    PsiImportStatementBase[] allStatements = list.getAllImportStatements();
    int[] entries = ArrayUtil.newIntArray(allStatements.length);
    List<PsiImportStatementBase> statements = new ArrayList<PsiImportStatementBase>();
    for (int i = 0; i < allStatements.length; i++) {
      PsiImportStatementBase statement1 = allStatements[i];
      int entryIndex1 = findEntryIndex(statement1);
      entries[i] = entryIndex1;
      if (entryIndex1 == entryIndex) {
        statements.add(statement1);
      }
    }

    if (statements.isEmpty()) {
      int index;
      for (index = entries.length - 1; index >= 0; index--) {
        if (entries[index] < entryIndex) break;
      }
      index++;
      return index < entries.length
          ? SourceTreeToPsiMap.psiElementToTree(allStatements[index])
          : null;
    } else {
      String refText = ref.getCanonicalText();
      if (statement.isOnDemand()) {
        refText += ".";
      }

      PsiImportStatementBase insertBefore = null;
      PsiImportStatementBase insertAfter = null;
      for (PsiImportStatementBase statement1 : statements) {
        PsiJavaCodeReferenceElement ref1 = statement1.getImportReference();
        if (ref1 == null) {
          continue;
        }
        String refTextThis = ref1.getCanonicalText();
        if (statement1.isOnDemand()) {
          refTextThis += ".";
        }

        int comp = Comparing.compare(refText, refTextThis);
        if (comp < 0 && insertBefore == null) {
          insertBefore = statement1;
        }
        if (comp > 0) {
          insertAfter = statement1;
        }
      }

      if (insertBefore != null) return insertBefore.getNode();
      if (insertAfter != null) return insertAfter.getNode().getTreeNext();
      return null;
    }
  }
 @Override
 public int compare(JavaExecutionStack th1, JavaExecutionStack th2) {
   int res =
       Comparing.compare(
           th2.getThreadProxy().isSuspended(), th1.getThreadProxy().isSuspended());
   if (res == 0) {
     return th1.getDisplayName().compareToIgnoreCase(th2.getDisplayName());
   }
   return res;
 }
 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);
       });
 }
        @Override
        public int compare(UsageNode c1, UsageNode c2) {
          if (c1 instanceof StringNode) return 1;
          if (c2 instanceof StringNode) return -1;
          Usage o1 = c1.getUsage();
          Usage o2 = c2.getUsage();
          if (o1 == MORE_USAGES_SEPARATOR) return 1;
          if (o2 == MORE_USAGES_SEPARATOR) return -1;

          VirtualFile v1 = UsageListCellRenderer.getVirtualFile(o1);
          VirtualFile v2 = UsageListCellRenderer.getVirtualFile(o2);
          String name1 = v1 == null ? null : v1.getName();
          String name2 = v2 == null ? null : v2.getName();
          int i = Comparing.compare(name1, name2);
          if (i != 0) return i;

          if (o1 instanceof Comparable && o2 instanceof Comparable) {
            return ((Comparable) o1).compareTo(o2);
          }

          FileEditorLocation loc1 = o1.getLocation();
          FileEditorLocation loc2 = o2.getLocation();
          return Comparing.compare(loc1, loc2);
        }
  public static String composeText(
      final Map<String, ExpectedHighlightingSet> types,
      Collection<HighlightInfo> infos,
      String text) {
    // filter highlighting data and map each highlighting to a tag name
    List<Pair<String, HighlightInfo>> list =
        ContainerUtil.mapNotNull(
            infos,
            (NullableFunction<HighlightInfo, Pair<String, HighlightInfo>>)
                info -> {
                  for (Map.Entry<String, ExpectedHighlightingSet> entry : types.entrySet()) {
                    final ExpectedHighlightingSet set = entry.getValue();
                    if (set.enabled
                        && set.severity == info.getSeverity()
                        && set.endOfLine == info.isAfterEndOfLine()) {
                      return Pair.create(entry.getKey(), info);
                    }
                  }
                  return null;
                });

    boolean showAttributesKeys = false;
    for (ExpectedHighlightingSet eachSet : types.values()) {
      for (HighlightInfo eachInfo : eachSet.infos) {
        if (eachInfo.forcedTextAttributesKey != null) {
          showAttributesKeys = true;
          break;
        }
      }
    }

    // sort filtered highlighting data by end offset in descending order
    Collections.sort(
        list,
        (o1, o2) -> {
          HighlightInfo i1 = o1.second;
          HighlightInfo i2 = o2.second;

          int byEnds = i2.endOffset - i1.endOffset;
          if (byEnds != 0) return byEnds;

          if (!i1.isAfterEndOfLine() && !i2.isAfterEndOfLine()) {
            int byStarts = i1.startOffset - i2.startOffset;
            if (byStarts != 0) return byStarts;
          } else {
            int byEOL = Comparing.compare(i2.isAfterEndOfLine(), i1.isAfterEndOfLine());
            if (byEOL != 0) return byEOL;
          }

          int bySeverity = i2.getSeverity().compareTo(i1.getSeverity());
          if (bySeverity != 0) return bySeverity;

          return Comparing.compare(i1.getDescription(), i2.getDescription());
        });

    // combine highlighting data with original text
    StringBuilder sb = new StringBuilder();
    Couple<Integer> result = composeText(sb, list, 0, text, text.length(), 0, showAttributesKeys);
    sb.insert(0, text.substring(0, result.second));
    return sb.toString();
  }
 @Override
 public int compareTo(@NotNull ExternalProjectSettings that) {
   return Comparing.compare(myExternalProjectPath, that.myExternalProjectPath);
 }
 @Override
 public int compareTo(VcsDescriptor o) {
   return Comparing.compare(myDisplayName, o.myDisplayName);
 }
 public int compareTo(final VcsRevisionNumber o) {
   return Comparing.compare(myText, ((TextRevisionNumber) o).myText);
 }
 public int compare(Task o1, Task o2) {
   int i = Comparing.compare(o2.getUpdated(), o1.getUpdated());
   return i == 0 ? Comparing.compare(o2.getCreated(), o1.getCreated()) : i;
 }