private Iterable<MethodSpec> createMethodSpecs(TypeElement typeElement) {
        List<MethodSpec> methodSpecs = new ArrayList<>();

        methodSpecs.add(createOnPermissionRequestResultMethod());

        methodSpecs.add(MethodSpec.methodBuilder("checkSelfPermissions")
                .addParameter(ClassName.get("android.content", "Context"), "context")
                .addParameter(String[].class, "perms")
                .addModifiers(Modifier.STATIC)
                .returns(TypeName.BOOLEAN)
                .addCode("for (String p : perms) {\n" +
                        "            if (androidx.core.app.ActivityCompat.checkSelfPermission(context, p)\n" +
                        "                    != android.content.pm.PackageManager.PERMISSION_GRANTED) {\n" +
                        "                return false;\n" +
                        "            }\n" +
                        "        }\n" +
                        "        return true;\n")
                .build());

        List<? extends Element> enclosedElements = typeElement.getEnclosedElements();

        enclosedElements.stream().filter(e -> e.getKind() == ElementKind.METHOD).forEach(e -> {
            RequiresPermission requiresPermission = e.getAnnotation(RequiresPermission.class);
            RequiresPermission.Before before = e.getAnnotation(RequiresPermission.Before.class);
            RequiresPermission.OnDenied onDenied = e.getAnnotation(RequiresPermission.OnDenied.class);
            if (requiresPermission != null) {
                Logger.debug("RequiresPermission found @:" + e);
                try {
                    methodSpecs.add(createMethodForRequiresPermission(typeElement, e,
                            before,
                            onDenied,
                            requiresPermission));
                } catch (Throwable t) {
//                    StringBuilder stacks = new StringBuilder();
//                    for (StackTraceElement se : t.getStackTrace()) {
//                        stacks.append(se.toString()).append("\n");
//                    }
                    mErrorReporter.abortWithError(t.getLocalizedMessage(), e);
                }
            }
        });
        return methodSpecs;
    }
Created by guohao4 on 2017/9/6.
Email: Tornaco@163.com
android/annotation_processors/permission-requester-compiler/src/main/java/github/tornaco/permission/compiler/RuntimePermissionsCompiler.java