// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.lang.jvm.util;

import com.intellij.lang.jvm.JvmClass;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtilCore;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.Comparator;

public class JvmClassUtil {

  private JvmClassUtil() {}

  @Contract(pure = true)
  @NotNull
  public static Comparator<JvmClass> createScopeComparator(@NotNull GlobalSearchScope scope) {
    return (c1, c2) -> {
      VirtualFile file1 = PsiUtilCore.getVirtualFile(c1.getSourceElement());
      VirtualFile file2 = PsiUtilCore.getVirtualFile(c2.getSourceElement());
      if (file1 == null) return file2 == null ? 0 : -1;
      if (file2 == null) return 1;
      return scope.compare(file2, file1);
    };
  }
}

@@ -347,16 +347,52 @@
 ilCore;%0A
+import com.intellij.util.SmartList;%0A
 import o
@@ -472,94 +472,986 @@
 ll;%0A
-%0Aimport java.util.Comparator;%0A%0Apublic class JvmClassUtil %7B%0A%0A  private JvmClassUtil() %7B
+import org.jetbrains.annotations.Nullable;%0A%0Aimport java.util.Comparator;%0Aimport java.util.List;%0A%0Aimport static com.intellij.openapi.util.text.StringUtil.join;%0Aimport static com.intellij.util.containers.ContainerUtil.reverse;%0A%0Apublic class JvmClassUtil %7B%0A%0A  private JvmClassUtil() %7B%7D%0A%0A  @Nullable%0A  public static String getJvmClassName(@NotNull JvmClass aClass) %7B%0A    final List%3CString%3E parts = new SmartList%3C%3E();%0A%0A    JvmClass current = aClass;%0A    while (true) %7B%0A      final JvmClass containingClass = current.getContainingClass();%0A      if (containingClass == null) %7B // current class is top-level class%0A        String qualifiedName = current.getQualifiedName();%0A        if (qualifiedName == null) return null;%0A        parts.add(qualifiedName);%0A        break;%0A      %7D%0A      else %7B%0A        String name = current.getName();%0A        if (name == null) return null;%0A        parts.add(name);%0A        current = containingClass;%0A      %7D%0A    %7D%0A%0A    return join(reverse(parts), %22$%22);%0A  
 %7D%0A%0A 

add ability to compute JVM name of a JvmClass