// Path: library-compiler/src/main/java/com/wangjie/rapidrouter/compiler/constants/GuessClass.java
// public class GuessClass {
//     public static final String BASE_ROUTER_MAPPING = "com.wangjie.rapidrouter.core.RapidRouterMapping";
//     public static final String ROUTER_TARGET = "com.wangjie.rapidrouter.core.target.RouterTarget";
// 
// }
// 
// Path: library-compiler/src/main/java/com/wangjie/rapidrouter/compiler/util/LogUtil.java
// public class LogUtil {
//     public static final boolean LOG_CONTROL = true;
//     public static final boolean LOG_FILE = false;
//     private static SimpleDateFormat LOGGER_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
// 
// 
//     public static void loggerE(Throwable throwable) {
//         if (!LOG_CONTROL && !LOG_FILE) {
//             return;
//         }
//         logger("[ERROR]" + transformStackTrace(throwable));
//     }
// 
//     public static void logger(String str) {
//         if (!LOG_CONTROL && !LOG_FILE) {
//             return;
//         }
//         String loggerDate = "...[" + LOGGER_DATE_FORMAT.format(new Date()) + "]";
//         String log = loggerDate + ": " + str;
//         if (LOG_CONTROL) {
//             GlobalEnvironment.getProcessingEnv().getMessager().printMessage(Diagnostic.Kind.NOTE, log);
//         }
//         if (LOG_FILE) {
//             writeToDisk(log);
//         }
//     }
// 
//     private static void writeToDisk(String log) {
//         try {
//             File logFile = new File("/Users/wangjie/Desktop/za/test/rapidorm/processor_http.txt");
//             if (!logFile.exists()) {
//                 logFile.getParentFile().mkdirs();
//                 logFile.createNewFile();
//             }
//             FileWriter fw = new FileWriter(logFile, true);
//             fw.write(log + "\n\n");
//             fw.close();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     public static StringBuilder transformStackTrace(StackTraceElement[] elements){
//         StringBuilder sb = new StringBuilder();
//         for(StackTraceElement element : elements){
//             sb.append(element.toString()).append("\r\n");
//         }
//         return sb;
//     }
//     public static String transformStackTrace(Throwable throwable){
//         if(null == throwable){
//             return "throwable is null";
//         }
//         StringBuilder sb = new StringBuilder(throwable.getMessage()).append("\n");
//         for(StackTraceElement element : throwable.getStackTrace()){
//             sb.append(element.toString()).append("\r\n");
//         }
//         return sb.toString();
//     }
// 
// }


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 com.wangjie.rapidrouter.compiler.constants.GuessClass;
import com.wangjie.rapidrouter.compiler.util.LogUtil;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.lang.model.element.Modifier;
                    "getEnsureMap($L, $S).put($S, new $T($T.class, null))",
                    "routerMapper", uriEntry.getScheme(), uriEntry.getHost(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()));
        } else {
            calcSimpleMapperMethodBuilder.addStatement("$L = new $T<>(" + paramSize + ", 1F)",
                    "params", hashMapClassName);
            for (ParamEntry paramEntry : paramEntries) {
                LogUtil.logger("[Simple]paramEntry: " + paramEntry);
                calcSimpleMapperMethodBuilder.addStatement("params.put($S, $T.class)", paramEntry.getName(), paramEntry.getType());
            }

            calcSimpleMapperMethodBuilder.addStatement(
                    "getEnsureMap($L, $S).put($S, new $T($T.class, $L))",
                    "routerMapper", uriEntry.getScheme(), uriEntry.getHost(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()), "params");

        }
    }

    private void onRegularMapperMethodStatement(ClassName hashMapClassName, TypeName routerTargetTypeName, MethodSpec.Builder calcRegMapperMethodBuilder, UriEntry uriEntry) {
        calcRegMapperMethodBuilder.addCode("// " + uriEntry.getRouterTargetClass() + "\n");

        List<ParamEntry> paramEntries = uriEntry.getParams();
        int paramSize = null == paramEntries ? 0 : paramEntries.size();
        if (paramSize <= 0) {
            calcRegMapperMethodBuilder.addStatement(
                    "$L.put($S, new $T($T.class, null))",
                    "routerMapper", uriEntry.getUriRegular(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()));
        } else {
            calcRegMapperMethodBuilder.addStatement("$L = new $T<>(" + paramSize + ", 1F)",
                    "params", hashMapClassName);
            for (ParamEntry paramEntry : paramEntries) {
// Path: library-compiler/src/main/java/com/wangjie/rapidrouter/compiler/constants/GuessClass.java
// public class GuessClass {
//     public static final String BASE_ROUTER_MAPPING = "com.wangjie.rapidrouter.core.RapidRouterMapping";
//     public static final String ROUTER_TARGET = "com.wangjie.rapidrouter.core.target.RouterTarget";
// 
// }
// 
// Path: library-compiler/src/main/java/com/wangjie/rapidrouter/compiler/util/LogUtil.java
// public class LogUtil {
//     public static final boolean LOG_CONTROL = true;
//     public static final boolean LOG_FILE = false;
//     private static SimpleDateFormat LOGGER_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
// 
// 
//     public static void loggerE(Throwable throwable) {
//         if (!LOG_CONTROL && !LOG_FILE) {
//             return;
//         }
//         logger("[ERROR]" + transformStackTrace(throwable));
//     }
// 
//     public static void logger(String str) {
//         if (!LOG_CONTROL && !LOG_FILE) {
//             return;
//         }
//         String loggerDate = "...[" + LOGGER_DATE_FORMAT.format(new Date()) + "]";
//         String log = loggerDate + ": " + str;
//         if (LOG_CONTROL) {
//             GlobalEnvironment.getProcessingEnv().getMessager().printMessage(Diagnostic.Kind.NOTE, log);
//         }
//         if (LOG_FILE) {
//             writeToDisk(log);
//         }
//     }
// 
//     private static void writeToDisk(String log) {
//         try {
//             File logFile = new File("/Users/wangjie/Desktop/za/test/rapidorm/processor_http.txt");
//             if (!logFile.exists()) {
//                 logFile.getParentFile().mkdirs();
//                 logFile.createNewFile();
//             }
//             FileWriter fw = new FileWriter(logFile, true);
//             fw.write(log + "\n\n");
//             fw.close();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     public static StringBuilder transformStackTrace(StackTraceElement[] elements){
//         StringBuilder sb = new StringBuilder();
//         for(StackTraceElement element : elements){
//             sb.append(element.toString()).append("\r\n");
//         }
//         return sb;
//     }
//     public static String transformStackTrace(Throwable throwable){
//         if(null == throwable){
//             return "throwable is null";
//         }
//         StringBuilder sb = new StringBuilder(throwable.getMessage()).append("\n");
//         for(StackTraceElement element : throwable.getStackTrace()){
//             sb.append(element.toString()).append("\r\n");
//         }
//         return sb.toString();
//     }
// 
// }


// Path: library-compiler/src/main/java/com/wangjie/rapidrouter/compiler/objs/RouterEntry.java
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 com.wangjie.rapidrouter.compiler.constants.GuessClass;
import com.wangjie.rapidrouter.compiler.util.LogUtil;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.lang.model.element.Modifier;

                    "getEnsureMap($L, $S).put($S, new $T($T.class, null))",
                    "routerMapper", uriEntry.getScheme(), uriEntry.getHost(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()));
        } else {
            calcSimpleMapperMethodBuilder.addStatement("$L = new $T<>(" + paramSize + ", 1F)",
                    "params", hashMapClassName);
            for (ParamEntry paramEntry : paramEntries) {
                LogUtil.logger("[Simple]paramEntry: " + paramEntry);
                calcSimpleMapperMethodBuilder.addStatement("params.put($S, $T.class)", paramEntry.getName(), paramEntry.getType());
            }

            calcSimpleMapperMethodBuilder.addStatement(
                    "getEnsureMap($L, $S).put($S, new $T($T.class, $L))",
                    "routerMapper", uriEntry.getScheme(), uriEntry.getHost(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()), "params");

        }
    }

    private void onRegularMapperMethodStatement(ClassName hashMapClassName, TypeName routerTargetTypeName, MethodSpec.Builder calcRegMapperMethodBuilder, UriEntry uriEntry) {
        calcRegMapperMethodBuilder.addCode("// " + uriEntry.getRouterTargetClass() + "\n");

        List<ParamEntry> paramEntries = uriEntry.getParams();
        int paramSize = null == paramEntries ? 0 : paramEntries.size();
        if (paramSize <= 0) {
            calcRegMapperMethodBuilder.addStatement(
                    "$L.put($S, new $T($T.class, null))",
                    "routerMapper", uriEntry.getUriRegular(), routerTargetTypeName, ClassName.get(uriEntry.getRouterTargetClass().asType()));
        } else {
            calcRegMapperMethodBuilder.addStatement("$L = new $T<>(" + paramSize + ", 1F)",
                    "params", hashMapClassName);
            for (ParamEntry paramEntry : paramEntries) {
                LogUtil.logger("[Reg]paramEntry: " + paramEntry);