Permalink
Please sign in to comment.
Showing
with
334 additions
and 57 deletions.
- +12 −7 ...c/main/java/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessor.java
- +1 −1 ...htorefresh/storio/common/annotations/processor/generate/{ResolverGenerator.java → Generator.java}
- +11 −4 ...om/pushtorefresh/storio/contentresolver/annotations/processor/StorIOContentResolverProcessor.java
- +10 −3 .../pushtorefresh/storio/contentresolver/annotations/processor/generate/DeleteResolverGenerator.java
- +10 −3 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/GetResolverGenerator.java
- +59 −0 ...ava/com/pushtorefresh/storio/contentresolver/annotations/processor/generate/MappingGenerator.java
- +10 −3 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/PutResolverGenerator.java
- +48 −0 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/MappingGeneratorTest.java
- +3 −3 ...t-resolver/src/main/java/com/pushtorefresh/storio/contentresolver/ContentResolverTypeMapping.java
- +3 −0 storio-sample-app/build.gradle
- +4 −16 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/DbModule.java
- +7 −0 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/entities/Tweet.java
- +4 −1 storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/provider/meta/TweetMeta.java
- +11 −4 ...or/src/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/StorIOSQLiteProcessor.java
- +10 −3 .../java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/DeleteResolverGenerator.java
- +10 −3 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGenerator.java
- +59 −0 ...rc/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/MappingGenerator.java
- +10 −3 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/PutResolverGenerator.java
- +49 −0 ...est/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/MappingGeneratorTest.java
- +3 −3 storio-sqlite/src/main/java/com/pushtorefresh/storio/sqlite/SQLiteTypeMapping.java
19
...ava/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessor.java
2
...processor/generate/ResolverGenerator.java → ...tations/processor/generate/Generator.java
15
...orefresh/storio/contentresolver/annotations/processor/StorIOContentResolverProcessor.java
13
...efresh/storio/contentresolver/annotations/processor/generate/DeleteResolverGenerator.java
13
...torefresh/storio/contentresolver/annotations/processor/generate/GetResolverGenerator.java
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(); | ||
+ } | ||
+} |
13
...torefresh/storio/contentresolver/annotations/processor/generate/PutResolverGenerator.java
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); | ||
+ } | ||
+} |
6
...er/src/main/java/com/pushtorefresh/storio/contentresolver/ContentResolverTypeMapping.java
3
storio-sample-app/build.gradle
20
storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/DbModule.java
7
storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/db/entities/Tweet.java
5
storio-sample-app/src/main/java/com/pushtorefresh/storio/sample/provider/meta/TweetMeta.java
15
...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/StorIOSQLiteProcessor.java
13
...m/pushtorefresh/storio/sqlite/annotations/processor/generate/DeleteResolverGenerator.java
13
.../com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGenerator.java
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(); | ||
+ } | ||
+} |
13
.../com/pushtorefresh/storio/sqlite/annotations/processor/generate/PutResolverGenerator.java
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); | ||
+ } | ||
+} |
6
storio-sqlite/src/main/java/com/pushtorefresh/storio/sqlite/SQLiteTypeMapping.java
0 comments on commit
8995197