code: public static TypeElement getDeclaringClass(Element element) {
      do {
        element = element.getEnclosingElement();
      } while (element != null && !isTypeElement(element));
      return (TypeElement) element;
    }
docs: static block, which does not work with getBinaryName(TypeElement) (one proven example)