Search in sources :

Example 26 with MethodSpec

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;
}
Also used : GeneratorsNameUtil(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil) MethodSpec(com.squareup.javapoet.MethodSpec) CodeBlock(com.squareup.javapoet.CodeBlock) ClassName(com.squareup.javapoet.ClassName) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) Component(com.axellience.vuegwt.core.annotations.component.Component) LinkedList(java.util.LinkedList)

Example 27 with MethodSpec

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();
}
Also used : WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) ArrayTypeName(com.squareup.javapoet.ArrayTypeName) MethodSpec(com.squareup.javapoet.MethodSpec) ClassName(com.squareup.javapoet.ClassName) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 28 with MethodSpec

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();
}
Also used : WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) ArrayTypeName(com.squareup.javapoet.ArrayTypeName) Transaction(com.palantir.atlasdb.transaction.api.Transaction) MethodSpec(com.squareup.javapoet.MethodSpec)

Example 29 with MethodSpec

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();
}
Also used : TypeName(com.squareup.javapoet.TypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) MethodSpec(com.squareup.javapoet.MethodSpec)

Example 30 with MethodSpec

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;
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) ArrayList(java.util.ArrayList) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Aggregations

MethodSpec (com.squareup.javapoet.MethodSpec)155 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)43 TypeName (com.squareup.javapoet.TypeName)42 ArrayList (java.util.ArrayList)38 ClassName (com.squareup.javapoet.ClassName)34 TypeSpec (com.squareup.javapoet.TypeSpec)31 ParameterSpec (com.squareup.javapoet.ParameterSpec)24 CodeBlock (com.squareup.javapoet.CodeBlock)23 WildcardTypeName (com.squareup.javapoet.WildcardTypeName)20 Nonnull (javax.annotation.Nonnull)17 TypeMirror (javax.lang.model.type.TypeMirror)15 WireField (com.squareup.wire.WireField)14 Field (com.squareup.wire.schema.Field)14 TypeElement (javax.lang.model.element.TypeElement)14 ByteString (okio.ByteString)13 JvmLanguages.builtInAdapterString (com.squareup.wire.schema.internal.JvmLanguages.builtInAdapterString)12 List (java.util.List)11 VariableElement (javax.lang.model.element.VariableElement)11 Utf8String (org.fisco.bcos.web3j.abi.datatypes.Utf8String)11 FieldSpec (com.squareup.javapoet.FieldSpec)10