Java Code Examples for com.squareup.javapoet.MethodSpec.Builder#addCode()

The following examples show how to use com.squareup.javapoet.MethodSpec.Builder#addCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeUtility.java    From kripton with Apache License 2.0 6 votes vote down vote up
/**
 * generate begin string to translate in code to used in content value or parameter need to be converted in string through String.valueOf
 *
 * @param methodBuilder
 *            the method builder
 * @param typeMirror
 *            the type mirror
 */
public static void beginStringConversion(Builder methodBuilder, TypeName typeMirror) {
	SQLTransform transform = SQLTransformer.lookup(typeMirror);

	switch (transform.getColumnType()) {
	case TEXT:
		return;
	case BLOB:
		methodBuilder.addCode("new String(");
		break;
	case INTEGER:
	case REAL:
		methodBuilder.addCode("String.valueOf(");
		break;
	default:
		break;
	}

}
 
Example 2
Source File: TypeUtility.java    From kripton with Apache License 2.0 6 votes vote down vote up
/**
 * generate end string to translate in code to used in content value or parameter need to be converted in string through String.valueOf
 *
 * @param methodBuilder
 *            the method builder
 * @param typeMirror
 *            the type mirror
 */
public static void endStringConversion(Builder methodBuilder, TypeName typeMirror) {
	SQLTransform transform = SQLTransformer.lookup(typeMirror);

	switch (transform.getColumnType()) {
	case TEXT:
		return;
	case BLOB:
		methodBuilder.addCode(",$T.UTF_8)", StandardCharsets.class);
		break;
	case INTEGER:
	case REAL:
		methodBuilder.addCode(")");
		break;
	default:
		break;
	}
}
 
Example 3
Source File: AbstractPrimitivePrefsTransform.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public void generateWriteProperty(Builder methodBuilder, String editorName, TypeName beanClass, String beanName,
		PrefsProperty property) {
	if (nullable) {
		methodBuilder.beginControlFlow("if ($L!=null) ", getter(beanName, beanClass, property));
	}
	methodBuilder.addCode("$L.put" + PREFS_TYPE + "($S,", editorName, property.getPreferenceKey());

	if (property.hasTypeAdapter()) {
		methodBuilder.addCode("$T.getAdapter($T.class).toData(", PrefsTypeAdapterUtils.class,
				TypeUtility.typeName(property.typeAdapter.adapterClazz));
	}
	methodBuilder.addCode(PREFS_CONVERT + "$L", getter(beanName, beanClass, property));
	if (property.hasTypeAdapter()) {
		methodBuilder.addCode(")");
	}

	methodBuilder.addCode(");\n");

	if (nullable) {
		methodBuilder.endControlFlow();
	}

}
 
Example 4
Source File: WrappedPrefsTransform.java    From kripton with Apache License 2.0 5 votes vote down vote up
@Override
public void generateReadProperty(Builder methodBuilder, String preferenceName, TypeName beanClass, String beanName, PrefsProperty property, boolean readAll, ReadType readType) {
	if (readAll) {
		methodBuilder.beginControlFlow("");
	}

	methodBuilder.addStatement("String temp=$L.getString($S, null)", preferenceName, property.getPreferenceKey());

	if (readAll) {
		methodBuilder.addCode(setter(beanClass, beanName, property) + (!property.isPublicField() && beanName!=null ? "(" : "="));
	} 
	
	switch (readType) {
	case NONE:
		break;
	case RETURN:
		methodBuilder.addCode("return ");
		break;
	case VALUE:
		methodBuilder.addCode("$T _value=",property.getPropertyType().getTypeName());
		break;
	}

	methodBuilder.addCode("($T.hasText(temp)) ? ", StringUtils.class);
	methodBuilder.addCode("$T.read(temp)", utilClazz);
	methodBuilder.addCode(": $L", getter(DEFAULT_BEAN_NAME, beanClass, property));

	if (readAll) {
		methodBuilder.addCode(!property.isPublicField() && beanName!=null ? ")" : "");
	}

	methodBuilder.addCode(";");

	if (readAll) {
		methodBuilder.endControlFlow();
	}
}
 
Example 5
Source File: DoublePrefsTransform.java    From kripton with Apache License 2.0 5 votes vote down vote up
@Override
public void generateReadProperty(Builder methodBuilder, String preferenceName, TypeName beanClass, String beanName, PrefsProperty property, boolean readAll, ReadType readType) {
	if (readAll) {
		methodBuilder.beginControlFlow("");
	}

	methodBuilder.addStatement("String temp=$L.getString($S, null)", preferenceName, property.getPreferenceKey());

	if (readAll) {
		methodBuilder.addCode(setter(beanClass, beanName, property) + (!property.isPublicField() && beanName!=null ? "(" : "="));
	} 
	
	switch (readType) {
	case NONE:
		break;
	case RETURN:
		methodBuilder.addCode("return ");
		break;
	case VALUE:
		methodBuilder.addCode("$T _value=", property.getPropertyType().getTypeName());
		break;
	}

	methodBuilder.addCode("($T.hasText(temp)) ? ", StringUtils.class);
	methodBuilder.addCode("$T.valueOf(temp)", Double.class);
	methodBuilder.addCode(": $L", getter(DEFAULT_BEAN_NAME, beanClass, property));

	if (readAll) {
		methodBuilder.addCode(!property.isPublicField() && beanName!=null ? ")" : "");
	}

	methodBuilder.addCode(";\n");

	if (readAll) {
		methodBuilder.endControlFlow();
	}
}
 
Example 6
Source File: ByteArraySQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateReadValueFromCursor(Builder methodBuilder, SQLiteDaoDefinition daoDefinition, TypeName paramTypeName, String cursorName, String indexName) {
	methodBuilder.addCode("$L.getBlob($L)", cursorName, indexName);		
}
 
Example 7
Source File: BigIntegerSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateWriteProperty2ContentValues(Builder methodBuilder, String beanName, TypeName beanClass, ModelProperty property) {
	methodBuilder.addCode("$L", getter(beanName, beanClass, property));
}
 
Example 8
Source File: ByteArraySQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateDefaultValue(Builder methodBuilder)
{
	methodBuilder.addCode("null");		
}
 
Example 9
Source File: BigDecimalSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateResetProperty(Builder methodBuilder, TypeName beanClass, String beanName,
		ModelProperty property, String cursorName, String indexName) {
	methodBuilder.addCode(setter(beanClass, beanName, property, "null"));
}
 
Example 10
Source File: AbstractGeneratedSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateWriteParam2ContentValues(Builder methodBuilder, SQLiteModelMethod method, String paramName, TypeName paramTypeName, ModelProperty property) {	
	String methodName = method.getParent().generateJava2ContentSerializer(paramTypeName);

	methodBuilder.addCode("$L($L)", methodName, paramName);
}
 
Example 11
Source File: UtilSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateReadPropertyFromCursor(Builder methodBuilder, TypeName beanClass, String beanName, ModelProperty property, String cursorName, String indexName) {
	methodBuilder.addCode(setter(beanClass, beanName, property, "$T.read($L.getString($L))"), utilClazz, cursorName, indexName);
}
 
Example 12
Source File: BigIntegerSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateWriteParam2ContentValues(Builder methodBuilder, SQLiteModelMethod method, String paramName,
		TypeName paramTypeName, ModelProperty property) {
	methodBuilder.addCode("$L", paramName);
}
 
Example 13
Source File: IntegerSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateDefaultValue(Builder methodBuilder) {
	methodBuilder.addCode(defaultValue);
}
 
Example 14
Source File: UtilSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateWriteParam2WhereCondition(Builder methodBuilder, SQLiteModelMethod method, String paramName, TypeName paramTypeName) {
	methodBuilder.addCode("$T.write($L)", utilClazz, paramName);
}
 
Example 15
Source File: EnumSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateResetProperty(Builder methodBuilder, TypeName beanClass, String beanName, ModelProperty property, String cursorName, String indexName) {
	methodBuilder.addCode(setter(beanClass, beanName, property, "null"));
}
 
Example 16
Source File: StringSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateDefaultValue(Builder methodBuilder)
{
	methodBuilder.addCode("null");		
}
 
Example 17
Source File: UtilSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateResetProperty(Builder methodBuilder, TypeName beanClass, String beanName, ModelProperty property, String cursorName, String indexName) {
	methodBuilder.addCode(setter(beanClass, beanName, property, "null"));
}
 
Example 18
Source File: CurrencySQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateWriteProperty2ContentValues(Builder methodBuilder, String beanName, TypeName beanClass, ModelProperty property) {
	methodBuilder.addCode("$T.write($L)", CurrencyUtils.class, getter(beanName, beanClass, property));
}
 
Example 19
Source File: EnumSQLTransform.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateReadPropertyFromCursor(Builder methodBuilder, TypeName beanClass, String beanName, ModelProperty property, String cursorName, String indexName) {
	methodBuilder.addCode(setter(beanClass, beanName, property, "$T.valueOf($L.getString($L))"), property.getPropertyType().getTypeName(), cursorName, indexName);
}
 
Example 20
Source File: WrappedSQLTransformation.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public void generateReadValueFromCursor(Builder methodBuilder, SQLiteDaoDefinition daoDefinition, TypeName paramTypeName, String cursorName, String indexName) {
	methodBuilder.addCode(READ_FROM_CURSOR, cursorName, indexName);
}