private static boolean visitAnnotatedElementInner(@NotNull PsiElement element, @NotNull AnnotatedElementVisitor visitor) {
    final PsiElement parent = element.getParent();

    if (element instanceof PsiReferenceExpression) {
      if (parent instanceof PsiReferenceExpression) return false; // skip qualified references
      if (!visitor.visitReference((PsiReferenceExpression)element)) return false;
    }
    else if (element instanceof PsiNameValuePair && parent != null && parent.getParent() instanceof PsiAnnotation) {
      return visitor.visitAnnotationParameter((PsiNameValuePair)element, (PsiAnnotation)parent.getParent());
    }

    if (parent instanceof PsiAssignmentExpression p) {
      if (p.getRExpression() == element || p.getOperationTokenType() == JavaTokenType.PLUSEQ) {
        final PsiExpression left = p.getLExpression();
        if (left instanceof PsiReferenceExpression) {
          return visitor.visitReference((PsiReferenceExpression)left);
        }
      }
    }
    else if (parent instanceof PsiTemplateExpression templ) {
      if (templ.getProcessor() instanceof PsiReferenceExpression ref && ref != element) {
        PsiElement target = ref.resolve();
        if (target instanceof PsiVariable var) {
          visitor.visitVariable(var);
        }
      }
      else if (templ.getProcessor() instanceof PsiCallExpression call && call != element) {
        PsiMethod method = call.resolveMethod();
        if (method != null) {
          visitor.visitMethodReturnStatement(call, method);
        }
      }
    }
    else if (parent instanceof PsiConditionalExpression && ((PsiConditionalExpression)parent).getCondition() == element) {
      return false;
    }
    else if (parent instanceof PsiFunctionalExpression) {
      PsiMethod m = LambdaUtil.getFunctionalInterfaceMethod(parent);
      return m == null || visitor.visitMethodReturnStatement(element, m);
    }
    else if (parent instanceof PsiReturnStatement) {
      PsiElement e = PsiTreeUtil.getParentOfType(parent, PsiMethod.class, PsiFunctionalExpression.class);
      PsiMethod m = e == null ? null : e instanceof PsiMethod ? (PsiMethod)e : LambdaUtil.getFunctionalInterfaceMethod(e);
      return m == null || visitor.visitMethodReturnStatement(parent, m);
    }
    else if (parent instanceof PsiVariable) {
      return visitor.visitVariable((PsiVariable)parent);
    }
    else if (parent instanceof PsiModifierListOwner) {
      return false; // PsiClass/PsiClassInitializer/PsiCodeBlock
    }
    else if (parent instanceof PsiArrayInitializerMemberValue || parent instanceof PsiNameValuePair) {
      return true;
    }
    else if (parent instanceof PsiExpressionList && parent.getParent() instanceof PsiCall) {
      return visitor.visitMethodParameter((PsiExpression)element, (PsiCall)parent.getParent());
    }
    return true;
  }
private static boolean visitAnnotatedElementInner(@NotNull PsiElement element, @NotNull AnnotatedElementVisitor visitor)