public static PackageElement getPackage(Element element) {
    while (element.getKind() != PACKAGE) {
      element = element.getEnclosingElement();
    }
    return (PackageElement) element;
  }
An alternate implementation of {@link Elements#getPackageOf} that does not require an {@link
Elements} instance.

@throws NullPointerException if {@code element} is {@code null}
common/src/main/java/com/google/auto/common/MoreElements.java