本文整理汇总了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;
}
示例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();
}
示例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());
}
示例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());
}