Java Code Examples for com.intellij.psi.util.PsiUtilCore#compareElementsByPosition()

The following examples show how to use com.intellij.psi.util.PsiUtilCore#compareElementsByPosition() . 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: InspectionResultsViewComparator.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static int compareEntity(final RefEntity entity, final PsiElement element) {
  if (entity instanceof RefElement) {
    final PsiElement psiElement = ((RefElement)entity).getElement();
    if (psiElement != null && element != null) {
      return PsiUtilCore.compareElementsByPosition(psiElement, element);
    }
    if (element == null) return psiElement == null ? 0 : 1;
  }
  if (element instanceof PsiQualifiedNamedElement) {
    return StringUtil.compare(entity.getQualifiedName(), ((PsiQualifiedNamedElement)element).getQualifiedName(), true);
  }
  if (element instanceof PsiNamedElement) {
    return StringUtil.compare(entity.getName(), ((PsiNamedElement)element).getName(), true);
  }
  return -1;
}
 
Example 2
Source File: InspectionResultsViewComparator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int compareEntities(final RefEntity entity1, final RefEntity entity2) {
  if (entity1 instanceof RefElement && entity2 instanceof RefElement) {
    return PsiUtilCore.compareElementsByPosition(((RefElement)entity1).getElement(), ((RefElement)entity2).getElement());
  }
  if (entity1 != null && entity2 != null) {
    return entity1.getName().compareToIgnoreCase(entity2.getName());
  }
  if (entity1 != null) return -1;
  return entity2 != null ? 1 : 0;
}