use of org.jetbrains.annotations.NotNull in project storio by pushtorefresh.
the class StorIOTypeMeta method getOrderedColumns.
@NotNull
public Collection<ColumnMeta> getOrderedColumns() {
if (needCreator) {
List<String> params = new ArrayList<String>(columns.size());
List<ColumnMeta> orderedColumns = new ArrayList<ColumnMeta>(Collections.<ColumnMeta>nCopies(columns.size(), null));
//noinspection ConstantConditions
for (VariableElement param : creator.getParameters()) {
params.add(param.getSimpleName().toString());
}
for (ColumnMeta column : columns.values()) {
orderedColumns.set(params.indexOf(column.getRealElementName()), column);
}
return orderedColumns;
} else {
return columns.values();
}
}
use of org.jetbrains.annotations.NotNull in project storio by pushtorefresh.
the class JavaTypeTest method mockTypeMirror.
@NotNull
private static TypeMirror mockTypeMirror(@Nullable TypeKind typeKind, @Nullable String typeName) {
final TypeMirror typeMirror = mock(TypeMirror.class);
when(typeMirror.getKind()).thenReturn(typeKind);
when(typeMirror.toString()).thenReturn(typeName);
return typeMirror;
}
use of org.jetbrains.annotations.NotNull in project storio by pushtorefresh.
the class DeleteResolverGenerator method generateJavaFile.
@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
final TypeSpec deleteResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta)).addJavadoc("Generated resolver for Delete Operation\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.delete", "DefaultDeleteResolver"), storIOContentResolverTypeClassName)).addMethod(createMapToDeleteQueryMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).build();
return JavaFile.builder(storIOContentResolverTypeMeta.packageName, deleteResolver).indent(INDENT).build();
}
use of org.jetbrains.annotations.NotNull in project storio by pushtorefresh.
the class GetResolverGenerator method createMapFromCursorWithCreatorMethodSpec.
@NotNull
private MethodSpec createMapFromCursorWithCreatorMethodSpec(@NotNull StorIOContentResolverTypeMeta storIOContentResolverTypeMeta, @NotNull ClassName storIOSQLiteTypeClassName) {
final MethodSpec.Builder builder = MethodSpec.methodBuilder("mapFromCursor").addJavadoc("{@inheritDoc}\n").addAnnotation(Override.class).addAnnotation(ANDROID_NON_NULL_ANNOTATION_CLASS_NAME).addModifiers(PUBLIC).returns(storIOSQLiteTypeClassName).addParameter(ParameterSpec.builder(ClassName.get("android.database", "Cursor"), "cursor").addAnnotation(ANDROID_NON_NULL_ANNOTATION_CLASS_NAME).build()).addCode("\n");
final StringBuilder paramsBuilder = new StringBuilder();
paramsBuilder.append("(");
boolean first = true;
for (final StorIOContentResolverColumnMeta columnMeta : storIOContentResolverTypeMeta.getOrderedColumns()) {
final String columnIndex = "cursor.getColumnIndex(\"" + columnMeta.storIOColumn.name() + "\")";
final JavaType javaType = columnMeta.javaType;
final String getFromCursor = getFromCursorString(columnMeta, javaType, columnIndex);
final TypeName name = TypeName.get(((ExecutableElement) columnMeta.element).getReturnType());
final boolean isBoxed = javaType.isBoxedType();
if (isBoxed) {
// otherwise -> if primitive and value from cursor null -> fail early
builder.addStatement("$T $L = null", name, columnMeta.getRealElementName());
builder.beginControlFlow("if (!cursor.isNull($L))", columnIndex);
builder.addStatement("$L = cursor.$L", columnMeta.getRealElementName(), getFromCursor);
builder.endControlFlow();
} else {
builder.addStatement("$T $L = cursor.$L", name, columnMeta.getRealElementName(), getFromCursor);
}
if (!first) {
paramsBuilder.append(", ");
}
first = false;
paramsBuilder.append(columnMeta.getRealElementName());
}
paramsBuilder.append(")");
builder.addCode("\n");
if (storIOContentResolverTypeMeta.creator.getKind() == ElementKind.CONSTRUCTOR) {
builder.addStatement("$T object = new $T" + paramsBuilder.toString(), storIOSQLiteTypeClassName, storIOSQLiteTypeClassName);
} else {
builder.addStatement("$T object = $T.$L", storIOSQLiteTypeClassName, storIOSQLiteTypeClassName, storIOContentResolverTypeMeta.creator.getSimpleName() + paramsBuilder.toString());
}
return builder.addCode("\n").addStatement("return object").build();
}
use of org.jetbrains.annotations.NotNull in project storio by pushtorefresh.
the class MappingGenerator method createConstructor.
@NotNull
private MethodSpec createConstructor(StorIOContentResolverTypeMeta storIOSQLiteTypeMeta) {
final ClassName putResolver = ClassName.get(storIOSQLiteTypeMeta.packageName, PutResolverGenerator.generateName(storIOSQLiteTypeMeta));
final ClassName getResolver = ClassName.get(storIOSQLiteTypeMeta.packageName, GetResolverGenerator.generateName(storIOSQLiteTypeMeta));
final ClassName deleteResolver = ClassName.get(storIOSQLiteTypeMeta.packageName, DeleteResolverGenerator.generateName(storIOSQLiteTypeMeta));
return MethodSpec.constructorBuilder().addModifiers(PUBLIC).addStatement("super(new $T(),\nnew $T(),\nnew $T())", putResolver, getResolver, deleteResolver).build();
}
Aggregations