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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations