本文整理汇总了Java中com.squareup.javapoet.TypeSpec.Builder.addMethod方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.addMethod方法的具体用法?Java Builder.addMethod怎么用?Java Builder.addMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.javapoet.TypeSpec.Builder
的用法示例。
在下文中一共展示了Builder.addMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addClassMethodsToBuilder
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* genera i metodi di test per clazz
*
* @param classTestBuilder
* @param clazz
* @param prop
* @param mongo
*/
private void addClassMethodsToBuilder(Builder classTestBuilder, Class<?> clazz) {
int count = 0;
String appName = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.APP_NAME);
List<Document> methodInfo;
for (Method method : clazz.getDeclaredMethods()) {
Document methodInputs = null, methodOutput = null;
if (java.lang.reflect.Modifier.isPublic(method.getModifiers())) {
LOG.info("app: " + appName + " - method: " + method);
count++;
methodInfo = mongo.find(appName, method.toString());
for (Document doc : methodInfo) {
LOG.debug("document: " + doc);
if (doc.containsKey("argsBefore")) {
methodInputs = doc;
} else {
methodOutput = doc;
}
}
MethodSpec methodSpec = getMethodSpec(count, method, clazz, methodInputs, methodOutput);
classTestBuilder.addMethod(methodSpec);
}
}
classTestBuilder.addMethod(getDeserializeMethod(clazz));
}
示例2: generate
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Generate and save the Java file for the typeElement passed to the constructor
* @param directiveTypeElement The {@link VueDirective} class to
* generate {@link VueDirectiveOptions} from
*/
public void generate(TypeElement directiveTypeElement)
{
ClassName optionsClassName = GenerationNameUtil.directiveOptionsName(directiveTypeElement);
Builder componentClassBuilder = TypeSpec
.classBuilder(optionsClassName)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.superclass(VueDirectiveOptions.class)
.addAnnotation(JsType.class)
.addJavadoc("VueComponent Directive Options for directive {@link $S}",
directiveTypeElement.getQualifiedName().toString());
// Initialize constructor
MethodSpec.Builder constructorBuilder =
MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC);
// Add the Java Component Instance initialization
constructorBuilder.addStatement("this.$L = new $T()",
"vuegwt$javaDirectiveInstance",
TypeName.get(directiveTypeElement.asType()));
// Call the method to copy hooks functions
constructorBuilder.addStatement("this.copyHooks()");
// Finish building the constructor
componentClassBuilder.addMethod(constructorBuilder.build());
// Build the DirectiveOptions class
GenerationUtil.toJavaFile(filer,
componentClassBuilder,
optionsClassName,
directiveTypeElement);
}
示例3: processRenderFunction
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Process the render function from the Component Class if it has one.
* @param component {@link VueComponent} to process
* @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
* {@link VueComponentOptions}
* @param componentJsTypeBuilder Builder for the JsType class
*/
private void processRenderFunction(TypeElement component, MethodSpec.Builder optionsBuilder,
Builder componentJsTypeBuilder)
{
if (!hasInterface(processingEnv, component.asType(), HasRender.class))
return;
componentJsTypeBuilder.addMethod(MethodSpec
.methodBuilder("vuegwt$render")
.addModifiers(Modifier.PUBLIC)
.returns(VNode.class)
.addParameter(CreateElementFunction.class, "createElementFunction")
.addStatement("return super.render(new $T(createElementFunction))", VNodeBuilder.class)
.build());
// Register the render method
optionsBuilder.addStatement("options.addHookMethod($S, $S)", "render", "vuegwt$render");
}
示例4: generate
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Generate our {@link VueFactory} class.
* @param component The {@link VueComponent} class to generate {@link VueComponentOptions} from
*/
public void generate(TypeElement component)
{
ClassName vueFactoryClassName = componentFactoryName(component);
Builder vueFactoryBuilder = createFactoryBuilderClass(component, vueFactoryClassName);
createProperties(vueFactoryClassName, vueFactoryBuilder);
List<CodeBlock> staticInitParameters = createInitMethod(component, vueFactoryBuilder);
createStaticGetMethod(vueFactoryClassName, vueFactoryBuilder, staticInitParameters);
vueFactoryBuilder.addMethod(MethodSpec
.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Inject.class)
.build());
// Build the ComponentOptions class
GenerationUtil.toJavaFile(filer, vueFactoryBuilder, vueFactoryClassName, component);
}
示例5: generateProvisionMethodForProviderOrLazy
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* For key like javax.inject.Provider<Foo> and dagger.Lazy<Foo>. Qualifier, if presented, will
* also apply to element binding.
*/
private void generateProvisionMethodForProviderOrLazy(NewBindingKey key,
TypeElement referencingClass, String suffix) {
// System.out.println(String.format(
// "generateProvisionMethodForProviderOrLazy: key %s, referencingClass: %s, suffix : %s.", key,
// referencingClass, suffix));
ClassName injectorClassName = getInjectorFor(key, referencingClass);
TypeSpec anonymousTypeSpec =
createAnonymousBuiltinTypeForUniqueBinding(injectorClassName, key, referencingClass);
MethodSpec.Builder methodSpecBuilder =
MethodSpec.methodBuilder(getProvisionMethodName(key) + suffix)
.addModifiers(suffix.isEmpty() ? Modifier.PUBLIC : Modifier.PRIVATE)
.returns(key.getTypeName()).addStatement("return $L", anonymousTypeSpec);
Builder componentSpecBuilder =
getInjectorTypeSpecBuilder(getInjectorFor(key, referencingClass));
componentSpecBuilder.addMethod(methodSpecBuilder.build());
}
示例6: generateScopedProvisionMethod
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void generateScopedProvisionMethod(
Builder componentSpecBuilder, NewBindingKey key) {
MethodSpec.Builder builder =
MethodSpec.methodBuilder(getProvisionMethodName(key))
.returns(key.getTypeName())
.addModifiers(Modifier.PUBLIC);
builder
.addStatement("$T result = $N", key.getTypeName().box(), getFieldName(key))
.beginControlFlow("if (result == null)")
.beginControlFlow("synchronized ($L)", TOP_LEVEL_INJECTOR_FIELD)
.addStatement("result = $N", getFieldName(key)).beginControlFlow("if (result == null)")
.addStatement("result = $L = $L()", getFieldName(key),
getProvisionMethodName(key) + UNSCOPED_SUFFIX)
.endControlFlow() // if
.endControlFlow() // synchronized
.endControlFlow() // if
.addStatement("return result");
componentSpecBuilder.addMethod(builder.build());
}
示例7: extendConcludingBuilder
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void extendConcludingBuilder(ProcessorContext context, Builder builderTypeBuilder,
DeclaredType concludingBuilder) {
if (context.utils().isAssignable(concludingBuilder,
context.utils().of(ClassArgBuilder.class), true)) {
// implement the constructor with class parameters
// TODO that bundle part is redundant... consider improving
builderTypeBuilder.addMethod(MethodSpec.constructorBuilder()
.addParameter(ClassName.get(AndroidTypes.Bundle.asMirror(context)),
"bundle")
.addCode("super(bundle, $L.class);", targetClassName).build());
} else if (context.utils().isAssignable(concludingBuilder,
context.utils().of(ArgConcludingBuilder.class), true)) {
// this is probably an user implemented one
builderTypeBuilder.addMethod(MethodSpec.constructorBuilder()
.addCode("this.bundle = new Bundle();").build());
} else {
throw new AssertionError(concludingBuilder + " is not supported, @ArgConfig should"
+ " not allow this in the first place...");
}
}
示例8: addEncodeMethod
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
private void addEncodeMethod(Builder classBuilder, List<FieldModel> fieldModel) {
MethodSpec.Builder encode = MethodSpec.methodBuilder("encode")
.returns(TypeName.VOID).addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class).addParameter(BsonWriter.class, "writer")
.addParameter(this.thisType, "value")
.addParameter(EncoderContext.class, "encoderContext")
.addStatement("writer.writeStartDocument()");
for (FieldModel field : fieldModel) {
String getter = "value." + field.methodNameGet() + "()";
String setter = "value." + field.methodNameSet() + "(%s)";
CodeGeneratorContext ctx = new CodeGeneratorContext(field, encode,
this.instanceFields, getter, setter);
field.codeGen().addEncodeStatements(ctx);
}
encode.addStatement("writer.writeEndDocument()");
classBuilder.addMethod(encode.build());
}
示例9: markerBuilder
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
public static JavaFile markerBuilder(Domain ontology) {
List<Key> keys = ontology.getKeys();
ClassName name = ClassName.get(ontology.getTargetPackage(), ontology.getName()+ MARKER_BUILDER);
Builder builder = TypeSpec.classBuilder(name)
.addJavadoc(composeJavadoc(ontology, name))
.addModifiers(Modifier.PUBLIC);
ClassName markerName = getName(ontology);
for(Key key : keys) {
builder.addMethod(getBuilderMethod(markerName, key));
}
if(ontology.hasTags()) {
ClassName tagsName = TagGenerator.getName(ontology);
ParameterSpec parameter = ParameterSpec.builder(ArrayTypeName.of(tagsName), "value").build();
builder.addMethod(MethodSpec.methodBuilder("tags")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addParameter(parameter).varargs()
.addStatement("$T marker = new $T()", markerName, markerName)
.addStatement("marker.tags($N)", parameter)
.returns(markerName)
.addStatement("return marker")
.build());
}
return JavaFile.builder(name.packageName(), builder.build()).build();
}
示例10: poetSpec
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
@Override
public TypeSpec poetSpec() {
ClassName interfaceClass = poetExtensions.getClientClass(model.getMetadata().getSyncInterface());
Builder classBuilder = PoetUtils.createClassBuilder(className)
.addAnnotation(SdkInternalApi.class)
.addModifiers(FINAL)
.addSuperinterface(interfaceClass)
.addJavadoc("Internal implementation of {@link $1T}.\n\[email protected] $1T#builder()",
interfaceClass)
.addField(ClientHandler.class, "clientHandler", PRIVATE, FINAL)
.addField(protocolSpec.protocolFactory(model))
.addField(ClientConfiguration.class, "clientConfiguration", PRIVATE, FINAL)
.addMethods(operations());
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
classBuilder.addMethod(constructorWithAdvancedConfiguration());
} else {
classBuilder.addMethod(constructor());
}
protocolSpec.createErrorResponseHandler().ifPresent(classBuilder::addMethod);
classBuilder.addMethod(protocolSpec.initProtocolFactory(model));
classBuilder.addMethod(closeMethod());
classBuilder.addMethods(protocolSpec.additionalMethods());
return classBuilder.build();
}
示例11: createCreatedHook
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Create the "created" hook method. This method will be called on each Component when it's
* created.
* It will inject dependencies if any, and call the {@link ComponentJavaConstructor} on the
* newly created instance.
* @param component {@link VueComponent} to process
* @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
* {@link VueComponentOptions}
* @param componentJsTypeBuilder Builder for the JsType class
* @param dependenciesBuilder Builder for our component dependencies, needed here to inject the
* dependencies in the instance
*/
private void createCreatedHook(TypeElement component, MethodSpec.Builder optionsBuilder,
Builder componentJsTypeBuilder, ComponentInjectedDependenciesBuilder dependenciesBuilder)
{
String hasRunCreatedFlagName = "vuegwt$hrc_" + getSuperComponentCount(component);
componentJsTypeBuilder.addField(boolean.class, hasRunCreatedFlagName, Modifier.PUBLIC);
MethodSpec.Builder createdMethodBuilder =
MethodSpec.methodBuilder("vuegwt$created").addModifiers(Modifier.PUBLIC);
// Avoid infinite recursion in case calling the Java constructor calls Vue.js constructor
// This can happen when extending an existing JS component
createdMethodBuilder.addStatement("if ($L) return", hasRunCreatedFlagName);
createdMethodBuilder.addStatement("$L = true", hasRunCreatedFlagName);
injectDependencies(component, dependenciesBuilder, createdMethodBuilder);
callConstructor(component, createdMethodBuilder);
if (hasInterface(processingEnv, component.asType(), HasCreated.class))
{
createdMethodBuilder.addStatement("super.created()");
}
componentJsTypeBuilder.addMethod(createdMethodBuilder.build());
// Register the hook
optionsBuilder.addStatement("options.addHookMethod($S, $S)", "created", "vuegwt$created");
}
示例12: createStaticGetMethod
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Create a static get method that can be used to retrieve an instance of our Factory.
* Factory retrieved using this method do NOT support injection.
* @param vueFactoryClassName The type name of our generated {@link VueFactory}
* @param vueFactoryBuilder The builder to create our {@link VueFactory} class
* @param staticInitParameters Parameters from the init method when called on static
* initialization (when the factory is not injected)
*/
private void createStaticGetMethod(ClassName vueFactoryClassName, Builder vueFactoryBuilder,
List<CodeBlock> staticInitParameters)
{
MethodSpec.Builder getBuilder = MethodSpec
.methodBuilder("get")
.addModifiers(Modifier.STATIC, Modifier.PUBLIC)
.returns(vueFactoryClassName);
getBuilder.beginControlFlow("if ($L == null)", INSTANCE_PROP);
getBuilder.addStatement("$L = new $T()", INSTANCE_PROP, vueFactoryClassName);
getBuilder.addCode("$L.init(", INSTANCE_PROP);
boolean isFirst = true;
for (CodeBlock staticInitParameter : staticInitParameters)
{
if (!isFirst)
getBuilder.addCode(", ");
getBuilder.addCode(staticInitParameter);
isFirst = false;
}
getBuilder.addCode(");");
getBuilder.endControlFlow();
getBuilder.addStatement("return $L", INSTANCE_PROP);
vueFactoryBuilder.addMethod(getBuilder.build());
}
示例13: generateGwtBundle
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
public static void generateGwtBundle(TypeElement sourceType, ClassName bundleClassName,
String bundleMethodName, TypeName resourceType, String resourceExtension, Filer filer)
{
Builder bundleClassBuilder = TypeSpec
.interfaceBuilder(bundleClassName)
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(ClientBundle.class);
bundleClassBuilder.addField(FieldSpec
.builder(bundleClassName, "INSTANCE", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(CodeBlock.of("$T.create($T.class)", GWT.class, bundleClassName))
.build());
String typeElementName = sourceType.getQualifiedName().toString();
String resourcePath = typeElementName.replaceAll("\\.", "/") + "." + resourceExtension;
AnnotationSpec annotationSpec = AnnotationSpec
.builder(Source.class)
.addMember("value", CodeBlock.of("$S", resourcePath))
.build();
bundleClassBuilder.addMethod(MethodSpec
.methodBuilder(bundleMethodName)
.addAnnotation(annotationSpec)
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(resourceType)
.build());
GenerationUtil.toJavaFile(filer, bundleClassBuilder, bundleClassName, sourceType);
}
示例14: generateGetRenderFunction
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Generate the method that returns the body of the render function.
* @param templateBuilder The template builder
* @param result The result from compilation using vue-template-compiler
*/
private void generateGetRenderFunction(Builder templateBuilder,
VueTemplateCompilerResult result)
{
MethodSpec.Builder getRenderFunctionBuilder = MethodSpec
.methodBuilder("getRenderFunction")
.addModifiers(Modifier.PUBLIC)
.returns(String.class)
.addStatement("return $S", result.getRenderFunction());
templateBuilder.addMethod(getRenderFunctionBuilder.build());
}
示例15: generateGetStaticRenderFunctions
import com.squareup.javapoet.TypeSpec.Builder; //导入方法依赖的package包/类
/**
* Generate the method that returns the body of the static render functions.
* @param templateBuilder The template builder
* @param result The result from compilation using vue-template-compiler
*/
private void generateGetStaticRenderFunctions(Builder templateBuilder,
VueTemplateCompilerResult result)
{
CodeBlock.Builder staticFunctions = CodeBlock.builder();
boolean isFirst = true;
for (String staticRenderFunction : result.getStaticRenderFunctions())
{
if (!isFirst)
{
staticFunctions.add(", ");
}
else
{
isFirst = false;
}
staticFunctions.add("$S", staticRenderFunction);
}
MethodSpec.Builder getStaticRenderFunctionsBuilder = MethodSpec
.methodBuilder("getStaticRenderFunctions")
.addModifiers(Modifier.PUBLIC)
.returns(String[].class)
.addStatement("return new String[] { $L }", staticFunctions.build());
templateBuilder.addMethod(getStaticRenderFunctionsBuilder.build());
}