int (ElementNode n1, ElementNode n2) { if (n1.getDelegate() instanceof ClassMemberWithElement && n2.getDelegate() instanceof ClassMemberWithElement) { PsiElement element1 = ((ClassMemberWithElement)n1.getDelegate()).getElement(); PsiElement element2 = ((ClassMemberWithElement)n2.getDelegate()).getElement(); if (!(element1 instanceof PsiCompiledElement) && !(element2 instanceof PsiCompiledElement)) { final PsiFile file1 = element1.getContainingFile(); final PsiFile file2 = element2.getContainingFile(); if (Comparing.equal(file1, file2)) { return element1.getTextOffset() - element2.getTextOffset(); } else { if (file2 == null) return -1; if (file1 == null) return 1; return comparing(PsiFile::getVirtualFile, nullsLast(comparing(VirtualFile::getPath))).compare(file1, file2); } } } return n1.getOrder() - n2.getOrder(); }