当前位置: 首页>>代码示例>>Java>>正文


Java MethodSpec.constructorBuilder方法代码示例

本文整理汇总了Java中com.squareup.javapoet.MethodSpec.constructorBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java MethodSpec.constructorBuilder方法的具体用法?Java MethodSpec.constructorBuilder怎么用?Java MethodSpec.constructorBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.javapoet.MethodSpec的用法示例。


在下文中一共展示了MethodSpec.constructorBuilder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateConstructor

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private MethodSpec generateConstructor(ClassName appGlideModule,
    Set<String> libraryGlideModuleClassNames, Set<String> excludedGlideModuleClassNames) {
  MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
  constructorBuilder.addStatement("appGlideModule = new $T()", appGlideModule);

  ClassName androidLogName = ClassName.get("android.util", "Log");

  // Add some log lines to indicate to developers which modules where discovered.
  constructorBuilder.beginControlFlow("if ($T.isLoggable($S, $T.DEBUG))",
      androidLogName, GLIDE_LOG_TAG, androidLogName);
  constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
      "Discovered AppGlideModule from annotation: " + appGlideModule);
  // Excluded GlideModule classes from the manifest are logged in Glide's singleton.
  for (String glideModule : libraryGlideModuleClassNames) {
    ClassName moduleClassName = ClassName.bestGuess(glideModule);
    if (excludedGlideModuleClassNames.contains(glideModule)) {
      constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
          "AppGlideModule excludes LibraryGlideModule from annotation: " + moduleClassName);
    } else {
      constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
          "Discovered LibraryGlideModule from annotation: " + moduleClassName);
    }
  }
  constructorBuilder.endControlFlow();
  return constructorBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:AppModuleGenerator.java

示例2: generateMasterJavaFile

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private void generateMasterJavaFile(Map<String, Map<String, Element>> groups, List<JavaFile> javaFiles) {
    Set<Map.Entry<String, Map<String, Element>>> kvs = groups.entrySet();
    for (Map.Entry<String, Map<String, Element>> group : kvs) {
        String namespace = group.getKey();
        if (isEmpty(namespace)) return;

        Map<String, Element> methodMappings = group.getValue();

        // constructor build
        MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
        constructorBuilder.addModifiers(Modifier.PUBLIC).addException(Throwable.class);

        // constructor body
        constructorBuilder.addStatement("this.mapping = new $T()", HashMap.class);

        for (Map.Entry<String, Element> mapping : methodMappings.entrySet()) {
            String fullName = mapping.getKey();//method name + "." + extra
            Element element = mapping.getValue();

            SurgeonMethod sm = parseToSurgeonMethod(element);
            sm.owner = ClassName.get(((TypeElement) element.getEnclosingElement()));

            // add method
            constructorBuilder.addStatement(
                    "mapping.put($S," + "new $T($T.class," + sm.method + ",$S,$S)" + ")",
                    fullName,
                    SurgeonMethod,
                    sm.owner,
                    //method inner
                    sm.owner,
                    element.getSimpleName().toString(),
                    //method inner end
                    sm.simpleParamsName,
                    sm.simpleParamsTypes);
            //.addCode("\n");
        }

        // method build
        MethodSpec.Builder invokeBuilder = MethodSpec.methodBuilder("find");
        invokeBuilder.addModifiers(Modifier.PUBLIC)
                .returns(SurgeonMethod)
                .addParameter(String.class, "name");

        // method body
        invokeBuilder.addStatement("return ($T) mapping.get(name)", SurgeonMethod);

        // java file build
        String mirror_name_main = PREFIX + namespace.replace(".", "_");
        TypeSpec clazz = TypeSpec.classBuilder(mirror_name_main)
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(ISurgeonMaster)
                // Fields
                .addFields(buildRouterModuleFields())
                // constructor
                .addMethod(constructorBuilder.build())
                // Methods
                .addMethod(invokeBuilder.build())
                // doc
                .addJavadoc(FILE_DOC)
                .build();

        JavaFile javaFile = JavaFile.builder(PACKAGE_NAME, clazz).build();
        javaFiles.add(javaFile);
    }
}
 
开发者ID:TangXiaoLv,项目名称:Surgeon,代码行数:65,代码来源:SurgeonProcessor.java

示例3: makeSubFile

import com.squareup.javapoet.MethodSpec; //导入方法依赖的package包/类
private void makeSubFile(String scheme, String host, ClassName main, List<JavaFile> javaFiles) {
    String[] schemes = scheme.split("\\|");
    for (int i = 1; i < schemes.length; i++) {
        String subScheme = schemes[i];

        // filed build
        FieldSpec f_main = FieldSpec.builder(Object.class, "main")
                .addModifiers(Modifier.PRIVATE, Modifier.FINAL)
                .build();

        // constructor build
        MethodSpec.Builder constructor = MethodSpec.constructorBuilder();
        constructor.addModifiers(Modifier.PUBLIC)
                .addException(IllegalAccessException.class)
                .addException(InstantiationException.class)
                .addStatement("this.main = $T.class.newInstance()", main);

        // method build
        MethodSpec.Builder invoke = MethodSpec.methodBuilder("invoke")
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
                .returns(void.class)
                .addParameter(String.class, "path")
                .addParameter(PARAMS_WRAPPER, "params")
                .addException(Exception.class)
                .addStatement(
                        "main.getClass().getMethod(\"invoke\",String.class,$T.class).invoke(main, path, params)",
                        PARAMS_WRAPPER);

        // java file build
        String mirror_name_sub = PREFIX + subScheme + "_" + host;
        TypeSpec clazz = TypeSpec.classBuilder(mirror_name_sub)
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(IMIRROR)
                .addField(f_main)
                // constructor
                .addMethod(constructor.build())
                // Methods
                .addMethod(invoke.build())
                // doc
                .addJavadoc(FILE_DOC)
                .build();

        JavaFile javaFile = JavaFile.builder(PACKAGE_NAME, clazz).build();
        javaFiles.add(javaFile);
    }
}
 
开发者ID:TangXiaoLv,项目名称:Android-Router,代码行数:46,代码来源:AndroidRouterProcessor.java


注:本文中的com.squareup.javapoet.MethodSpec.constructorBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。