@Nullable
 private static PsiClass getFieldOrMethodAccessedClass(
     PsiReferenceExpression ref, PsiClass fieldOrMethodClass) {
   PsiElement[] children = ref.getChildren();
   if (children.length > 1 && children[0] instanceof PsiExpression) {
     PsiExpression expr = (PsiExpression) children[0];
     PsiType type = expr.getType();
     if (type != null) {
       if (!(type instanceof PsiClassType)) return null;
       return PsiUtil.resolveClassInType(type);
     } else {
       if (expr instanceof PsiReferenceExpression) {
         PsiElement refElement = ((PsiReferenceExpression) expr).resolve();
         if (refElement instanceof PsiClass) return (PsiClass) refElement;
       }
       return null;
     }
   }
   PsiManager manager = ref.getManager();
   for (PsiElement parent = ref; parent != null; parent = parent.getParent()) {
     if (parent instanceof PsiClass
         && (manager.areElementsEquivalent(parent, fieldOrMethodClass)
             || ((PsiClass) parent).isInheritor(fieldOrMethodClass, true))) {
       return (PsiClass) parent;
     }
   }
   return null;
 }
 @NotNull
 public UsageViewPresentation createPresentation(
     @NotNull FindUsagesHandler handler, @NotNull FindUsagesOptions findUsagesOptions) {
   PsiElement element = handler.getPsiElement();
   LOG.assertTrue(element.isValid());
   return createPresentation(element, findUsagesOptions, myToOpenInNewTab);
 }
 @NotNull
 private static Set<VirtualFile> getLocalScopeFiles(@NotNull LocalSearchScope scope) {
   Set<VirtualFile> files = new LinkedHashSet<VirtualFile>();
   for (PsiElement element : scope.getScope()) {
     PsiFile file = element.getContainingFile();
     if (file != null) {
       ContainerUtil.addIfNotNull(files, file.getVirtualFile());
     }
   }
   return files;
 }
 @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);
 }
 private static void convertToUsageTarget(
     @NotNull List<PsiElement2UsageTargetAdapter> targets, @NotNull PsiElement elementToSearch) {
   if (elementToSearch instanceof NavigationItem) {
     targets.add(new PsiElement2UsageTargetAdapter(elementToSearch));
   } else {
     throw new IllegalArgumentException(
         "Wrong usage target:" + elementToSearch + "; " + elementToSearch.getClass());
   }
 }
  private static List<PsiElement> getTopLevelRegExpChars(String regExpText, Project project) {
    @SuppressWarnings("deprecation")
    PsiFile file = PsiFileFactory.getInstance(project).createFileFromText("A.regexp", regExpText);
    List<PsiElement> result = null;
    final PsiElement[] children = file.getChildren();

    for (PsiElement child : children) {
      PsiElement[] grandChildren = child.getChildren();
      if (grandChildren.length != 1)
        return Collections
            .emptyList(); // a | b, more than one branch, can not predict in current way

      for (PsiElement grandGrandChild : grandChildren[0].getChildren()) {
        if (result == null) result = new ArrayList<>();
        result.add(grandGrandChild);
      }
    }
    return result != null ? result : Collections.<PsiElement>emptyList();
  }
 private static boolean askWhetherShouldSearchForParameterInOverridingMethods(
     final PsiElement psiElement, final PsiParameter parameter) {
   return Messages.showOkCancelDialog(
           psiElement.getProject(),
           FindBundle.message(
               "find.parameter.usages.in.overriding.methods.prompt", parameter.getName()),
           FindBundle.message("find.parameter.usages.in.overriding.methods.title"),
           CommonBundle.getYesButtonText(),
           CommonBundle.getNoButtonText(),
           Messages.getQuestionIcon())
       == 0;
 }
  private static boolean filterUsage(PsiElement usage, FindUsagesOptions options) {
    if (!(usage instanceof PsiJavaCodeReferenceElement)) {
      return true;
    }
    if (options instanceof JavaPackageFindUsagesOptions
        && !((JavaPackageFindUsagesOptions) options).isIncludeSubpackages
        && ((PsiReference) usage).resolve() instanceof PsiPackage) {
      PsiElement parent = usage.getParent();
      if (parent instanceof PsiJavaCodeReferenceElement
          && ((PsiJavaCodeReferenceElement) parent).resolve() instanceof PsiPackage) {
        return false;
      }
    }

    if (!(usage instanceof PsiReferenceExpression)) {
      if (options instanceof JavaFindUsagesOptions
          && ((JavaFindUsagesOptions) options).isSkipImportStatements) {
        PsiElement parent = usage.getParent();
        while (parent instanceof PsiJavaCodeReferenceElement) {
          parent = parent.getParent();
        }
        if (parent instanceof PsiImportStatement) {
          return false;
        }
      }

      if (options instanceof JavaPackageFindUsagesOptions
          && ((JavaPackageFindUsagesOptions) options).isSkipPackageStatements) {
        PsiElement parent = usage.getParent();
        while (parent instanceof PsiJavaCodeReferenceElement) {
          parent = parent.getParent();
        }
        if (parent instanceof PsiPackageStatement) {
          return false;
        }
      }
    }
    return true;
  }
 public static String getHelpID(PsiElement element) {
   return LanguageFindUsages.INSTANCE.forLanguage(element.getLanguage()).getHelpId(element);
 }