當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。