use of com.squareup.javapoet.MethodSpec in project vue-gwt by Axellience.
the class VueComponentFactoryGenerator method createInitMethod.
@Override
protected List<CodeBlock> createInitMethod(TypeElement component, Builder vueFactoryClassBuilder) {
MethodSpec.Builder initBuilder = MethodSpec.methodBuilder("init").addModifiers(Modifier.PROTECTED).addAnnotation(Inject.class);
List<CodeBlock> initParametersCall = new LinkedList<>();
// Get options
initBuilder.addStatement("$T<$T> componentOptions = $T.getOptions()", VueComponentOptions.class, component.asType(), componentJsTypeName(component));
processCustomizeOptions(component, initBuilder, initParametersCall);
// Extend the parent Component
Optional<ClassName> superFactoryType = getSuperComponentType(component).map(GeneratorsNameUtil::componentFactoryName);
if (superFactoryType.isPresent()) {
initBuilder.addParameter(superFactoryType.get(), "superFactory");
initBuilder.addStatement("jsConstructor = superFactory.getJsConstructor().extendJavaComponent($L)", "componentOptions");
initParametersCall.add(CodeBlock.of("$T.get()", superFactoryType.get()));
} else {
initBuilder.addStatement("jsConstructor = $T.extendJavaComponent($L)", Vue.class, "componentOptions");
}
Component componentAnnotation = component.getAnnotation(Component.class);
if (hasInjectedDependencies)
registerDependenciesProvider(component, initBuilder, initParametersCall);
registerLocalComponents(component, initBuilder, initParametersCall);
registerLocalDirectives(componentAnnotation, initBuilder);
MethodSpec initMethod = initBuilder.build();
vueFactoryClassBuilder.addMethod(initMethod);
return initParametersCall;
}
use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableFactoryRenderer method getNullSharedTriggers.
private TypeSpec getNullSharedTriggers(TypeName sharedTriggersInterfaceType) {
TypeSpec.Builder nullSharedTriggersClassBuilder = TypeSpec.classBuilder("NullSharedTriggers").addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT, Modifier.STATIC).addSuperinterface(sharedTriggersInterfaceType);
for (Entry<String, TableDefinition> entry : definitions.entrySet()) {
String name = entry.getKey();
TableDefinition tableDefinition = entry.getValue();
String tableName = getTableName(name);
ClassName tableType = ClassName.get(packageName, tableName);
TypeName rowType = tableType.nestedClass(name + "Row");
TypeName columnType = tableType.nestedClass(name + "ColumnValue");
if (!tableDefinition.toTableMetadata().getColumns().hasDynamicColumns()) {
columnType = ParameterizedTypeName.get(ClassName.get(packageName, tableName + "." + name + "NamedColumnValue"), WildcardTypeName.subtypeOf(Object.class));
}
MethodSpec putMethod = MethodSpec.methodBuilder("put" + name).addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(ParameterizedTypeName.get(ClassName.get(Multimap.class), rowType, WildcardTypeName.subtypeOf(columnType)), "newRows").addComment("do nothing").build();
nullSharedTriggersClassBuilder.addMethod(putMethod);
}
return nullSharedTriggersClassBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableFactoryRenderer method getTableMethod.
private MethodSpec getTableMethod(String name, TableDefinition tableDefinition) {
String tableName = getTableName(name);
String triggerName = tableName + "." + name + "Trigger";
TypeName tableType = ClassName.get(packageName, tableName);
TypeName triggerType = ClassName.get(packageName, triggerName);
MethodSpec.Builder tableGetterMethodBuilder = MethodSpec.methodBuilder("get" + tableName).addModifiers(Modifier.PUBLIC).addParameter(Transaction.class, "t").returns(tableType);
if (tableDefinition.getGenericTableName() != null) {
tableGetterMethodBuilder.addParameter(String.class, "name").addParameter(ArrayTypeName.of(triggerType), "triggers").varargs().addStatement("return $T.of(t, namespace, name, $T.getAllTriggers(t, sharedTriggers, triggers))", tableType, Triggers.class);
} else {
tableGetterMethodBuilder.addParameter(ArrayTypeName.of(triggerType), "triggers").varargs().addStatement("return $T.of(t, namespace, $T.getAllTriggers(t, sharedTriggers, triggers))", tableType, Triggers.class);
}
return tableGetterMethodBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableClassRendererV2 method renderNamedPutColumn.
private MethodSpec renderNamedPutColumn(NamedColumnDescription col) {
MethodSpec.Builder putColumnBuilder = MethodSpec.methodBuilder("put" + VarName(col)).addJavadoc("Takes the row-keys and a value to be inserted at column $L.", VarName(col)).addModifiers(Modifier.PUBLIC);
putColumnBuilder = addParametersFromRowComponents(putColumnBuilder, tableMetadata);
TypeName columnValueType = tableType.nestedClass(VarName(col));
putColumnBuilder.addParameter(getColumnClass(col), col.getLongName());
putColumnBuilder.addStatement("$T row = $T.of($L)", rowType, rowType, getArgumentsFromRowComponents(tableMetadata)).addStatement("t.put(tableRef, $T.toCellValues($T.of(row, $T.of($L))))", ColumnValues.class, ImmutableMultimap.class, columnValueType, col.getLongName());
return putColumnBuilder.build();
}
use of com.squareup.javapoet.MethodSpec in project atlasdb by palantir.
the class TableClassRendererV2 method renderNamedPutAndUpdate.
private List<MethodSpec> renderNamedPutAndUpdate() {
List<MethodSpec> putAndUpdateResults = new ArrayList<>();
for (NamedColumnDescription col : ColumnRenderers.namedColumns(tableMetadata)) {
putAndUpdateResults.add(renderNamedPutColumn(col));
putAndUpdateResults.add(renderNamedUpdateColumn(col));
}
return putAndUpdateResults;
}
Aggregations