use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableFactoryRenderer method getV2TableMethod.
private MethodSpec getV2TableMethod(String name, TableDefinition tableDefinition) {
String tableName = getV2TableName(name);
TypeName tableType = ClassName.get(packageName, tableName);
MethodSpec.Builder tableGetterMethodBuilder = MethodSpec.methodBuilder("get" + tableName).addModifiers(Modifier.PUBLIC).addParameter(Transaction.class, "t").returns(tableType).addStatement("return $T.of(t, namespace)", tableType);
return tableGetterMethodBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableFactoryRenderer method getConstructors.
private List<MethodSpec> getConstructors() {
List<MethodSpec> results = new ArrayList<>();
TypeName functionOfTransactionAndTriggersType = ParameterizedTypeName.get(ClassName.get(Function.class), WildcardTypeName.supertypeOf(Transaction.class), sharedTriggersType);
TypeName sharedTriggersListType = ParameterizedTypeName.get(ClassName.get(List.class), functionOfTransactionAndTriggersType);
results.add(factoryBaseBuilder().addParameter(ParameterizedTypeName.get(ClassName.get(List.class), functionOfTransactionAndTriggersType), "sharedTriggers").addParameter(Namespace.class, "namespace").addStatement("return new $T($L, $L)", tableFactoryType, "sharedTriggers", "namespace").build());
results.add(factoryBaseBuilder().addParameter(sharedTriggersListType, "sharedTriggers").addStatement("return new $T($L, $L)", tableFactoryType, "sharedTriggers", "defaultNamespace").build());
results.add(factoryBaseBuilder().addParameter(Namespace.class, "namespace").addStatement("return of($T.<$T>of(), $L)", ImmutableList.class, functionOfTransactionAndTriggersType, "namespace").build());
results.add(factoryBaseBuilder().addStatement("return of($T.<$T>of(), $L)", ImmutableList.class, functionOfTransactionAndTriggersType, "defaultNamespace").build());
results.add(MethodSpec.constructorBuilder().addModifiers(Modifier.PRIVATE).addParameter(sharedTriggersListType, "sharedTriggers").addParameter(Namespace.class, "namespace").addStatement("this.$L = $L", "sharedTriggers", "sharedTriggers").addStatement("this.$L = $L", "namespace", "namespace").build());
return results;
}
use of com.squareup.javapoet.MethodSpec in project AndroidLife by CaMnter.
the class SaveTestProcessor method process.
/**
* {@inheritDoc}
*/
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
MethodSpec main = MethodSpec.methodBuilder("main").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(void.class).addParameter(String[].class, "args").addStatement("$T.out.println($S)", System.class, "Save you from anything").build();
TypeSpec saveTest = TypeSpec.classBuilder("SaveTest").addModifiers(Modifier.PUBLIC, Modifier.FINAL).addMethod(main).build();
JavaFile javaFile = JavaFile.builder("com.camnter.annotation.processor.output", saveTest).build();
try {
javaFile.writeTo(this.processingEnv.getFiler());
} catch (IOException e) {
// e.printStackTrace();
}
return false;
}
use of com.squareup.javapoet.MethodSpec in project AndroidLife by CaMnter.
the class RouterManagerClass method getSmartRouterMethod.
/**
* public static SmartRouter getSmartRouter(@NonNull final String host) {
* - return new SmartRouter(host);
* }
*
* @return List<MethodSpec>
*/
public List<MethodSpec> getSmartRouterMethod() {
final List<MethodSpec> getSmartRouterMethods = new ArrayList<>();
for (RouterClass routerClass : this.routerClassHashMap.values()) {
final TypeName routerTypeName = ClassName.get(routerClass.getPackageName(), routerClass.getSimpleName() + Const.SMART_ROUTER_SUFFIX);
final MethodSpec.Builder getSmartRouterMethodBuilder = MethodSpec.methodBuilder("get" + routerClass.getSimpleName() + "SmartRouter").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(routerTypeName).addParameter(createNonNullParameter(ClassName.get(String.class), "host", Modifier.FINAL)).addCode(" return new $T(host);\n", routerTypeName);
getSmartRouterMethods.add(getSmartRouterMethodBuilder.build());
}
return getSmartRouterMethods;
}
use of com.squareup.javapoet.MethodSpec in project Rocket by mozilla-tw.
the class RequestBuilderGenerator method generateGeneratedRequestOptionEquivalent.
/**
* Generates a particular method with an equivalent name and arguments to the given method
* from the generated {@link com.bumptech.glide.request.BaseRequestBuilder} subclass.
*/
private MethodSpec generateGeneratedRequestOptionEquivalent(MethodSpec requestOptionMethod) {
CodeBlock callRequestOptionsMethod = CodeBlock.builder().add(".$N(", requestOptionMethod.name).add(FluentIterable.from(requestOptionMethod.parameters).transform(new Function<ParameterSpec, String>() {
@Override
public String apply(ParameterSpec input) {
return input.name;
}
}).join(Joiner.on(", "))).add(");\n").build();
MethodSpec.Builder result = MethodSpec.methodBuilder(requestOptionMethod.name).addJavadoc(processorUtil.generateSeeMethodJavadoc(requestOptionsClassName, requestOptionMethod)).addModifiers(Modifier.PUBLIC).varargs(requestOptionMethod.varargs).addAnnotations(FluentIterable.from(requestOptionMethod.annotations).filter(new Predicate<AnnotationSpec>() {
@Override
public boolean apply(AnnotationSpec input) {
return !input.type.equals(TypeName.get(Override.class)) && // non-final to allow for mocking.
!input.type.equals(TypeName.get(SafeVarargs.class)) && // autoClone() in RequestBuilder.
!input.type.equals(CHECK_RESULT_CLASS_NAME);
}
}).toList()).addTypeVariables(requestOptionMethod.typeVariables).addParameters(requestOptionMethod.parameters).returns(generatedRequestBuilderOfTranscodeType).beginControlFlow("if (getMutableOptions() instanceof $T)", requestOptionsClassName).addCode("this.requestOptions = (($T) getMutableOptions())", requestOptionsClassName).addCode(callRequestOptionsMethod).nextControlFlow("else").addCode(CodeBlock.of("this.requestOptions = new $T().apply(this.requestOptions)", requestOptionsClassName)).addCode(callRequestOptionsMethod).endControlFlow().addStatement("return this");
if (requestOptionMethod.annotations.contains(AnnotationSpec.builder(SafeVarargs.class).build())) {
result.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unchecked").addMember("value", "$S", "varargs").build());
}
return result.build();
}
Aggregations