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


Java JavaFile.builder方法代码示例

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


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

示例1: process

import com.squareup.javapoet.JavaFile; //导入方法依赖的package包/类
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
  Filer filer = processingEnv.getFiler();
  Messager messager = processingEnv.getMessager();

  for (Element element : roundEnvironment.getElementsAnnotatedWith(DataEnum.class)) {
    try {

      Spec spec = SpecParser.parse(element, processingEnv);
      if (spec == null) {
        continue;
      }

      OutputSpec outputSpec = OutputSpecFactory.create(spec);
      TypeSpec outputTypeSpec = SpecTypeFactory.create(outputSpec);

      JavaFile.Builder javaFileBuilder =
          JavaFile.builder(outputSpec.outputClass().packageName(), outputTypeSpec);
      if (needsCheckNotNull(spec)) {
        javaFileBuilder.addStaticImport(DataenumUtils.class, "checkNotNull");
      }
      if (needsNullSafeEquals(spec)) {
        javaFileBuilder.addStaticImport(DataenumUtils.class, "equal");
      }

      JavaFile javaFile = javaFileBuilder.build();
      javaFile.writeTo(filer);

    } catch (IOException | ParserException e) {
      messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
    }
  }

  return false;
}
 
开发者ID:spotify,项目名称:dataenum,代码行数:36,代码来源:DataEnumProcessor.java

示例2: createFileSpec

import com.squareup.javapoet.JavaFile; //导入方法依赖的package包/类
private JavaFile createFileSpec() throws Exception {
    AnnotationSpec generated = AnnotationSpec.builder(Generated.class)
            .addMember("value", "$S", "com.vocalabs.egtest.EgTest")
            .build();
    TypeSpec.Builder typeSpecBuilder = TypeSpec.classBuilder(className)
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .addAnnotation(generated);
    TestWriter.write(this, typeSpecBuilder);
    codeInjector.decorateClass(typeSpecBuilder);
    TypeSpec javaFileSpec = typeSpecBuilder.build();
    JavaFile.Builder fileBuilder = JavaFile.builder(codeInjector.getPackageName(), javaFileSpec);
    return fileBuilder.build();
}
 
开发者ID:dleppik,项目名称:EgTest,代码行数:14,代码来源:ClassWriter.java

示例3: buildProxyClass

import com.squareup.javapoet.JavaFile; //导入方法依赖的package包/类
public JavaFile.Builder buildProxyClass() {
    ClassName proxyClassName = getProxyClassName();

    TypeSpec.Builder proxyClassBuilder = TypeSpec
            .classBuilder(proxyClassName.simpleName())
            .addModifiers(Modifier.PUBLIC)
            .addSuperinterface(TypeName.get(getRemoterInterfaceElement().asType()));


    for (TypeParameterElement typeParameterElement : ((TypeElement) getRemoterInterfaceElement()).getTypeParameters()) {
        proxyClassBuilder.addTypeVariable(TypeVariableName.get(typeParameterElement.toString()));
    }

    //constructor
    proxyClassBuilder.addMethod(MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addJavadoc("Initialize this {@link " + getProxyClassName().simpleName() + "} with the given {@link IBinder}\n\n")
            .addJavadoc("@param binder An {@link IBinder} that exposes a remote {@link " + getRemoterInterfaceClassName() + "}\n")
            .addParameter(ClassName.get("android.os", "IBinder"), "binder")
            .addStatement("this.mRemote = binder").build());


    getBindingManager().getFieldBuilder(getRemoterInterfaceElement()).addProxyFields(proxyClassBuilder);
    getBindingManager().getMethoddBuilder(getRemoterInterfaceElement()).addProxyMethods(proxyClassBuilder);

    proxyClassBuilder.addJavadoc("Wraps a remote {@link IBinder} that implements {@link " + getRemoterInterfaceClassName() + "} interface\n");
    proxyClassBuilder.addJavadoc("<p>\n");
    proxyClassBuilder.addJavadoc("Autogenerated by <a href=\"https://bit.ly/Remoter\">Remoter</a>\n");
    proxyClassBuilder.addJavadoc("@see " + getStubClassName().simpleName() + "\n");

    return JavaFile.builder(proxyClassName.packageName(), proxyClassBuilder.build());
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:33,代码来源:ClassBuilder.java

示例4: buildStubClass

import com.squareup.javapoet.JavaFile; //导入方法依赖的package包/类
public JavaFile.Builder buildStubClass() {
    ClassName stubClassName = getStubClassName();

    TypeSpec.Builder stubClassBuilder = TypeSpec
            .classBuilder(stubClassName.simpleName())
            .addModifiers(Modifier.PUBLIC)
            .superclass(TypeName.get(getBindingManager().getType("android.os.Binder")));

    for (TypeParameterElement typeParameterElement : ((TypeElement) getRemoterInterfaceElement()).getTypeParameters()) {
        stubClassBuilder.addTypeVariable(TypeVariableName.get(typeParameterElement.toString()));
    }


    //constructor
    stubClassBuilder.addMethod(MethodSpec.constructorBuilder()
            .addModifiers(Modifier.PUBLIC)
            .addJavadoc("Initialize this {@link " + getStubClassName().simpleName() + "} with the given {@link " + getRemoterInterfaceClassName() + "} implementation \n\n")
            .addJavadoc("@param serviceImpl An implementation of {@link " + getRemoterInterfaceClassName() + "}\n")
            .addParameter(TypeName.get(getRemoterInterfaceElement().asType()), "serviceImpl")
            .addStatement("this.serviceImpl = serviceImpl")
            .beginControlFlow("this.attachInterface(new $T()", ClassName.get("android.os", "IInterface"))
            .beginControlFlow("public $T asBinder()", ClassName.get("android.os", "IBinder"))
            .addStatement("return " + stubClassName.simpleName() + ".this")
            .endControlFlow()
            .endControlFlow()
            .addStatement(", DESCRIPTOR)")
            .build());


    getBindingManager().getFieldBuilder(getRemoterInterfaceElement()).addStubFields(stubClassBuilder);
    getBindingManager().getMethoddBuilder(getRemoterInterfaceElement()).addStubMethods(stubClassBuilder);

    stubClassBuilder.addJavadoc("Wraps a {@link " + getRemoterInterfaceClassName() + "} implementation and expose it as a remote {@link IBinder}\n");
    stubClassBuilder.addJavadoc("<p>\n");
    stubClassBuilder.addJavadoc("Autogenerated by <a href=\"https://bit.ly/Remoter\">Remoter</a>\n");
    stubClassBuilder.addJavadoc("@see " + getProxyClassName().simpleName() + "\n");

    return JavaFile.builder(stubClassName.packageName(), stubClassBuilder.build());
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:40,代码来源:ClassBuilder.java


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