private void performAction(
      String from,
      String to,
      final int docCommentPolicy,
      String[] expectedConflicts,
      final String[] toPullUp) {
    final JSClassResolver resolver =
        JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4)
            .getClassResolver();
    final JSClass sourceClass =
        (JSClass) resolver.findClassByQName(from, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("source class not found: " + sourceClass, sourceClass);

    final JSClass targetClass =
        (JSClass) resolver.findClassByQName(to, GlobalSearchScope.projectScope(getProject()));
    assertNotNull("target class not found: " + targetClass, targetClass);

    assertTrue(
        "Source should be a subclass of target",
        JSInheritanceUtil.isParentClass(sourceClass, targetClass));

    final List<JSMemberInfo> memberInfos = getMemberInfos(toPullUp, sourceClass, false);

    final JSMemberInfo[] infosArray =
        JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.<JSMemberInfo>alwaysTrue());
    MultiMap<PsiElement, String> conflicts =
        JSPullUpConflictsUtil.checkConflicts(
            infosArray,
            sourceClass,
            targetClass,
            new JSInterfaceContainmentVerifier() {
              @Override
              public boolean checkedInterfacesContain(JSFunction psiMethod) {
                return JSPullUpHelper.checkedInterfacesContain(memberInfos, psiMethod);
              }
            },
            JSVisibilityUtil.DEFAULT_OPTIONS);

    ArrayList<String> messages = new ArrayList<String>(conflicts.values());
    for (int i = 0; i < messages.size(); i++) {
      messages.set(i, messages.get(i).replaceAll("<[^>]+>", ""));
    }
    assertSameElements(messages, expectedConflicts);
    if (conflicts.isEmpty()) {
      WriteCommandAction.runWriteCommandAction(
          null,
          new Runnable() {
            public void run() {
              new JSPullUpHelper(sourceClass, targetClass, infosArray, docCommentPolicy)
                  .moveMembersToBase();
              myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
            }
          });

      FileDocumentManager.getInstance().saveAllDocuments();
    }
  }
 @Override
 public String detectParameterValue(Project project) {
   PsiPackage root = JavaPsiFacade.getInstance(project).findPackage("");
   if (root == null) return null;
   String name = getBasePackage(root, GlobalSearchScope.projectScope(project)).getQualifiedName();
   return StringUtil.isEmpty(name) ? null : name;
 }
 @Nullable
 private PsiDirectory[] getSelectedDirectories() {
   if (myBuilder == null) return null;
   final Object[] selectedNodeElements = getSelectedNodeElements();
   if (selectedNodeElements.length != 1) return null;
   for (FavoriteNodeProvider nodeProvider :
       Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
     final PsiElement psiElement = nodeProvider.getPsiElement(selectedNodeElements[0]);
     if (psiElement instanceof PsiDirectory) {
       return new PsiDirectory[] {(PsiDirectory) psiElement};
     } else if (psiElement instanceof PsiDirectoryContainer) {
       final String moduleName = nodeProvider.getElementModuleName(selectedNodeElements[0]);
       GlobalSearchScope searchScope = GlobalSearchScope.projectScope(myProject);
       if (moduleName != null) {
         final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleName);
         if (module != null) {
           searchScope = GlobalSearchScope.moduleScope(module);
         }
       }
       return ((PsiDirectoryContainer) psiElement).getDirectories(searchScope);
     }
   }
   return selectedNodeElements[0] instanceof PsiDirectory
       ? new PsiDirectory[] {(PsiDirectory) selectedNodeElements[0]}
       : null;
 }
 public AntHectorConfigurable(XmlFile file) {
   myFile = file;
   myProject = file.getProject();
   final VirtualFile selfVFile = myFile.getVirtualFile();
   myLocalPath = PathUtil.getLocalPath(selfVFile);
   myFileFilter = GlobalSearchScope.projectScope(myProject);
 }
  @Nullable
  public static PsiClass[] getAllTestClasses(final TestClassFilter filter, boolean sync) {
    final PsiClass[][] holder = new PsiClass[1][];
    final Runnable process =
        () -> {
          final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();

          final Collection<PsiClass> set = new LinkedHashSet<>();
          final PsiManager manager = PsiManager.getInstance(filter.getProject());
          final GlobalSearchScope projectScope =
              GlobalSearchScope.projectScope(manager.getProject());
          final GlobalSearchScope scope = projectScope.intersectWith(filter.getScope());
          for (final PsiClass psiClass : AllClassesSearch.search(scope, manager.getProject())) {
            if (filter.isAccepted(psiClass)) {
              if (indicator != null) {
                indicator.setText2(
                    "Found test class " + ReadAction.compute(psiClass::getQualifiedName));
              }
              set.add(psiClass);
            }
          }
          holder[0] = set.toArray(new PsiClass[set.size()]);
        };
    if (sync) {
      ProgressManager.getInstance()
          .runProcessWithProgressSynchronously(
              process, "Searching For Tests...", true, filter.getProject());
    } else {
      process.run();
    }
    return holder[0];
  }
  public void testMultiPackageFunction() {
    myFixture.configureByText(
        JetFileType.INSTANCE,
        "package test.testing\n" + "fun other(v : Int) = 12\n" + "fun other(v : String) {}");

    StubPackageMemberDeclarationProvider provider =
        new StubPackageMemberDeclarationProvider(
            new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));

    List<JetNamedFunction> other =
        Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("other")));
    Collection<String> functionTexts =
        Collections2.transform(
            other,
            new Function<JetNamedFunction, String>() {
              @Override
              public String apply(JetNamedFunction function) {
                return function.getText();
              }
            });

    assertSize(2, other);
    assertTrue(functionTexts.contains("fun other(v : Int) = 12"));
    assertTrue(functionTexts.contains("fun other(v : String) {}"));
  }
  private static PsiDirectory[] suggestMostAppropriateDirectories(PsiPackage psiPackage) {
    final Project project = psiPackage.getProject();
    PsiDirectory[] directories = null;
    final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    if (editor != null) {
      final Document document = editor.getDocument();
      final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
      if (psiFile != null) {
        final Module module = ModuleUtil.findModuleForPsiElement(psiFile);
        if (module != null) {
          directories =
              psiPackage.getDirectories(GlobalSearchScope.moduleWithDependenciesScope(module));
        } else {
          directories =
              psiPackage.getDirectories(
                  GlobalSearchScope.notScope(GlobalSearchScope.projectScope(project)));
        }
      }
    }

    if (directories == null || directories.length == 0) {
      directories = psiPackage.getDirectories();
    }
    return directories;
  }
  @NotNull
  @Override
  public Collection<PsiReference> findReferences(PsiElement element) {
    assert element instanceof GrField;

    ArrayList<PsiReference> refs = new ArrayList<>();

    GrField field = (GrField) element;
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
    PsiMethod setter = field.getSetter();
    if (setter != null) {
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter));
    }
    GrAccessorMethod[] getters = field.getGetters();
    for (GrAccessorMethod getter : getters) {
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter));
    }
    refs.addAll(
        RenameAliasedUsagesUtil.filterAliasedRefs(
            ReferencesSearch.search(field, projectScope, false).findAll(), field));
    return refs;
  }
  @NotNull
  @Override
  public Collection<PsiReference> findReferences(final PsiElement element) {
    if (element instanceof GrField) {
      ArrayList<PsiReference> refs = new ArrayList<PsiReference>();

      GrField field = (GrField) element;
      PsiMethod setter = GroovyPropertyUtils.findSetterForField(field);
      GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
      if (setter != null && setter instanceof GrAccessorMethod) {
        refs.addAll(
            RenameAliasedUsagesUtil.filterAliasedRefs(
                MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter));
      }
      GrAccessorMethod[] getters = field.getGetters();
      for (GrAccessorMethod getter : getters) {
        refs.addAll(
            RenameAliasedUsagesUtil.filterAliasedRefs(
                MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter));
      }
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              ReferencesSearch.search(field, projectScope, true).findAll(), field));
      return refs;
    }
    return super.findReferences(element);
  }
  @NotNull
  private static DartLibInfo collectPackagesLibraryRoots(
      @NotNull final Project project, @NotNull final DartSdk sdk) {
    final DartLibInfo libInfo = new DartLibInfo(false);

    final Collection<VirtualFile> pubspecYamlFiles =
        FilenameIndex.getVirtualFilesByName(
            project, PUBSPEC_YAML, GlobalSearchScope.projectScope(project));
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();

    for (VirtualFile pubspecFile : pubspecYamlFiles) {
      final VirtualFile dotPackagesFile =
          pubspecFile.getParent().findChild(DotPackagesFileUtil.DOT_PACKAGES);
      final Module module =
          dotPackagesFile == null ? null : fileIndex.getModuleForFile(dotPackagesFile);

      if (dotPackagesFile != null
          && !dotPackagesFile.isDirectory()
          && module != null
          && DartSdkGlobalLibUtil.isDartSdkEnabled(module)) {
        final Map<String, String> packagesMap = DotPackagesFileUtil.getPackagesMap(dotPackagesFile);
        if (packagesMap != null) {
          for (Map.Entry<String, String> entry : packagesMap.entrySet()) {
            final String packageName = entry.getKey();
            final String packagePath = entry.getValue();
            if (isPathOutsideProjectContent(fileIndex, packagePath)) {
              libInfo.addPackage(packageName, packagePath);
            }
          }
        }
      }
    }

    return libInfo;
  }
 private static void addParameterUsages(
     PsiParameter parameter, ArrayList<UsageInfo> results, ParameterInfo info) {
   PsiManager manager = parameter.getManager();
   GlobalSearchScope projectScope = GlobalSearchScope.projectScope(manager.getProject());
   for (PsiReference psiReference : ReferencesSearch.search(parameter, projectScope, false)) {
     PsiElement parmRef = psiReference.getElement();
     UsageInfo usageInfo =
         new ChangeSignatureParameterUsageInfo(parmRef, parameter.getName(), info.getName());
     results.add(usageInfo);
   }
 }
  public void testSinglePackageFunction() {
    myFixture.configureByText(JetFileType.INSTANCE, "package test.testing\n" + "fun some() {}");
    StubPackageMemberDeclarationProvider provider =
        new StubPackageMemberDeclarationProvider(
            new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));

    List<JetNamedFunction> some =
        Lists.newArrayList(provider.getFunctionDeclarations(Name.identifier("some")));

    assertSize(1, some);
    assertEquals("fun some() {}", some.get(0).getText());
  }
 @NotNull
 @Override
 public NavigationItem[] getItemsByName(
     String name, String pattern, Project project, boolean includeNonProjectItems) {
   final GlobalSearchScope scope =
       includeNonProjectItems
           ? GlobalSearchScope.allScope(project)
           : GlobalSearchScope.projectScope(project);
   final Collection<HaxeComponent> result =
       HaxeComponentIndex.getItemsByName(name, project, scope);
   return result.toArray(new NavigationItem[result.size()]);
 }
 @NotNull
 public List<PsiClass> getClassesByFQName(
     @NotNull @NonNls String name, @NotNull GlobalSearchScope scope) {
   final List<PsiClass> result = addClasses(name, scope, true);
   if (result.isEmpty()) {
     result.addAll(addClasses(name, scope, false));
   }
   if (result.isEmpty()) {
     result.addAll(addClasses(name, GlobalSearchScope.projectScope(myProject), false));
   }
   return result;
 }
  @NotNull
  public Collection<PsiElement> findTestsForClass(@NotNull PsiElement element) {
    PsiClass klass = findSourceElement(element);
    if (klass == null) return Collections.emptySet();

    GlobalSearchScope scope;
    Module module = getModule(element);
    if (module != null) {
      scope = GlobalSearchScope.moduleWithDependentsScope(module);
    } else {
      scope = GlobalSearchScope.projectScope(element.getProject());
    }

    PsiShortNamesCache cache = JavaPsiFacade.getInstance(element.getProject()).getShortNamesCache();

    String klassName = klass.getName();
    Pattern pattern = Pattern.compile(".*" + klassName + ".*");

    List<Pair<PsiClass, Integer>> classesWithProximities = new ArrayList<Pair<PsiClass, Integer>>();

    HashSet<String> names = new HashSet<String>();
    cache.getAllClassNames(names);
    for (String eachName : names) {
      if (pattern.matcher(eachName).matches()) {
        for (PsiClass eachClass : cache.getClassesByName(eachName, scope)) {
          if (TestUtil.isTestClass(eachClass)) {
            classesWithProximities.add(
                new Pair<PsiClass, Integer>(eachClass, calcTestNameProximity(klassName, eachName)));
          }
        }
      }
    }

    Collections.sort(
        classesWithProximities,
        new Comparator<Pair<PsiClass, Integer>>() {
          public int compare(Pair<PsiClass, Integer> o1, Pair<PsiClass, Integer> o2) {
            int result = o1.second.compareTo(o2.second);
            if (result == 0) {
              result = o1.first.getName().compareTo(o2.first.getName());
            }
            return result;
          }
        });

    List<PsiElement> result = new ArrayList<PsiElement>();
    for (Pair<PsiClass, Integer> each : classesWithProximities) {
      result.add(each.first);
    }

    return result;
  }
  public void testPackageProperty() {
    myFixture.configureByText(JetFileType.INSTANCE, "package test.testing\n" + "val test = 12\n");

    StubPackageMemberDeclarationProvider provider =
        new StubPackageMemberDeclarationProvider(
            new FqName("test.testing"), getProject(), GlobalSearchScope.projectScope(getProject()));

    List<JetProperty> testProperties =
        Lists.newArrayList(provider.getPropertyDeclarations(Name.identifier("test")));

    assertSize(1, testProperties);
    assertEquals("val test = 12", testProperties.get(0).getText());
  }
  public void testGetPackageByIntermediatePartition() {
    myFixture.configureByText(JetFileType.INSTANCE, "package first.second.third");

    StubPackageMemberDeclarationProvider provider =
        new StubPackageMemberDeclarationProvider(
            new FqName("first.second"), getProject(), GlobalSearchScope.projectScope(getProject()));

    Collection<NavigatablePsiElement> packageDeclarations =
        provider.getPackageDeclarations(new FqName("first.second"));

    assertSize(1, packageDeclarations);
    assertEquals("second", packageDeclarations.iterator().next().getText());
  }
 @NotNull
 public static GlobalSearchScope getMaximalScope(@NotNull FindUsagesHandler handler) {
   PsiElement element = handler.getPsiElement();
   Project project = element.getProject();
   PsiFile file = element.getContainingFile();
   if (file != null
       && ProjectFileIndex.SERVICE
           .getInstance(project)
           .isInContent(file.getViewProvider().getVirtualFile())) {
     return GlobalSearchScope.projectScope(project);
   }
   return GlobalSearchScope.allScope(project);
 }
  @NotNull
  @Override
  protected UsageInfo[] findUsages() {
    ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();

    final PsiMethod toSearchFor = ((PsiMethod) mySettings.getToSearchFor());

    if (!mySettings.generateDelegate()) {
      Collection<PsiReference> refs =
          MethodReferencesSearch.search(
                  toSearchFor, GlobalSearchScope.projectScope(myProject), true)
              .findAll();

      for (PsiReference ref1 : refs) {
        PsiElement ref = ref1.getElement();
        if (ref instanceof PsiMethod && ((PsiMethod) ref).isConstructor()) {
          DefaultConstructorImplicitUsageInfo implicitUsageInfo =
              new DefaultConstructorImplicitUsageInfo(
                  (PsiMethod) ref, ((PsiMethod) ref).getContainingClass(), toSearchFor);
          result.add(implicitUsageInfo);
        } else if (ref instanceof PsiClass) {
          result.add(new NoConstructorClassUsageInfo((PsiClass) ref));
        } else if (!PsiTreeUtil.isAncestor(mySettings.getToReplaceIn(), ref, false)) {
          result.add(new ExternalUsageInfo(ref));
        } else {
          result.add(new ChangedMethodCallInfo(ref));
        }
      }
    }

    if (mySettings.replaceAllOccurrences()) {
      PsiElement[] exprs = GroovyIntroduceParameterUtil.getOccurrences(mySettings);
      for (PsiElement expr : exprs) {
        result.add(new InternalUsageInfo(expr));
      }
    } else {
      if (mySettings.getExpression() != null) {
        result.add(new InternalUsageInfo(mySettings.getExpression()));
      }
    }

    Collection<PsiMethod> overridingMethods =
        OverridingMethodsSearch.search(toSearchFor, true).findAll();

    for (PsiMethod overridingMethod : overridingMethods) {
      result.add(new UsageInfo(overridingMethod));
    }

    final UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]);
    return UsageViewUtil.removeDuplicatedUsages(usageInfos);
  }
 private boolean needTransformCopying(CompileScope compileScope) {
   final CompilerConfiguration configuration = CompilerConfiguration.getInstance(myProject);
   final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
   for (VirtualFile file :
       FilenameIndex.getVirtualFilesByName(
           myProject, AST_TRANSFORM_FILE_NAME, GlobalSearchScope.projectScope(myProject))) {
     if (compileScope.belongs(file.getUrl())
         && index.isInSource(file)
         && !configuration.isResourceFile(file)) {
       return true;
     }
   }
   return false;
 }
 protected static int initOccurrencesNumber(PsiNameIdentifierOwner nameIdentifierOwner) {
   final ProgressManager progressManager = ProgressManager.getInstance();
   final PsiSearchHelper searchHelper =
       PsiSearchHelper.SERVICE.getInstance(nameIdentifierOwner.getProject());
   final GlobalSearchScope scope =
       GlobalSearchScope.projectScope(nameIdentifierOwner.getProject());
   final String name = nameIdentifierOwner.getName();
   final boolean isCheapToSearch =
       name != null
           && searchHelper.isCheapEnoughToSearch(
                   name, scope, null, progressManager.getProgressIndicator())
               != PsiSearchHelper.SearchCostResult.TOO_MANY_OCCURRENCES;
   return isCheapToSearch ? ReferencesSearch.search(nameIdentifierOwner).findAll().size() : -1;
 }
  private void visitVariable(PsiVariable variable, TypeOccurence occurence) {
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myClass.getProject());
    for (PsiReference reference : ReferencesSearch.search(variable, projectScope, false)) {
      PsiElement element = reference.getElement();

      // todo: handle arrays
      if (element instanceof PsiExpression) {
        processExpression((PsiExpression) element, occurence, variable);
      } else {
        // todo: java doc processing?
        //        LOG.assertTrue(false);
      }
    }
  }
  @Override
  public void visitMethodReturnType(PsiMethod method, TypeOccurence occurence) {
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(myClass.getProject());

    for (PsiReference ref : ReferencesSearch.search(method, projectScope, false)) {
      PsiElement element = ref.getElement();
      if (element instanceof PsiReferenceExpression) {
        PsiElement parent = element.getParent();
        if (parent instanceof PsiMethodCallExpression) {
          processExpression((PsiMethodCallExpression) parent, occurence, method);
        }
      }
    }
  }
  @NotNull
  protected UsageInfo[] findUsages() {
    ArrayList<UsageInfo> result = new ArrayList<UsageInfo>();

    PsiMethod[] overridingMethods =
        OverridingMethodsSearch.search(myMethodToSearchFor, true).toArray(PsiMethod.EMPTY_ARRAY);
    for (PsiMethod overridingMethod : overridingMethods) {
      result.add(new UsageInfo(overridingMethod));
    }
    if (!myGenerateDelegate) {
      PsiReference[] refs =
          MethodReferencesSearch.search(
                  myMethodToSearchFor, GlobalSearchScope.projectScope(myProject), true)
              .toArray(PsiReference.EMPTY_ARRAY);

      for (PsiReference ref1 : refs) {
        PsiElement ref = ref1.getElement();
        if (ref instanceof PsiMethod && ((PsiMethod) ref).isConstructor()) {
          DefaultConstructorImplicitUsageInfo implicitUsageInfo =
              new DefaultConstructorImplicitUsageInfo(
                  (PsiMethod) ref, ((PsiMethod) ref).getContainingClass(), myMethodToSearchFor);
          result.add(implicitUsageInfo);
        } else if (ref instanceof PsiClass) {
          result.add(new NoConstructorClassUsageInfo((PsiClass) ref));
        } else if (!IntroduceParameterUtil.insideMethodToBeReplaced(ref, myMethodToReplaceIn)) {
          result.add(new ExternalUsageInfo(ref));
        } else {
          result.add(new ChangedMethodCallInfo(ref));
        }
      }
    }

    if (myReplaceAllOccurences) {
      for (PsiElement expr : getOccurrences()) {
        result.add(new InternalUsageInfo(expr));
      }
    } else {
      if (myExpressionToSearch != null && myExpressionToSearch.isValid()) {
        result.add(new InternalUsageInfo(myExpressionToSearch));
      }
    }

    final UsageInfo[] usageInfos = result.toArray(new UsageInfo[result.size()]);
    return UsageViewUtil.removeDuplicatedUsages(usageInfos);
  }
  public static void doTest(PsiElement element, String[] fileNames, int[] starts, int[] ends)
      throws Exception {
    final ArrayList<PsiFile> filesList = new ArrayList<PsiFile>();
    final IntArrayList startsList = new IntArrayList();
    final IntArrayList endsList = new IntArrayList();
    ReferencesSearch.search(element, GlobalSearchScope.projectScope(element.getProject()), false)
        .forEach(
            new PsiReferenceProcessorAdapter(
                new PsiReferenceProcessor() {
                  @Override
                  public boolean execute(PsiReference ref) {
                    addReference(ref, filesList, startsList, endsList);
                    return true;
                  }
                }));

    checkResult(fileNames, filesList, starts, startsList, ends, endsList);
  }
  @NotNull
  public Collection<PsiElement> findClassesForTest(@NotNull PsiElement element) {
    PsiClass klass = findSourceElement(element);
    if (klass == null) return Collections.emptySet();

    GlobalSearchScope scope;
    Module module = getModule(element);
    if (module != null) {
      scope = GlobalSearchScope.moduleWithDependenciesScope(module);
    } else {
      scope = GlobalSearchScope.projectScope(element.getProject());
    }

    PsiShortNamesCache cache = JavaPsiFacade.getInstance(element.getProject()).getShortNamesCache();

    List<Pair<PsiClass, Integer>> classesWithWeights = new ArrayList<Pair<PsiClass, Integer>>();
    for (Pair<String, Integer> eachNameWithWeight :
        collectPossibleClassNamesWithWeights(klass.getName())) {
      for (PsiClass eachClass : cache.getClassesByName(eachNameWithWeight.first, scope)) {
        if (isTestSubjectClass(eachClass)) {
          classesWithWeights.add(new Pair<PsiClass, Integer>(eachClass, eachNameWithWeight.second));
        }
      }
    }

    Collections.sort(
        classesWithWeights,
        new Comparator<Pair<PsiClass, Integer>>() {
          public int compare(Pair<PsiClass, Integer> o1, Pair<PsiClass, Integer> o2) {
            int result = o2.second.compareTo(o1.second);
            if (result == 0) {
              result = o1.first.getName().compareTo(o2.first.getName());
            }
            return result;
          }
        });

    List<PsiElement> result = new ArrayList<PsiElement>();
    for (Pair<PsiClass, Integer> each : classesWithWeights) {
      result.add(each.first);
    }

    return result;
  }
 public static boolean processUsagesInStringsAndComments(
     @NotNull final PsiElement element,
     @NotNull final String stringToSearch,
     final boolean ignoreReferences,
     @NotNull final PairProcessor<PsiElement, TextRange> processor) {
   PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(element.getProject());
   SearchScope scope = helper.getUseScope(element);
   scope = GlobalSearchScope.projectScope(element.getProject()).intersectWith(scope);
   Processor<PsiElement> commentOrLiteralProcessor =
       new Processor<PsiElement>() {
         public boolean process(PsiElement literal) {
           return processTextIn(literal, stringToSearch, ignoreReferences, processor);
         }
       };
   return processStringLiteralsContainingIdentifier(
           stringToSearch, scope, helper, commentOrLiteralProcessor)
       && helper.processCommentsContainingIdentifier(
           stringToSearch, scope, commentOrLiteralProcessor);
 }
 private static String getConfigurationName(PsiClass aClass, RunConfigurationModule module) {
   String qualifiedName = aClass.getQualifiedName();
   Project project = module.getProject();
   if (qualifiedName != null) {
     PsiClass psiClass =
         JavaPsiFacade.getInstance(project)
             .findClass(qualifiedName.replace('$', '.'), GlobalSearchScope.projectScope(project));
     if (psiClass != null) {
       return psiClass.getName();
     } else {
       int lastDot = qualifiedName.lastIndexOf('.');
       if (lastDot == -1 || lastDot == qualifiedName.length() - 1) {
         return qualifiedName;
       }
       return qualifiedName.substring(lastDot + 1, qualifiedName.length());
     }
   }
   return module.getModuleName();
 }
 private MyExistLocalesListModel() {
   myLocales = new ArrayList<>();
   myLocales.add(PropertiesUtil.DEFAULT_LOCALE);
   PropertiesReferenceManager.getInstance(myProject)
       .processPropertiesFiles(
           GlobalSearchScope.projectScope(myProject),
           new PropertiesFileProcessor() {
             @Override
             public boolean process(String baseName, PropertiesFile propertiesFile) {
               final Locale locale = propertiesFile.getLocale();
               if (locale != PropertiesUtil.DEFAULT_LOCALE && !myLocales.contains(locale)) {
                 myLocales.add(locale);
               }
               return true;
             }
           },
           BundleNameEvaluator.DEFAULT);
   Collections.sort(myLocales, LOCALE_COMPARATOR);
 }
 @NotNull
 public static List<PyFile> find(
     @NotNull String name, @NotNull Project project, boolean includeNonProjectItems) {
   final List<PyFile> results = new ArrayList<PyFile>();
   final GlobalSearchScope scope =
       includeNonProjectItems
           ? PyProjectScopeBuilder.excludeSdkTestsScope(project)
           : GlobalSearchScope.projectScope(project);
   final Collection<VirtualFile> files =
       FileBasedIndex.getInstance().getContainingFiles(NAME, name, scope);
   for (VirtualFile virtualFile : files) {
     final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
     if (psiFile instanceof PyFile) {
       if (!PyUserSkeletonsUtil.isUnderUserSkeletonsDirectory(psiFile)) {
         results.add((PyFile) psiFile);
       }
     }
   }
   return results;
 }