public static Optional<DeclaredType> nonObjectSuperclass(final Types types, Elements elements,
                                                             DeclaredType type) {
        checkNotNull(types);
        checkNotNull(elements);
        checkNotNull(type);

        final TypeMirror objectType =
                elements.getTypeElement(Object.class.getCanonicalName()).asType();
        // It's guaranteed there's only a single CLASS superclass because java doesn't have multiple
        // class inheritance.
        TypeMirror superclass = getOnlyElement(FluentIterable.from(types.directSupertypes(type))
                .filter(new Predicate<TypeMirror>() {
                    @Override
                    public boolean apply(TypeMirror input) {
                        return input.getKind().equals(TypeKind.DECLARED)
                                && (MoreElements.asType(
                                MoreTypes.asDeclared(input).asElement())).getKind().equals(ElementKind.CLASS)
                                && !types.isSameType(objectType, input);
                    }
                }), null);
        return superclass != null
                ? Optional.of(MoreTypes.asDeclared(superclass))
                : Optional.<DeclaredType>absent();
    }
Utilities related to {@link TypeMirror} instances.

@author Gregory Kick
@since 2.0
android/annotation_processors/xposed_hook_compiler/src/main/java/github/tornaco/permission/compiler/common/MoreTypes.java