Search in sources :

Example 56 with MethodSpec

use of com.squareup.javapoet.MethodSpec in project kripton by xcesco.

the class SqlInsertBuilder method generate.

/**
 * @param elementUtils
 * @param builder
 * @param method
 */
public static void generate(TypeSpec.Builder classBuilder, SQLiteModelMethod method) {
    InsertType insertResultType = detectInsertType(method);
    // if true, field must be associate to ben attributes
    TypeName returnType = method.getReturnClass();
    AssertKripton.failWithInvalidMethodSignException(insertResultType == null, method);
    // generate method code
    MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(method.getName()).addAnnotation(Override.class).addModifiers(Modifier.PUBLIC);
    ParameterSpec parameterSpec;
    for (Pair<String, TypeName> item : method.getParameters()) {
        parameterSpec = ParameterSpec.builder(item.value1, item.value0).build();
        methodBuilder.addParameter(parameterSpec);
    }
    methodBuilder.returns(returnType);
    // fail if we use jql to INSERT_BEAN with operation of INSERT-FOR-SELECT
    // AssertKripton.failWithInvalidMethodSignException(insertResultType ==
    // InsertType.INSERT_BEAN && method.jql.containsSelectOperation, method,
    // "INSERT-FROM-SELECT SQL can not be used with method sign");
    // generate inner code
    insertResultType.generate(classBuilder, methodBuilder, method, returnType);
    MethodSpec methodSpec = methodBuilder.build();
    classBuilder.addMethod(methodSpec);
    if (method.contentProviderEntryPathEnabled) {
        // we need to generate insert for content provider to
        generateInsertForContentProvider(classBuilder, method, insertResultType);
    }
}
Also used : TypeName(com.squareup.javapoet.TypeName) MethodSpec(com.squareup.javapoet.MethodSpec) ParameterSpec(com.squareup.javapoet.ParameterSpec)

Example 57 with MethodSpec

use of com.squareup.javapoet.MethodSpec in project kripton by xcesco.

the class BindM2MBuilder method generateInsert.

private void generateInsert(M2MEntity entity, String packageName) {
    if (!isMethodAlreadyDefined(entity, "insert")) {
        // @formatter:off
        MethodSpec methodSpec = MethodSpec.methodBuilder("insert").addModifiers(Modifier.PUBLIC).addModifiers(Modifier.ABSTRACT).addAnnotation(AnnotationSpec.builder(BindSqlInsert.class).build()).addParameter(ParameterSpec.builder(TypeUtility.className(packageName, entity.name), "bean").addAnnotation(AnnotationSpec.builder(BindSqlParam.class).addMember("value", "$S", "bean").build()).build()).returns(Integer.TYPE).build();
        // @formatter:on
        classBuilder.addMethod(methodSpec);
    }
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) BindSqlParam(com.abubusoft.kripton.android.annotation.BindSqlParam) BindSqlInsert(com.abubusoft.kripton.android.annotation.BindSqlInsert)

Example 58 with MethodSpec

use of com.squareup.javapoet.MethodSpec in project kripton by xcesco.

the class BindM2MBuilder method generateDeletes.

private void generateDeletes(M2MEntity entity, String packageName) {
    String idPart = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, entity.idName);
    String methodName = "";
    String workId = "";
    methodName = "deleteBy" + idPart;
    if (!isMethodAlreadyDefined(entity, methodName)) {
        // @formatter:off
        MethodSpec methodSpec = MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.ABSTRACT).addAnnotation(AnnotationSpec.builder(BindSqlDelete.class).addMember("where", "$S", entity.idName + "=${" + entity.idName + "}").build()).addParameter(ParameterSpec.builder(Long.TYPE, entity.idName).addAnnotation(AnnotationSpec.builder(BindSqlParam.class).addMember("value", "$S", entity.idName).build()).build()).returns(Integer.TYPE).build();
        // @formatter:on
        classBuilder.addMethod(methodSpec);
    }
    methodName = entity.entity1Name.simpleName() + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, entity.idName);
    workId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, methodName);
    methodName = "deleteBy" + methodName;
    if (!isMethodAlreadyDefined(entity, methodName)) {
        // @formatter:off
        MethodSpec methodSpec = MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.ABSTRACT).addAnnotation(AnnotationSpec.builder(BindSqlDelete.class).addMember("where", "$S", workId + "=${" + workId + "}").build()).addParameter(ParameterSpec.builder(Long.TYPE, workId).addAnnotation(AnnotationSpec.builder(BindSqlParam.class).addMember("value", "$S", workId).build()).build()).returns(Integer.TYPE).build();
        // @formatter:on
        classBuilder.addMethod(methodSpec);
    }
    methodName = entity.entity2Name.simpleName() + CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, entity.idName);
    workId = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, methodName);
    methodName = "deleteBy" + methodName;
    if (!isMethodAlreadyDefined(entity, methodName)) {
        // @formatter:off
        MethodSpec methodSpec = MethodSpec.methodBuilder(methodName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.ABSTRACT).addAnnotation(AnnotationSpec.builder(BindSqlDelete.class).addMember("where", "$S", workId + "=${" + workId + "}").build()).addParameter(ParameterSpec.builder(Long.TYPE, workId).addAnnotation(AnnotationSpec.builder(BindSqlParam.class).addMember("value", "$S", workId).build()).build()).returns(Integer.TYPE).build();
        // @formatter:on
        classBuilder.addMethod(methodSpec);
    }
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec) BindSqlParam(com.abubusoft.kripton.android.annotation.BindSqlParam)

Example 59 with MethodSpec

use of com.squareup.javapoet.MethodSpec in project BGABadgeView-Android by bingoogolapple.

the class BGABadgeProcessor method getBadgeViewHelper.

private void getBadgeViewHelper(TypeSpec.Builder typeBuilder) {
    MethodSpec methodSpec = MethodSpec.methodBuilder("getBadgeViewHelper").addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addStatement("return mBadgeViewHelper").returns(ClassName.get(PACKAGE_NAME, "BGABadgeViewHelper")).build();
    typeBuilder.addMethod(methodSpec);
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec)

Example 60 with MethodSpec

use of com.squareup.javapoet.MethodSpec in project BGABadgeView-Android by bingoogolapple.

the class BGABadgeProcessor method isDraggable.

private void isDraggable(TypeSpec.Builder typeBuilder) {
    MethodSpec methodSpec = MethodSpec.methodBuilder("isDraggable").addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addStatement("return mBadgeViewHelper.isDraggable()").returns(boolean.class).build();
    typeBuilder.addMethod(methodSpec);
}
Also used : MethodSpec(com.squareup.javapoet.MethodSpec)

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