code: public static TypeElement enclosingClass(final Element elem) {
          Element result = elem;
          while (result != null && !result.getKind().isClass()
                  && !result.getKind().isInterface()) {
              Element encl = result.getEnclosingElement();
              result = encl;
          }
          return (TypeElement) result;
      }
docs: Returns the innermost type element enclosing the given element
  
  @param elem the enclosed element of a class
  @return the innermost type element