Skip to content
Browse files

add mapping generation

  • Loading branch information...
1 parent 801a2e3 commit 899519757aa278897856221948339befe0ddb091 @anton-pogonets anton-pogonets committed
Showing with 334 additions and 57 deletions.
  1. +12 −7 ...c/main/java/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessor.java
  2. +1 −1 ...htorefresh/storio/common/annotations/processor/generate/{ResolverGenerator.java → Generator.java}
  3. +11 −4 ...om/pushtorefresh/storio/contentresolver/annotations/processor/StorIOContentResolverProcessor.java
  4. +10 −3 .../pushtorefresh/storio/contentresolver/annotations/processor/generate/DeleteResolverGenerator.java
  5. +10 −3 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/GetResolverGenerator.java
  6. +59 −0 ...ava/com/pushtorefresh/storio/contentresolver/annotations/processor/generate/MappingGenerator.java
  7. +10 −3 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/PutResolverGenerator.java
  8. +48 −0 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/MappingGeneratorTest.java
  9. +3 −3 ...t-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/ContentResolverTypeMapping.java
  10. +3 −0 storio-sample-app/build.gradle
  11. +4 −16 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/DbModule.java
  12. +7 −0 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/entities/Tweet.java
  13. +4 −1 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/provider/meta/TweetMeta.java
  14. +11 −4 ...or/src/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/StorIOSQLiteProcessor.java
  15. +10 −3 .../java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/DeleteResolverGenerator.java
  16. +10 −3 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGenerator.java
  17. +59 −0 ...rc/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/MappingGenerator.java
  18. +10 −3 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/PutResolverGenerator.java
  19. +49 −0 ...est/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/MappingGeneratorTest.java
  20. +3 −3 storio-sqlite/src/main/java/com/pushtorefresh/storio/sqlite/SQLiteTypeMapping.java
View
19 ...ava/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessor.java
@@ -1,6 +1,6 @@
package com.pushtorefresh.storio.common.annotations.processor;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOColumnMeta;
import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOTypeMeta;
@@ -161,14 +161,16 @@ public boolean process(@Nullable final Set<? extends TypeElement> annotations, @
validateAnnotatedClassesAndColumns(annotatedClasses);
- final ResolverGenerator<TypeMeta> putResolverGenerator = createPutResolver();
- final ResolverGenerator<TypeMeta> getResolverGenerator = createGetResolver();
- final ResolverGenerator<TypeMeta> deleteResolverGenerator = createDeleteResolver();
+ final Generator<TypeMeta> putResolverGenerator = createPutResolver();
+ final Generator<TypeMeta> getResolverGenerator = createGetResolver();
+ final Generator<TypeMeta> deleteResolverGenerator = createDeleteResolver();
+ final Generator<TypeMeta> mappingGenerator = createMapping();
for (TypeMeta typeMeta : annotatedClasses.values()) {
putResolverGenerator.generateJavaFile(typeMeta).writeTo(filer);
getResolverGenerator.generateJavaFile(typeMeta).writeTo(filer);
deleteResolverGenerator.generateJavaFile(typeMeta).writeTo(filer);
+ mappingGenerator.generateJavaFile(typeMeta).writeTo(filer);
}
} catch (ProcessingException e) {
messager.printMessage(ERROR, e.getMessage(), e.element());
@@ -215,11 +217,14 @@ public boolean process(@Nullable final Set<? extends TypeElement> annotations, @
protected abstract Class<? extends Annotation> getColumnAnnotationClass();
@NotNull
- protected abstract ResolverGenerator<TypeMeta> createPutResolver();
+ protected abstract Generator<TypeMeta> createPutResolver();
@NotNull
- protected abstract ResolverGenerator<TypeMeta> createGetResolver();
+ protected abstract Generator<TypeMeta> createGetResolver();
@NotNull
- protected abstract ResolverGenerator<TypeMeta> createDeleteResolver();
+ protected abstract Generator<TypeMeta> createDeleteResolver();
+
+ @NotNull
+ protected abstract Generator<TypeMeta> createMapping();
}
View
2 ...processor/generate/ResolverGenerator.java → ...tations/processor/generate/Generator.java
@@ -5,7 +5,7 @@
import org.jetbrains.annotations.NotNull;
-public interface ResolverGenerator <TypeMeta extends StorIOTypeMeta> {
+public interface Generator<TypeMeta extends StorIOTypeMeta> {
@NotNull
JavaFile generateJavaFile(@NotNull TypeMeta typeMeta);
View
15 ...orefresh/storio/contentresolver/annotations/processor/StorIOContentResolverProcessor.java
@@ -3,12 +3,13 @@
import com.google.auto.service.AutoService;
import com.pushtorefresh.storio.common.annotations.processor.ProcessingException;
import com.pushtorefresh.storio.common.annotations.processor.StorIOAnnotationsProcessor;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType;
import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverColumn;
import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverType;
import com.pushtorefresh.storio.contentresolver.annotations.processor.generate.DeleteResolverGenerator;
import com.pushtorefresh.storio.contentresolver.annotations.processor.generate.GetResolverGenerator;
+import com.pushtorefresh.storio.contentresolver.annotations.processor.generate.MappingGenerator;
import com.pushtorefresh.storio.contentresolver.annotations.processor.generate.PutResolverGenerator;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverTypeMeta;
@@ -288,19 +289,25 @@ protected void validateAnnotatedClassesAndColumns(@NotNull final Map<TypeElement
@NotNull
@Override
- protected ResolverGenerator<StorIOContentResolverTypeMeta> createPutResolver() {
+ protected Generator<StorIOContentResolverTypeMeta> createPutResolver() {
return new PutResolverGenerator();
}
@NotNull
@Override
- protected ResolverGenerator<StorIOContentResolverTypeMeta> createGetResolver() {
+ protected Generator<StorIOContentResolverTypeMeta> createGetResolver() {
return new GetResolverGenerator();
}
@NotNull
@Override
- protected ResolverGenerator<StorIOContentResolverTypeMeta> createDeleteResolver() {
+ protected Generator<StorIOContentResolverTypeMeta> createDeleteResolver() {
return new DeleteResolverGenerator();
}
+
+ @NotNull
+ @Override
+ protected Generator<StorIOContentResolverTypeMeta> createMapping() {
+ return new MappingGenerator();
+ }
}
View
13 ...efresh/storio/contentresolver/annotations/processor/generate/DeleteResolverGenerator.java
@@ -1,6 +1,6 @@
package com.pushtorefresh.storio.contentresolver.annotations.processor.generate;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverTypeMeta;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
@@ -18,13 +18,20 @@
import static javax.lang.model.element.Modifier.PROTECTED;
import static javax.lang.model.element.Modifier.PUBLIC;
-public class DeleteResolverGenerator implements ResolverGenerator<StorIOContentResolverTypeMeta> {
+public class DeleteResolverGenerator implements Generator<StorIOContentResolverTypeMeta> {
+
+ private static final String SUFFIX = "StorIOContentResolverDeleteResolver";
+
+ @NotNull
+ public static String generateName(@NotNull StorIOContentResolverTypeMeta storIOSQLiteTypeMeta) {
+ return storIOSQLiteTypeMeta.simpleName + SUFFIX;
+ }
@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
- final TypeSpec deleteResolver = TypeSpec.classBuilder(storIOContentResolverTypeClassName.simpleName() + "StorIOContentResolverDeleteResolver")
+ 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))
View
13 ...torefresh/storio/contentresolver/annotations/processor/generate/GetResolverGenerator.java
@@ -1,7 +1,7 @@
package com.pushtorefresh.storio.contentresolver.annotations.processor.generate;
import com.pushtorefresh.storio.common.annotations.processor.ProcessingException;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverTypeMeta;
@@ -32,13 +32,20 @@
import static com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType.STRING;
import static javax.lang.model.element.Modifier.PUBLIC;
-public class GetResolverGenerator implements ResolverGenerator<StorIOContentResolverTypeMeta> {
+public class GetResolverGenerator implements Generator<StorIOContentResolverTypeMeta> {
+
+ private static final String SUFFIX = "StorIOContentResolverGetResolver";
+
+ @NotNull
+ public static String generateName(@NotNull StorIOContentResolverTypeMeta storIOSQLiteTypeMeta) {
+ return storIOSQLiteTypeMeta.simpleName + SUFFIX;
+ }
@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
- final TypeSpec getResolver = TypeSpec.classBuilder(storIOContentResolverTypeMeta.simpleName + "StorIOContentResolverGetResolver")
+ final TypeSpec getResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta))
.addJavadoc("Generated resolver for Get Operation\n")
.addModifiers(PUBLIC)
.superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.get", "DefaultGetResolver"), storIOContentResolverTypeClassName))
View
59 ...pushtorefresh/storio/contentresolver/annotations/processor/generate/MappingGenerator.java
@@ -0,0 +1,59 @@
+package com.pushtorefresh.storio.contentresolver.annotations.processor.generate;
+
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
+import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverTypeMeta;
+import com.squareup.javapoet.ClassName;
+import com.squareup.javapoet.JavaFile;
+import com.squareup.javapoet.MethodSpec;
+import com.squareup.javapoet.ParameterizedTypeName;
+import com.squareup.javapoet.TypeSpec;
+
+import org.jetbrains.annotations.NotNull;
+
+import static com.pushtorefresh.storio.common.annotations.processor.generate.Common.INDENT;
+import static javax.lang.model.element.Modifier.PUBLIC;
+
+public class MappingGenerator implements Generator<StorIOContentResolverTypeMeta> {
+
+ public static final String SUFFIX = "ContentResolverTypeMapping";
+
+ @NotNull
+ @Override
+ public JavaFile generateJavaFile(@NotNull StorIOContentResolverTypeMeta storIOSQLiteTypeMeta) {
+ final ClassName storIOSQLiteTypeClassName = ClassName.get(
+ storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
+
+ ClassName superclass = ClassName.get("com.pushtorefresh.storio.contentresolver", SUFFIX);
+ ParameterizedTypeName superclassParametrized =
+ ParameterizedTypeName.get(superclass, storIOSQLiteTypeClassName);
+
+
+ final TypeSpec mapping = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + SUFFIX)
+ .addJavadoc("Generated mapping with collection of resolvers\n")
+ .addModifiers(PUBLIC)
+ .superclass(superclassParametrized)
+ .addMethod(createConstructor(storIOSQLiteTypeMeta))
+ .build();
+
+ return JavaFile
+ .builder(storIOSQLiteTypeMeta.packageName, mapping)
+ .indent(INDENT)
+ .build();
+ }
+
+ @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();
+ }
+}
View
13 ...torefresh/storio/contentresolver/annotations/processor/generate/PutResolverGenerator.java
@@ -1,6 +1,6 @@
package com.pushtorefresh.storio.contentresolver.annotations.processor.generate;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta;
import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverTypeMeta;
import com.squareup.javapoet.ClassName;
@@ -19,13 +19,20 @@
import static javax.lang.model.element.Modifier.PROTECTED;
import static javax.lang.model.element.Modifier.PUBLIC;
-public class PutResolverGenerator implements ResolverGenerator<StorIOContentResolverTypeMeta> {
+public class PutResolverGenerator implements Generator<StorIOContentResolverTypeMeta> {
+
+ private static final String SUFFIX = "StorIOContentResolverPutResolver";
+
+ @NotNull
+ public static String generateName(@NotNull StorIOContentResolverTypeMeta storIOSQLiteTypeMeta) {
+ return storIOSQLiteTypeMeta.simpleName + SUFFIX;
+ }
@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
- final TypeSpec putResolver = TypeSpec.classBuilder(storIOContentResolverTypeMeta.simpleName + "StorIOContentResolverPutResolver")
+ final TypeSpec putResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta))
.addJavadoc("Generated resolver for Put Operation\n")
.addModifiers(PUBLIC)
.superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.put", "DefaultPutResolver"), storIOContentResolverTypeClassName))
View
48 ...torefresh/storio/contentresolver/annotations/processor/generate/MappingGeneratorTest.java
@@ -0,0 +1,48 @@
+package com.pushtorefresh.storio.contentresolver.annotations.processor.generate;
+
+import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverType;
+import com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverTypeMeta;
+import com.squareup.javapoet.JavaFile;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class MappingGeneratorTest {
+ @Test
+ public void generateJavaFile() throws IOException {
+ final StorIOContentResolverType storIOSQLiteType = mock(StorIOContentResolverType.class);
+
+ final StorIOContentResolverTypeMeta storIOSQLiteTypeMeta = new StorIOContentResolverTypeMeta(
+ "TestItem",
+ "com.test",
+ storIOSQLiteType
+ );
+
+ MappingGenerator mappingGenerator = new MappingGenerator();
+ final JavaFile javaFile = mappingGenerator.generateJavaFile(storIOSQLiteTypeMeta);
+ final StringBuilder out = new StringBuilder();
+ javaFile.writeTo(out);
+
+
+ String result = "package com.test;\n" +
+ "\n" +
+ "import com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping;\n" +
+ "\n" +
+ "/**\n" +
+ " * Generated mapping with collection of resolvers\n" +
+ " */\n" +
+ "public class TestItemContentResolverTypeMapping extends ContentResolverTypeMapping<TestItem> {\n" +
+ " public TestItemContentResolverTypeMapping() {\n" +
+ " super(new TestItemStorIOContentResolverPutResolver(),\n" +
+ " new TestItemStorIOContentResolverGetResolver(),\n" +
+ " new TestItemStorIOContentResolverDeleteResolver());\n" +
+ " }\n" +
+ "}\n";
+
+ assertThat(out.toString()).isEqualTo(result);
+ }
+}
View
6 ...er/src/main/java/com/pushtorefresh/storio/contentresolver/ContentResolverTypeMapping.java
@@ -24,9 +24,9 @@
@NonNull
private final DeleteResolver<T> deleteResolver;
- private ContentResolverTypeMapping(@NonNull PutResolver<T> putResolver,
- @NonNull GetResolver<T> getResolver,
- @NonNull DeleteResolver<T> deleteResolver) {
+ protected ContentResolverTypeMapping(@NonNull PutResolver<T> putResolver,
+ @NonNull GetResolver<T> getResolver,
+ @NonNull DeleteResolver<T> deleteResolver) {
this.putResolver = putResolver;
this.getResolver = getResolver;
this.deleteResolver = deleteResolver;
View
3 storio-sample-app/build.gradle
@@ -54,6 +54,9 @@ dependencies {
compile libraries.storIOSQLiteAnnotations
apt libraries.storIOSQLiteAnnotationsProcessor
+ compile libraries.storIOContentResolverAnnotations
+ apt libraries.storIOContentResolverAnnotationsProcessor
+
compile libraries.dagger
apt libraries.daggerCompiler
View
20 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/DbModule.java
@@ -5,14 +5,10 @@
import android.support.annotation.NonNull;
import com.pushtorefresh.storio.sample.db.entities.Tweet;
-import com.pushtorefresh.storio.sample.db.entities.TweetStorIOSQLiteDeleteResolver;
-import com.pushtorefresh.storio.sample.db.entities.TweetStorIOSQLiteGetResolver;
-import com.pushtorefresh.storio.sample.db.entities.TweetStorIOSQLitePutResolver;
+import com.pushtorefresh.storio.sample.db.entities.TweetSQLiteTypeMapping;
import com.pushtorefresh.storio.sample.db.entities.TweetWithUser;
import com.pushtorefresh.storio.sample.db.entities.User;
-import com.pushtorefresh.storio.sample.db.entities.UserStorIOSQLiteDeleteResolver;
-import com.pushtorefresh.storio.sample.db.entities.UserStorIOSQLiteGetResolver;
-import com.pushtorefresh.storio.sample.db.entities.UserStorIOSQLitePutResolver;
+import com.pushtorefresh.storio.sample.db.entities.UserSQLiteTypeMapping;
import com.pushtorefresh.storio.sample.db.resolvers.TweetWithUserDeleteResolver;
import com.pushtorefresh.storio.sample.db.resolvers.TweetWithUserGetResolver;
import com.pushtorefresh.storio.sample.db.resolvers.TweetWithUserPutResolver;
@@ -39,16 +35,8 @@
public StorIOSQLite provideStorIOSQLite(@NonNull SQLiteOpenHelper sqLiteOpenHelper) {
return DefaultStorIOSQLite.builder()
.sqliteOpenHelper(sqLiteOpenHelper)
- .addTypeMapping(Tweet.class, SQLiteTypeMapping.<Tweet>builder()
- .putResolver(new TweetStorIOSQLitePutResolver())
- .getResolver(new TweetStorIOSQLiteGetResolver())
- .deleteResolver(new TweetStorIOSQLiteDeleteResolver())
- .build())
- .addTypeMapping(User.class, SQLiteTypeMapping.<User>builder()
- .putResolver(new UserStorIOSQLitePutResolver())
- .getResolver(new UserStorIOSQLiteGetResolver())
- .deleteResolver(new UserStorIOSQLiteDeleteResolver())
- .build())
+.addTypeMapping(Tweet.class, new TweetSQLiteTypeMapping())
+.addTypeMapping(User.class, new UserSQLiteTypeMapping())
.addTypeMapping(TweetWithUser.class, SQLiteTypeMapping.<TweetWithUser>builder()
.putResolver(new TweetWithUserPutResolver())
.getResolver(new TweetWithUserGetResolver())
View
7 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/entities/Tweet.java
@@ -3,7 +3,10 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverColumn;
+import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverType;
import com.pushtorefresh.storio.sample.db.tables.TweetsTable;
+import com.pushtorefresh.storio.sample.provider.meta.TweetMeta;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
@@ -14,6 +17,7 @@
// Which will generate type mapping code in compile time,
// You just need to link it in your code.
@StorIOSQLiteType(table = TweetsTable.TABLE)
+@StorIOContentResolverType(uri = TweetMeta.URI_STRING)
public class Tweet {
/**
@@ -21,14 +25,17 @@
*/
@Nullable
@StorIOSQLiteColumn(name = TweetsTable.COLUMN_ID, key = true)
+ @StorIOContentResolverColumn(name = TweetsTable.COLUMN_ID, key = true)
Long id;
@NonNull
@StorIOSQLiteColumn(name = TweetsTable.COLUMN_AUTHOR)
+ @StorIOContentResolverColumn(name = TweetsTable.COLUMN_AUTHOR)
String author;
@NonNull
@StorIOSQLiteColumn(name = TweetsTable.COLUMN_CONTENT)
+ @StorIOContentResolverColumn(name = TweetsTable.COLUMN_CONTENT)
String content;
// leave default constructor for AutoGenerated code!
View
5 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/provider/meta/TweetMeta.java
@@ -21,7 +21,10 @@
public class TweetMeta {
@NonNull
- public static final Uri CONTENT_URI = Uri.parse("content://" + SampleContentProvider.AUTHORITY + "/tweets");
+ public static final String URI_STRING = "content://" + SampleContentProvider.AUTHORITY + "/tweets";
+
+ @NonNull
+ public static final Uri CONTENT_URI = Uri.parse(URI_STRING);
@NonNull
public static final PutResolver<Tweet> PUT_RESOLVER = new DefaultPutResolver<Tweet>() {
View
15 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/StorIOSQLiteProcessor.java
@@ -3,12 +3,13 @@
import com.google.auto.service.AutoService;
import com.pushtorefresh.storio.common.annotations.processor.ProcessingException;
import com.pushtorefresh.storio.common.annotations.processor.StorIOAnnotationsProcessor;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn;
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
import com.pushtorefresh.storio.sqlite.annotations.processor.generate.DeleteResolverGenerator;
import com.pushtorefresh.storio.sqlite.annotations.processor.generate.GetResolverGenerator;
+import com.pushtorefresh.storio.sqlite.annotations.processor.generate.MappingGenerator;
import com.pushtorefresh.storio.sqlite.annotations.processor.generate.PutResolverGenerator;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteColumnMeta;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteTypeMeta;
@@ -195,19 +196,25 @@ protected void validateAnnotatedClassesAndColumns(@NotNull Map<TypeElement, Stor
@NotNull
@Override
- protected ResolverGenerator<StorIOSQLiteTypeMeta> createPutResolver() {
+ protected Generator<StorIOSQLiteTypeMeta> createPutResolver() {
return new PutResolverGenerator();
}
@NotNull
@Override
- protected ResolverGenerator<StorIOSQLiteTypeMeta> createGetResolver() {
+ protected Generator<StorIOSQLiteTypeMeta> createGetResolver() {
return new GetResolverGenerator();
}
@NotNull
@Override
- protected ResolverGenerator<StorIOSQLiteTypeMeta> createDeleteResolver() {
+ protected Generator<StorIOSQLiteTypeMeta> createDeleteResolver() {
return new DeleteResolverGenerator();
}
+
+ @NotNull
+ @Override
+ protected Generator<StorIOSQLiteTypeMeta> createMapping() {
+ return new MappingGenerator();
+ }
}
View
13 ...m/pushtorefresh/storio/sqlite/annotations/processor/generate/DeleteResolverGenerator.java
@@ -1,6 +1,6 @@
package com.pushtorefresh.storio.sqlite.annotations.processor.generate;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteTypeMeta;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
@@ -18,13 +18,20 @@
import static javax.lang.model.element.Modifier.PROTECTED;
import static javax.lang.model.element.Modifier.PUBLIC;
-public class DeleteResolverGenerator implements ResolverGenerator<StorIOSQLiteTypeMeta> {
+public class DeleteResolverGenerator implements Generator<StorIOSQLiteTypeMeta> {
+
+ public static final String SUFFIX = "StorIOSQLiteDeleteResolver";
+
+ @NotNull
+ public static String generateName(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
+ return storIOSQLiteTypeMeta.simpleName + SUFFIX;
+ }
@NotNull
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
- final TypeSpec deleteResolver = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + "StorIOSQLiteDeleteResolver")
+ final TypeSpec deleteResolver = TypeSpec.classBuilder(generateName(storIOSQLiteTypeMeta))
.addJavadoc("Generated resolver for Delete Operation\n")
.addModifiers(PUBLIC)
.superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.sqlite.operations.delete", "DefaultDeleteResolver"), storIOSQLiteTypeClassName))
View
13 .../com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGenerator.java
@@ -1,7 +1,7 @@
package com.pushtorefresh.storio.sqlite.annotations.processor.generate;
import com.pushtorefresh.storio.common.annotations.processor.ProcessingException;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteColumnMeta;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteTypeMeta;
@@ -32,13 +32,20 @@
import static com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType.STRING;
import static javax.lang.model.element.Modifier.PUBLIC;
-public class GetResolverGenerator implements ResolverGenerator<StorIOSQLiteTypeMeta> {
+public class GetResolverGenerator implements Generator<StorIOSQLiteTypeMeta> {
+
+ public static final String SUFFIX = "StorIOSQLiteGetResolver";
+
+ @NotNull
+ public static String generateName(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
+ return storIOSQLiteTypeMeta.simpleName + SUFFIX;
+ }
@NotNull
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
- final TypeSpec getResolver = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + "StorIOSQLiteGetResolver")
+ final TypeSpec getResolver = TypeSpec.classBuilder(generateName(storIOSQLiteTypeMeta))
.addJavadoc("Generated resolver for Get Operation\n")
.addModifiers(PUBLIC)
.superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.sqlite.operations.get", "DefaultGetResolver"), storIOSQLiteTypeClassName))
View
59 ...java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/MappingGenerator.java
@@ -0,0 +1,59 @@
+package com.pushtorefresh.storio.sqlite.annotations.processor.generate;
+
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
+import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteTypeMeta;
+import com.squareup.javapoet.ClassName;
+import com.squareup.javapoet.JavaFile;
+import com.squareup.javapoet.MethodSpec;
+import com.squareup.javapoet.ParameterizedTypeName;
+import com.squareup.javapoet.TypeSpec;
+
+import org.jetbrains.annotations.NotNull;
+
+import static com.pushtorefresh.storio.common.annotations.processor.generate.Common.INDENT;
+import static javax.lang.model.element.Modifier.PUBLIC;
+
+public class MappingGenerator implements Generator<StorIOSQLiteTypeMeta> {
+
+ public static final String SUFFIX = "SQLiteTypeMapping";
+
+ @NotNull
+ @Override
+ public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
+ final ClassName storIOSQLiteTypeClassName = ClassName.get(
+ storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
+
+ ClassName superclass = ClassName.get("com.pushtorefresh.storio.sqlite", SUFFIX);
+ ParameterizedTypeName superclassParametrized =
+ ParameterizedTypeName.get(superclass, storIOSQLiteTypeClassName);
+
+
+ final TypeSpec mapping = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + SUFFIX)
+ .addJavadoc("Generated mapping with collection of resolvers\n")
+ .addModifiers(PUBLIC)
+ .superclass(superclassParametrized)
+ .addMethod(createConstructor(storIOSQLiteTypeMeta))
+ .build();
+
+ return JavaFile
+ .builder(storIOSQLiteTypeMeta.packageName, mapping)
+ .indent(INDENT)
+ .build();
+ }
+
+ @NotNull
+ private MethodSpec createConstructor(StorIOSQLiteTypeMeta 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();
+ }
+}
View
13 .../com/pushtorefresh/storio/sqlite/annotations/processor/generate/PutResolverGenerator.java
@@ -1,6 +1,6 @@
package com.pushtorefresh.storio.sqlite.annotations.processor.generate;
-import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator;
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteColumnMeta;
import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteTypeMeta;
import com.squareup.javapoet.ClassName;
@@ -19,13 +19,20 @@
import static javax.lang.model.element.Modifier.PROTECTED;
import static javax.lang.model.element.Modifier.PUBLIC;
-public class PutResolverGenerator implements ResolverGenerator<StorIOSQLiteTypeMeta> {
+public class PutResolverGenerator implements Generator<StorIOSQLiteTypeMeta> {
+
+ public static final String SUFFIX = "StorIOSQLitePutResolver";
+
+ @NotNull
+ public static String generateName(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
+ return storIOSQLiteTypeMeta.simpleName + SUFFIX;
+ }
@NotNull
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
- final TypeSpec putResolver = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + "StorIOSQLitePutResolver")
+ final TypeSpec putResolver = TypeSpec.classBuilder(generateName(storIOSQLiteTypeMeta))
.addJavadoc("Generated resolver for Put Operation\n")
.addModifiers(PUBLIC)
.superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.sqlite.operations.put", "DefaultPutResolver"), storIOSQLiteTypeClassName))
View
49 .../com/pushtorefresh/storio/sqlite/annotations/processor/generate/MappingGeneratorTest.java
@@ -0,0 +1,49 @@
+package com.pushtorefresh.storio.sqlite.annotations.processor.generate;
+
+import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType;
+import com.pushtorefresh.storio.sqlite.annotations.processor.introspection.StorIOSQLiteTypeMeta;
+import com.squareup.javapoet.JavaFile;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class MappingGeneratorTest {
+ @Test
+ public void generateJavaFile() throws IOException {
+ final StorIOSQLiteType storIOSQLiteType = mock(StorIOSQLiteType.class);
+
+ final StorIOSQLiteTypeMeta storIOSQLiteTypeMeta = new StorIOSQLiteTypeMeta(
+ "TestItem",
+ "com.test",
+ storIOSQLiteType
+ );
+
+ MappingGenerator mappingGenerator = new MappingGenerator();
+ final JavaFile javaFile = mappingGenerator.generateJavaFile(storIOSQLiteTypeMeta);
+ final StringBuilder out = new StringBuilder();
+ javaFile.writeTo(out);
+
+
+ String result =
+ "package com.test;\n" +
+ "\n" +
+ "import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping;\n" +
+ "\n" +
+ "/**\n" +
+ " * Generated mapping with collection of resolvers\n" +
+ " */\n" +
+ "public class TestItemSQLiteTypeMapping extends SQLiteTypeMapping<TestItem> {\n" +
+ " public TestItemSQLiteTypeMapping() {\n" +
+ " super(new TestItemStorIOSQLitePutResolver(),\n" +
+ " new TestItemStorIOSQLiteGetResolver(),\n" +
+ " new TestItemStorIOSQLiteDeleteResolver());\n" +
+ " }\n" +
+ "}\n";
+
+ assertThat(out.toString()).isEqualTo(result);
+ }
+}
View
6 storio-sqlite/src/main/java/com/pushtorefresh/storio/sqlite/SQLiteTypeMapping.java
@@ -24,9 +24,9 @@
@NonNull
private final DeleteResolver<T> deleteResolver;
- SQLiteTypeMapping(@NonNull PutResolver<T> putResolver,
- @NonNull GetResolver<T> getResolver,
- @NonNull DeleteResolver<T> deleteResolver) {
+ protected SQLiteTypeMapping(@NonNull PutResolver<T> putResolver,
+ @NonNull GetResolver<T> getResolver,
+ @NonNull DeleteResolver<T> deleteResolver) {
this.putResolver = putResolver;
this.getResolver = getResolver;
this.deleteResolver = deleteResolver;

0 comments on commit 8995197

Please sign in to comment.
Something went wrong with that request. Please try again.