<commit_before>package com.nelson.compiler;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;

import java.util.HashMap;
import java.util.Map;

import javax.lang.model.element.Modifier;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;

/**
 * Permission proxy class
 * Created by Nelson on 17/5/5.
 */

public class ProxyInfo {

    public static final String PROXY = "PermissionProxy";

    private String mPackageName;
    private String mProxyClassName;
    private TypeElement mTypeElement;

    final Map<Integer, String> mGrantMethodMap = new HashMap<>();
    final Map<Integer, String> mDeniedMethodMap = new HashMap<>();
    final Map<Integer, String> mRationaleMethodMap = new HashMap<>();

    public ProxyInfo(Elements elementUtils, TypeElement classElement) {
        PackageElement packageElement = elementUtils.getPackageOf(classElement);
        String packageName = packageElement.getQualifiedName().toString();
        String className = ClassValidator.getClassName(classElement, packageName);
        this.mPackageName = packageName;
        this.mProxyClassName = className + "$$" + PROXY;
    }

    String getProxyClassFullName() {
        return mPackageName + "." + mProxyClassName;
    }

    JavaFile brewJavaCode() {
        //---manual generate---
       /* StringBuilder builder = new StringBuilder();
        builder.append("// Generated code.Do not modify!\n");
        builder.append("package ").append(mPackageName).append(";\n\n");
        builder.append("import com.nelson.api.*;\n");
        builder.append("\n");

        builder.append("public class ").append(mProxyClassName).append(" implements " + ProxyInfo.PROXY + "<" + mTypeElement.getSimpleName() + ">");
        builder.append(" {\n");

        generateMethods(builder);
        builder.append("\n");

        builder.append("}\n");
        return builder.toString();*/

        //---javapoet---
        ClassName interfaceName = ClassName.get("com.nelson.api", PROXY);
        ClassName superinterface = ClassName.bestGuess(mTypeElement.getQualifiedName().toString());

        TypeSpec.Builder typeSpec = TypeSpec.classBuilder(mProxyClassName)
                .addModifiers(Modifier.PUBLIC)
                // 添加接口，ParameterizedTypeName参数1是接口，参数2是接口的泛型
                .addSuperinterface(ParameterizedTypeName.get(interfaceName, superinterface));


        MethodSpec.Builder needShowRationaleMethod = MethodSpec.methodBuilder("needShowRationale")
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(Override.class)
                .returns(TypeName.BOOLEAN)
                .addParameter(TypeName.INT, "requestCode");

        needShowRationaleMethod.beginControlFlow("switch(requestCode)");
        for (int code : mRationaleMethodMap.keySet()) {
            needShowRationaleMethod.addCode("case $L:\n", code)
                    .addStatement("$> return true$<");
        }
        needShowRationaleMethod.endControlFlow();

        needShowRationaleMethod.addStatement("return false");

        TypeSpec proxyClass = typeSpec.addMethod(generatMethod("grant", mGrantMethodMap).build())
                .addMethod(generatMethod("denied", mDeniedMethodMap).build())
                .addMethod(generatMethod("rationale", mRationaleMethodMap).build())
                .addMethod(needShowRationaleMethod.build())
                .build();

        return JavaFile.builder(mPackageName, proxyClass)
                .addFileComment("Generated code from PermissionHandle. Do not modity!")
                .build();<commit_msg>fixed spelling mistakes<commit_after>package com.nelson.compiler;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;

import java.util.HashMap;
import java.util.Map;

import javax.lang.model.element.Modifier;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;

/**
 * Permission proxy class
 * Created by Nelson on 17/5/5.
 */

public class ProxyInfo {

    public static final String PROXY = "PermissionProxy";

    private String mPackageName;
    private String mProxyClassName;
    private TypeElement mTypeElement;

    final Map<Integer, String> mGrantMethodMap = new HashMap<>();
    final Map<Integer, String> mDeniedMethodMap = new HashMap<>();
    final Map<Integer, String> mRationaleMethodMap = new HashMap<>();

    public ProxyInfo(Elements elementUtils, TypeElement classElement) {
        PackageElement packageElement = elementUtils.getPackageOf(classElement);
        String packageName = packageElement.getQualifiedName().toString();
        String className = ClassValidator.getClassName(classElement, packageName);
        this.mPackageName = packageName;
        this.mProxyClassName = className + "$$" + PROXY;
    }

    String getProxyClassFullName() {
        return mPackageName + "." + mProxyClassName;
    }

    JavaFile brewJavaCode() {
        //---manual generate---
       /* StringBuilder builder = new StringBuilder();
        builder.append("// Generated code.Do not modify!\n");
        builder.append("package ").append(mPackageName).append(";\n\n");
        builder.append("import com.nelson.api.*;\n");
        builder.append("\n");

        builder.append("public class ").append(mProxyClassName).append(" implements " + ProxyInfo.PROXY + "<" + mTypeElement.getSimpleName() + ">");
        builder.append(" {\n");

        generateMethods(builder);
        builder.append("\n");

        builder.append("}\n");
        return builder.toString();*/

        //---javapoet---
        ClassName interfaceName = ClassName.get("com.nelson.api", PROXY);
        ClassName superinterface = ClassName.bestGuess(mTypeElement.getQualifiedName().toString());

        TypeSpec.Builder typeSpec = TypeSpec.classBuilder(mProxyClassName)
                .addModifiers(Modifier.PUBLIC)
                // 添加接口，ParameterizedTypeName参数1是接口，参数2是接口的泛型
                .addSuperinterface(ParameterizedTypeName.get(interfaceName, superinterface));


        MethodSpec.Builder needShowRationaleMethod = MethodSpec.methodBuilder("needShowRationale")
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(Override.class)
                .returns(TypeName.BOOLEAN)
                .addParameter(TypeName.INT, "requestCode");

        needShowRationaleMethod.beginControlFlow("switch(requestCode)");
        for (int code : mRationaleMethodMap.keySet()) {
            needShowRationaleMethod.addCode("case $L:\n", code)
                    .addStatement("$> return true$<");
        }
        needShowRationaleMethod.endControlFlow();

        needShowRationaleMethod.addStatement("return false");

        TypeSpec proxyClass = typeSpec.addMethod(generatMethod("grant", mGrantMethodMap).build())
                .addMethod(generatMethod("denied", mDeniedMethodMap).build())
                .addMethod(generatMethod("rationale", mRationaleMethodMap).build())
                .addMethod(needShowRationaleMethod.build())
                .build();

        return JavaFile.builder(mPackageName, proxyClass)
                .addFileComment("Generated code from PermissionHandle processor. Do not modify!")
                .build();
{'fraction_non_alphanumeric': 0.11773899452982547, 'fraction_numerical': 0.0015629070070330815, 'mean_word_length': 3.159804983748646, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6988196', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2070, 'n_words': 370}