public static @Nullable PsiElement findReferenceTarget(@NotNull PsiManager manager, @NotNull String refText, PsiElement context, boolean useNavigationElement) {
    LOG.assertTrue(context == null || context.isValid());
    if (context != null) {
      context = context.getNavigationElement();
    }

    int poundIndex = refText.indexOf('#');
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
    if (poundIndex < 0) {
      PsiClass aClass = findClassFromRef(manager, facade, refText, context);

      if (aClass != null) {
        return useNavigationElement ? aClass.getNavigationElement() : aClass;
      }
      PsiPackage aPackage = facade.findPackage(refText);
      if (aPackage!=null) return aPackage;
      return null;
    }
    else {
      String classRef = refText.substring(0, poundIndex).trim();
      if (!classRef.isEmpty()) {
        PsiClass aClass = findClassFromRef(manager, facade, classRef, context);

        if (aClass == null) return null;
        PsiElement member = findReferencedMember(aClass, refText.substring(poundIndex + 1), context);
        return useNavigationElement && member != null ? member.getNavigationElement() : member;
      }
      else {
        String memberRefText = refText.substring(1);
        PsiElement scope = context;
        while (scope != null && !(scope instanceof PsiFile)) {
          if (scope instanceof PsiClass) {
            PsiElement member = findReferencedMember((PsiClass)scope, memberRefText, context);
            if (member != null) {
              return useNavigationElement ? member.getNavigationElement() : member;
            }
          }
          scope = scope.getParent();
        }
        return null;
      }
    }
  }
public static @Nullable PsiElement findReferenceTarget(@NotNull PsiManager manager, @NotNull String refText, PsiElement context, boolean useNavigationElement)