public static Optional<DeclaredType> nonObjectSuperclass(
      Types types, Elements elements, DeclaredType type) {
    checkNotNull(types);
    checkNotNull(elements); // This is no longer used, but here to avoid changing the API.
    checkNotNull(type);

    TypeMirror superclassType = asTypeElement(type).getSuperclass();
    if (!isType(superclassType)) { // type is Object or an interface
      return Optional.absent();
    }

    DeclaredType superclass = asDeclared(superclassType);
    if (isObjectType(superclass)) {
      return Optional.absent();
    }

    if (superclass.getTypeArguments().isEmpty()) {
      return Optional.of(superclass);
    }

    // In the case where the super class has type parameters, TypeElement#getSuperclass gives
    // SuperClass<T> rather than SuperClass<Foo>, so use Types#directSupertypes instead. The javadoc
    // for Types#directSupertypes guarantees that a super class, if it exists, comes before any
    // interfaces. Thus, we can just get the first element in the list.
    return Optional.of(asDeclared(types.directSupertypes(type).get(0)));
  }
Returns the superclass of {@code type}, with any type parameters bound by {@code type}, or
{@link Optional#absent()} if {@code type} is an interface or {@link Object} or its superclass
is {@link Object}.
common/src/main/java/com/google/auto/common/MoreTypes.java