Search in sources :

Example 26 with NotNull

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();
    }
}
Also used : ArrayList(java.util.ArrayList) VariableElement(javax.lang.model.element.VariableElement) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with NotNull

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;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) NotNull(org.jetbrains.annotations.NotNull)

Example 28 with NotNull

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();
}
Also used : ClassName(com.squareup.javapoet.ClassName) TypeSpec(com.squareup.javapoet.TypeSpec) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with NotNull

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();
}
Also used : JavaType(com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) MethodSpec(com.squareup.javapoet.MethodSpec) StorIOContentResolverColumnMeta(com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta) Common.getFromCursorString(com.pushtorefresh.storio.common.annotations.processor.generate.Common.getFromCursorString) NotNull(org.jetbrains.annotations.NotNull)

Example 30 with NotNull

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();
}
Also used : ClassName(com.squareup.javapoet.ClassName) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)6249 VirtualFile (com.intellij.openapi.vfs.VirtualFile)829 ArrayList (java.util.ArrayList)617 Project (com.intellij.openapi.project.Project)540 File (java.io.File)531 PsiElement (com.intellij.psi.PsiElement)461 Nullable (org.jetbrains.annotations.Nullable)391 Module (com.intellij.openapi.module.Module)315 PsiFile (com.intellij.psi.PsiFile)296 List (java.util.List)272 IOException (java.io.IOException)263 TextRange (com.intellij.openapi.util.TextRange)245 ContainerUtil (com.intellij.util.containers.ContainerUtil)170 Document (com.intellij.openapi.editor.Document)158 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)154 ASTNode (com.intellij.lang.ASTNode)145 Pair (com.intellij.openapi.util.Pair)141 StringUtil (com.intellij.openapi.util.text.StringUtil)133 Logger (com.intellij.openapi.diagnostic.Logger)127 Editor (com.intellij.openapi.editor.Editor)120