@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);
 }
  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);
  }
 public void testOverloadConstructors() throws Exception {
   PsiClass aClass = myJavaFacade.findClass("B", GlobalSearchScope.allScope(myProject));
   PsiMethod constructor;
   //    constructor = myJavaFacade.getElementFactory().createConstructor();
   //    constructor = aClass.findMethodBySignature(constructor, false);
   constructor = aClass.findMethodsByName("B", false)[0];
   PsiMethodCallExpression superCall =
       (PsiMethodCallExpression) constructor.getBody().getStatements()[0].getFirstChild();
   PsiReferenceExpression superExpr = superCall.getMethodExpression();
   String[] fileNames = new String[] {"B.java", "A.java", "A.java", "B.java"};
   int[] starts = new int[] {};
   int[] ends = new int[] {};
   final ArrayList<PsiFile> filesList = new ArrayList<PsiFile>();
   final IntArrayList startsList = new IntArrayList();
   final IntArrayList endsList = new IntArrayList();
   PsiReference[] refs =
       MethodReferencesSearch.search(
               (PsiMethod) superExpr.resolve(), GlobalSearchScope.projectScope(myProject), false)
           .toArray(PsiReference.EMPTY_ARRAY);
   for (PsiReference ref : refs) {
     addReference(ref, filesList, startsList, endsList);
   }
   checkResult(fileNames, filesList, starts, startsList, ends, endsList);
 }
  private void checkUsages(PsiElement element, @NonNls String[] expectedFiles) {
    PsiReference[] refs =
        ReferencesSearch.search(element, GlobalSearchScope.projectScope(myProject), false)
            .toArray(PsiReference.EMPTY_ARRAY);

    List<PsiFile> files = new ArrayList<PsiFile>();
    for (PsiReference ref : refs) {
      PsiFile file = ref.getElement().getContainingFile();
      if (!files.contains(file)) {
        files.add(file);
      }
    }

    assertEquals(expectedFiles.length, files.size());

    Collections.sort(files, (file1, file2) -> file1.getName().compareTo(file2.getName()));
    Arrays.sort(expectedFiles);

    for (int i = 0; i < expectedFiles.length; i++) {
      String name = expectedFiles[i];
      PsiFile file = files.get(i);
      assertEquals(name, file.getName());
    }
  }