@Override
  public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) {
    super.visitReferenceElement(reference);

    final PsiElement parent = reference.getParent();
    final MatchingHandler handler = myCompilingVisitor.getContext().getPattern().getHandler(reference);
    if (parent != null && parent.getParent() instanceof PsiClass) {
      GlobalCompilingVisitor.setFilter(handler, TypeFilter.getInstance());
    }
    else if (parent instanceof PsiNewExpression newExpression) {
      if (newExpression.isArrayCreation()) {
        GlobalCompilingVisitor.setFilter(handler, e -> e instanceof PsiJavaCodeReferenceElement || e instanceof PsiKeyword);
      }
      else {
        GlobalCompilingVisitor.setFilter(handler, e -> e instanceof PsiJavaCodeReferenceElement);
      }
    }
    else if (!(parent instanceof PsiAnnotation)) {
      GlobalCompilingVisitor.setFilter(handler, e -> e instanceof PsiJavaCodeReferenceElement);
    }
  }
@Override
  public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference)