public static boolean isTypeOf(final Class<?> clazz, TypeMirror type) {
        checkNotNull(clazz);
        return type.accept(new SimpleTypeVisitor6<Boolean, Void>() {
            @Override
            protected Boolean defaultAction(TypeMirror type, Void ignored) {
                throw new IllegalArgumentException(type + " cannot be represented as a Class<?>.");
            }

            @Override
            public Boolean visitNoType(NoType noType, Void p) {
                if (noType.getKind().equals(TypeKind.VOID)) {
                    return clazz.equals(Void.TYPE);
                }
                throw new IllegalArgumentException(noType + " cannot be represented as a Class<?>.");
            }

            @Override
            public Boolean visitPrimitive(PrimitiveType type, Void p) {
                switch (type.getKind()) {
                    case BOOLEAN:
                        return clazz.equals(Boolean.TYPE);
                    case BYTE:
                        return clazz.equals(Byte.TYPE);
                    case CHAR:
                        return clazz.equals(Character.TYPE);
                    case DOUBLE:
                        return clazz.equals(Double.TYPE);
                    case FLOAT:
                        return clazz.equals(Float.TYPE);
                    case INT:
                        return clazz.equals(Integer.TYPE);
                    case LONG:
                        return clazz.equals(Long.TYPE);
                    case SHORT:
                        return clazz.equals(Short.TYPE);
                    default:
                        throw new IllegalArgumentException(type + " cannot be represented as a Class<?>.");
                }
            }

            @Override
            public Boolean visitArray(ArrayType array, Void p) {
                return clazz.isArray()
                        && isTypeOf(clazz.getComponentType(), array.getComponentType());
            }

            @Override
            public Boolean visitDeclared(DeclaredType type, Void ignored) {
                TypeElement typeElement;
                try {
                    typeElement = MoreElements.asType(type.asElement());
                } catch (IllegalArgumentException iae) {
                    throw new IllegalArgumentException(type + " does not represent a class or interface.");
                }
                return typeElement.getQualifiedName().contentEquals(clazz.getCanonicalName());
            }
        }, null);
    }
Utilities related to {@link TypeMirror} instances.

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