Permalink
Please sign in to comment.
Showing
with
611 additions
and 824 deletions.
- +2 −1 build.gradle
- +3 −2 settings.gradle
- +16 −0 storio-common-annotations-processor/build.gradle
- +3 −0 storio-common-annotations-processor/gradle.properties
- +2 −2 ...sor/src/main/java/com/pushtorefresh/storio/common}/annotations/processor/ProcessingException.java
- +225 −0 ...c/main/java/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessor.java
- +10 −0 ...rocessor/src/main/java/com/pushtorefresh/storio/common/annotations/processor/generate/Common.java
- +12 −0 ...c/main/java/com/pushtorefresh/storio/common/annotations/processor/generate/ResolverGenerator.java
- +1 −1 .../src/main/java/com/pushtorefresh/storio/common}/annotations/processor/introspection/JavaType.java
- +73 −0 ...in/java/com/pushtorefresh/storio/common/annotations/processor/introspection/StorIOColumnMeta.java
- +67 −0 ...main/java/com/pushtorefresh/storio/common/annotations/processor/introspection/StorIOTypeMeta.java
- +15 −15 .../test/java/com/pushtorefresh/storio/common}/annotations/processor/introspection/JavaTypeTest.java
- +1 −0 storio-content-resolver-annotations-processor/build.gradle
- +0 −31 ...main/java/com/pushtorefresh/storio/contentresolver/annotations/processor/ProcessingException.java
- +40 −112 ...om/pushtorefresh/storio/contentresolver/annotations/processor/StorIOContentResolverProcessor.java
- +0 −10 ...src/main/java/com/pushtorefresh/storio/contentresolver/annotations/processor/generate/Common.java
- +5 −4 .../pushtorefresh/storio/contentresolver/annotations/processor/generate/DeleteResolverGenerator.java
- +21 −20 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/GetResolverGenerator.java
- +7 −6 ...com/pushtorefresh/storio/contentresolver/annotations/processor/generate/PutResolverGenerator.java
- +3 −3 .../java/com/pushtorefresh/storio/contentresolver/annotations/processor/generate/QueryGenerator.java
- +0 −62 ...n/java/com/pushtorefresh/storio/contentresolver/annotations/processor/introspection/JavaType.java
- +5 −58 ...h/storio/contentresolver/annotations/processor/introspection/StorIOContentResolverColumnMeta.java
- +4 −56 ...esh/storio/contentresolver/annotations/processor/introspection/StorIOContentResolverTypeMeta.java
- +1 −1 ...pushtorefresh/storio/contentresolver/annotations/processor/generate/GetResolverGeneratorTest.java
- +0 −126 ...va/com/pushtorefresh/storio/contentresolver/annotations/processor/introspection/JavaTypeTest.java
- +1 −0 storio-sqlite-annotations-processor/build.gradle
- +39 −157 ...or/src/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/StorIOSQLiteProcessor.java
- +0 −10 ...rocessor/src/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/Common.java
- +5 −4 .../java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/DeleteResolverGenerator.java
- +21 −20 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGenerator.java
- +7 −6 ...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/PutResolverGenerator.java
- +3 −3 .../src/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/QueryGenerator.java
- +10 −57 ...a/com/pushtorefresh/storio/sqlite/annotations/processor/introspection/StorIOSQLiteColumnMeta.java
- +8 −56 ...ava/com/pushtorefresh/storio/sqlite/annotations/processor/introspection/StorIOSQLiteTypeMeta.java
- +1 −1 ...java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGeneratorTest.java
3
build.gradle
5
settings.gradle
16
storio-common-annotations-processor/build.gradle
@@ -0,0 +1,16 @@ | ||
+apply plugin: 'java' | ||
+ | ||
+targetCompatibility = '1.6' | ||
+sourceCompatibility = '1.6' | ||
+ | ||
+dependencies { | ||
+ compile libraries.intellijAnnotations | ||
+ compile libraries.autoService | ||
+ compile libraries.javaPoet | ||
+ | ||
+ testCompile libraries.junit | ||
+ testCompile libraries.assertJ | ||
+ testCompile libraries.mockitoCore | ||
+} | ||
+ | ||
+apply from: '../gradle/publish-java-lib.gradle' |
3
storio-common-annotations-processor/gradle.properties
@@ -0,0 +1,3 @@ | ||
+POM_NAME=common-annotations-processor | ||
+POM_ARTIFACT_ID=common-annotations-processor | ||
+POM_PACKAGING=jar |
4
...ations/processor/ProcessingException.java → ...ations/processor/ProcessingException.java
225
...ava/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessor.java
@@ -0,0 +1,225 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor; | ||
+ | ||
+import com.pushtorefresh.storio.common.annotations.processor.generate.ResolverGenerator; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOColumnMeta; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOTypeMeta; | ||
+ | ||
+import org.jetbrains.annotations.NotNull; | ||
+import org.jetbrains.annotations.Nullable; | ||
+ | ||
+import java.lang.annotation.Annotation; | ||
+import java.util.Collections; | ||
+import java.util.HashMap; | ||
+import java.util.Map; | ||
+import java.util.Set; | ||
+ | ||
+import javax.annotation.processing.AbstractProcessor; | ||
+import javax.annotation.processing.Filer; | ||
+import javax.annotation.processing.Messager; | ||
+import javax.annotation.processing.ProcessingEnvironment; | ||
+import javax.annotation.processing.RoundEnvironment; | ||
+import javax.lang.model.SourceVersion; | ||
+import javax.lang.model.element.Element; | ||
+import javax.lang.model.element.TypeElement; | ||
+import javax.lang.model.util.Elements; | ||
+ | ||
+import static javax.lang.model.element.ElementKind.CLASS; | ||
+import static javax.lang.model.element.Modifier.FINAL; | ||
+import static javax.lang.model.element.Modifier.PRIVATE; | ||
+import static javax.tools.Diagnostic.Kind.ERROR; | ||
+ | ||
+/** | ||
+ * Base annotation processor for StorIO | ||
+ * <p> | ||
+ * It'll process annotations to generate StorIO Object-Mapping | ||
+ * <p> | ||
+ * Addition: Annotation Processor should work fast and be optimized because it's part of compilation | ||
+ * We don't want to annoy developers, who use StorIO | ||
+ */ | ||
+// Generate file with annotation processor declaration via another Annotation Processor! | ||
+public abstract class StorIOAnnotationsProcessor | ||
+ <TypeMeta extends StorIOTypeMeta, ColumnMeta extends StorIOColumnMeta> | ||
+ extends AbstractProcessor { | ||
+ | ||
+ private Filer filer; | ||
+ private Elements elementUtils; | ||
+ private Messager messager; | ||
+ | ||
+ /** | ||
+ * Processes class annotations | ||
+ * | ||
+ * @param roundEnvironment environment | ||
+ * @return non-null unmodifiable map(element, typeMeta) | ||
+ */ | ||
+ @NotNull | ||
+ private Map<TypeElement, TypeMeta> processAnnotatedClasses(@NotNull final RoundEnvironment roundEnvironment, @NotNull final Elements elementUtils) { | ||
+ final Set<? extends Element> elementsAnnotatedWithStorIOType | ||
+ = roundEnvironment.getElementsAnnotatedWith(getTypeAnnotationClass()); | ||
+ | ||
+ final Map<TypeElement, TypeMeta> results | ||
+ = new HashMap<TypeElement, TypeMeta>(elementsAnnotatedWithStorIOType.size()); | ||
+ | ||
+ for (final Element annotatedElement : elementsAnnotatedWithStorIOType) { | ||
+ final TypeElement classElement = validateAnnotatedClass(annotatedElement); | ||
+ final TypeMeta typeMeta = processAnnotatedClass(classElement, elementUtils); | ||
+ results.put(classElement, typeMeta); | ||
+ } | ||
+ | ||
+ return Collections.unmodifiableMap(results); | ||
+ } | ||
+ | ||
+ /** | ||
+ * Checks that annotated element satisfies all required conditions | ||
+ * | ||
+ * @param annotatedElement an annotated type | ||
+ * @return {@link TypeElement} object | ||
+ */ | ||
+ @NotNull | ||
+ private TypeElement validateAnnotatedClass(@NotNull final Element annotatedElement) { | ||
+ // we expect here that annotatedElement is Class, annotation requires that via @Target | ||
+ final TypeElement annotatedTypeElement = (TypeElement) annotatedElement; | ||
+ | ||
+ if (annotatedTypeElement.getModifiers().contains(PRIVATE)) { | ||
+ throw new ProcessingException( | ||
+ annotatedElement, | ||
+ getTypeAnnotationClass().getSimpleName() + " can not be applied to private class: " + annotatedTypeElement.getQualifiedName() | ||
+ ); | ||
+ } | ||
+ | ||
+ return annotatedTypeElement; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Checks that element annotated with {@link StorIOColumnMeta} satisfies all required conditions | ||
+ * | ||
+ * @param annotatedField an annotated field | ||
+ */ | ||
+ protected void validateAnnotatedField(@NotNull final Element annotatedField) { | ||
+ // we expect here that annotatedElement is Field, annotation requires that via @Target | ||
+ | ||
+ final Element enclosingElement = annotatedField.getEnclosingElement(); | ||
+ | ||
+ if (!enclosingElement.getKind().equals(CLASS)) { | ||
+ throw new ProcessingException( | ||
+ annotatedField, | ||
+ "Please apply " + getTypeAnnotationClass().getSimpleName() + " to fields of class: " + annotatedField.getSimpleName() | ||
+ ); | ||
+ } | ||
+ | ||
+ if (enclosingElement.getAnnotation(getTypeAnnotationClass()) == null) { | ||
+ throw new ProcessingException( | ||
+ annotatedField, | ||
+ "Please annotate class " + enclosingElement.getSimpleName() + " with " + getTypeAnnotationClass().getSimpleName() | ||
+ ); | ||
+ } | ||
+ | ||
+ if (annotatedField.getModifiers().contains(PRIVATE)) { | ||
+ throw new ProcessingException( | ||
+ annotatedField, | ||
+ getColumnAnnotationClass().getSimpleName() + " can not be applied to private field: " + annotatedField.getSimpleName() | ||
+ ); | ||
+ } | ||
+ | ||
+ if (annotatedField.getModifiers().contains(FINAL)) { | ||
+ throw new ProcessingException( | ||
+ annotatedField, | ||
+ getColumnAnnotationClass().getSimpleName() + " can not be applied to final field: " + annotatedField.getSimpleName() | ||
+ ); | ||
+ } | ||
+ } | ||
+ | ||
+ @Override | ||
+ public synchronized void init(@NotNull final ProcessingEnvironment processingEnv) { | ||
+ super.init(processingEnv); | ||
+ filer = processingEnv.getFiler(); | ||
+ elementUtils = processingEnv.getElementUtils(); // why class name is "Elements" but method "getElementUtils()", OKAY.. | ||
+ messager = processingEnv.getMessager(); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public SourceVersion getSupportedSourceVersion() { | ||
+ return SourceVersion.latestSupported(); | ||
+ } | ||
+ | ||
+ //endregion | ||
+ | ||
+ /** | ||
+ * For those who don't familiar with Annotation Processing API — this is the main method of Annotation Processor lifecycle | ||
+ * <p> | ||
+ * It will be called after Java Compiler will find lang elements annotated with annotations from {@link #getSupportedAnnotationTypes()} | ||
+ * | ||
+ * @param annotations set of annotations | ||
+ * @param roundEnv environment of current processing round | ||
+ * @return true if annotation processor should not be invoked in next rounds of annotation processing, false otherwise | ||
+ */ | ||
+ @Override | ||
+ public boolean process(@Nullable final Set<? extends TypeElement> annotations, @NotNull final RoundEnvironment roundEnv) { | ||
+ try { | ||
+ final Map<TypeElement, TypeMeta> annotatedClasses = processAnnotatedClasses(roundEnv, elementUtils); | ||
+ | ||
+ processAnnotatedFields(roundEnv, annotatedClasses); | ||
+ | ||
+ validateAnnotatedClassesAndColumns(annotatedClasses); | ||
+ | ||
+ final ResolverGenerator<TypeMeta> putResolverGenerator = createPutResolver(); | ||
+ final ResolverGenerator<TypeMeta> getResolverGenerator = createGetResolver(); | ||
+ final ResolverGenerator<TypeMeta> deleteResolverGenerator = createDeleteResolver(); | ||
+ | ||
+ for (TypeMeta typeMeta : annotatedClasses.values()) { | ||
+ putResolverGenerator.generateJavaFile(typeMeta).writeTo(filer); | ||
+ getResolverGenerator.generateJavaFile(typeMeta).writeTo(filer); | ||
+ deleteResolverGenerator.generateJavaFile(typeMeta).writeTo(filer); | ||
+ } | ||
+ } catch (ProcessingException e) { | ||
+ messager.printMessage(ERROR, e.getMessage(), e.element()); | ||
+ } catch (Exception e) { | ||
+ messager.printMessage(ERROR, "Problem occurred with StorIOProcessor: " + e.getMessage()); | ||
+ } | ||
+ | ||
+ return true; | ||
+ } | ||
+ | ||
+ /** | ||
+ * Processes annotated class | ||
+ * | ||
+ * @param classElement type element | ||
+ * @param elementUtils utils for working with elementUtils | ||
+ * @return result of processing as {@link TypeMeta} | ||
+ */ | ||
+ @NotNull | ||
+ protected abstract TypeMeta processAnnotatedClass(@NotNull TypeElement classElement, @NotNull Elements elementUtils); | ||
+ | ||
+ /** | ||
+ * Processes fields | ||
+ * | ||
+ * @param roundEnvironment current processing environment | ||
+ * @param annotatedClasses map of annotated classes | ||
+ */ | ||
+ protected abstract void processAnnotatedFields(@NotNull final RoundEnvironment roundEnvironment, @NotNull Map<TypeElement, TypeMeta> annotatedClasses); | ||
+ | ||
+ /** | ||
+ * Processes annotated field and returns result of processing or throws exception | ||
+ * | ||
+ * @param annotatedField field that was annotated as column | ||
+ * @return non-null {@link StorIOColumnMeta} with meta information about field | ||
+ */ | ||
+ @NotNull | ||
+ protected abstract ColumnMeta processAnnotatedField(@NotNull final Element annotatedField); | ||
+ | ||
+ protected abstract void validateAnnotatedClassesAndColumns(@NotNull Map<TypeElement, TypeMeta> annotatedClasses); | ||
+ | ||
+ @NotNull | ||
+ protected abstract Class<? extends Annotation> getTypeAnnotationClass(); | ||
+ | ||
+ @NotNull | ||
+ protected abstract Class<? extends Annotation> getColumnAnnotationClass(); | ||
+ | ||
+ @NotNull | ||
+ protected abstract ResolverGenerator<TypeMeta> createPutResolver(); | ||
+ | ||
+ @NotNull | ||
+ protected abstract ResolverGenerator<TypeMeta> createGetResolver(); | ||
+ | ||
+ @NotNull | ||
+ protected abstract ResolverGenerator<TypeMeta> createDeleteResolver(); | ||
+} |
10
.../src/main/java/com/pushtorefresh/storio/common/annotations/processor/generate/Common.java
@@ -0,0 +1,10 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor.generate; | ||
+ | ||
+import com.squareup.javapoet.ClassName; | ||
+ | ||
+public class Common { | ||
+ | ||
+ public static final ClassName ANDROID_NON_NULL_ANNOTATION_CLASS_NAME = ClassName.get("android.support.annotation", "NonNull"); | ||
+ | ||
+ public static final String INDENT = " "; // 4 spaces | ||
+} |
12
...ava/com/pushtorefresh/storio/common/annotations/processor/generate/ResolverGenerator.java
@@ -0,0 +1,12 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor.generate; | ||
+ | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOTypeMeta; | ||
+import com.squareup.javapoet.JavaFile; | ||
+ | ||
+import org.jetbrains.annotations.NotNull; | ||
+ | ||
+public interface ResolverGenerator <TypeMeta extends StorIOTypeMeta> { | ||
+ | ||
+ @NotNull | ||
+ JavaFile generateJavaFile(@NotNull TypeMeta typeMeta); | ||
+} |
2
...ons/processor/introspection/JavaType.java → ...ons/processor/introspection/JavaType.java
73
...com/pushtorefresh/storio/common/annotations/processor/introspection/StorIOColumnMeta.java
@@ -0,0 +1,73 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor.introspection; | ||
+ | ||
+import org.jetbrains.annotations.NotNull; | ||
+ | ||
+import java.lang.annotation.Annotation; | ||
+ | ||
+import javax.lang.model.element.Element; | ||
+ | ||
+public class StorIOColumnMeta <ColumnAnnotation extends Annotation> { | ||
+ | ||
+ @NotNull | ||
+ public final Element enclosingElement; | ||
+ | ||
+ @NotNull | ||
+ public final Element element; | ||
+ | ||
+ @NotNull | ||
+ public final String fieldName; | ||
+ | ||
+ @NotNull | ||
+ public final JavaType javaType; | ||
+ | ||
+ @NotNull | ||
+ public final ColumnAnnotation storIOColumn; | ||
+ | ||
+ public StorIOColumnMeta( | ||
+ @NotNull Element enclosingElement, | ||
+ @NotNull Element element, | ||
+ @NotNull String fieldName, | ||
+ @NotNull JavaType javaType, @NotNull ColumnAnnotation storIOColumn) { | ||
+ this.enclosingElement = enclosingElement; | ||
+ this.element = element; | ||
+ this.fieldName = fieldName; | ||
+ this.javaType = javaType; | ||
+ this.storIOColumn = storIOColumn; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public boolean equals(Object o) { | ||
+ if (this == o) return true; | ||
+ if (o == null || getClass() != o.getClass()) return false; | ||
+ | ||
+ StorIOColumnMeta<?> that = (StorIOColumnMeta<?>) o; | ||
+ | ||
+ if (!enclosingElement.equals(that.enclosingElement)) return false; | ||
+ if (!element.equals(that.element)) return false; | ||
+ if (!fieldName.equals(that.fieldName)) return false; | ||
+ if (javaType != that.javaType) return false; | ||
+ return storIOColumn.equals(that.storIOColumn); | ||
+ | ||
+ } | ||
+ | ||
+ @Override | ||
+ public int hashCode() { | ||
+ int result = enclosingElement.hashCode(); | ||
+ result = 31 * result + element.hashCode(); | ||
+ result = 31 * result + fieldName.hashCode(); | ||
+ result = 31 * result + javaType.hashCode(); | ||
+ result = 31 * result + storIOColumn.hashCode(); | ||
+ return result; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public String toString() { | ||
+ return "StorIOColumnMeta{" + | ||
+ "enclosingElement=" + enclosingElement + | ||
+ ", element=" + element + | ||
+ ", fieldName='" + fieldName + '\'' + | ||
+ ", javaType=" + javaType + | ||
+ ", storIOColumn=" + storIOColumn + | ||
+ '}'; | ||
+ } | ||
+} |
67
...a/com/pushtorefresh/storio/common/annotations/processor/introspection/StorIOTypeMeta.java
@@ -0,0 +1,67 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor.introspection; | ||
+ | ||
+import org.jetbrains.annotations.NotNull; | ||
+ | ||
+import java.lang.annotation.Annotation; | ||
+import java.util.HashMap; | ||
+import java.util.Map; | ||
+ | ||
+public class StorIOTypeMeta <TypeAnnotation extends Annotation, ColumnMeta extends StorIOColumnMeta> { | ||
+ | ||
+ @NotNull | ||
+ public final String simpleName; | ||
+ | ||
+ @NotNull | ||
+ public final String packageName; | ||
+ | ||
+ @NotNull | ||
+ public final TypeAnnotation storIOType; | ||
+ | ||
+ /** | ||
+ * Yep, this is MODIFIABLE Map, please use it carefully | ||
+ */ | ||
+ @NotNull | ||
+ public final Map<String, ColumnMeta> columns = new HashMap<String, ColumnMeta>(); | ||
+ | ||
+ public StorIOTypeMeta( | ||
+ @NotNull String simpleName, | ||
+ @NotNull String packageName, | ||
+ @NotNull TypeAnnotation storIOType) { | ||
+ this.simpleName = simpleName; | ||
+ this.packageName = packageName; | ||
+ this.storIOType = storIOType; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public boolean equals(Object o) { | ||
+ if (this == o) return true; | ||
+ if (o == null || getClass() != o.getClass()) return false; | ||
+ | ||
+ StorIOTypeMeta<?, ?> that = (StorIOTypeMeta<?, ?>) o; | ||
+ | ||
+ if (!simpleName.equals(that.simpleName)) return false; | ||
+ if (!packageName.equals(that.packageName)) return false; | ||
+ if (!storIOType.equals(that.storIOType)) return false; | ||
+ return columns.equals(that.columns); | ||
+ | ||
+ } | ||
+ | ||
+ @Override | ||
+ public int hashCode() { | ||
+ int result = simpleName.hashCode(); | ||
+ result = 31 * result + packageName.hashCode(); | ||
+ result = 31 * result + storIOType.hashCode(); | ||
+ result = 31 * result + columns.hashCode(); | ||
+ return result; | ||
+ } | ||
+ | ||
+ @Override | ||
+ public String toString() { | ||
+ return "StorIOTypeMeta{" + | ||
+ "simpleName='" + simpleName + '\'' + | ||
+ ", packageName='" + packageName + '\'' + | ||
+ ", storIOType=" + storIOType + | ||
+ ", columns=" + columns + | ||
+ '}'; | ||
+ } | ||
+} |
30
...processor/introspection/JavaTypeTest.java → ...processor/introspection/JavaTypeTest.java
1
storio-content-resolver-annotations-processor/build.gradle
31
...a/com/pushtorefresh/storio/contentresolver/annotations/processor/ProcessingException.java
@@ -1,31 +0,0 @@ | ||
-package com.pushtorefresh.storio.contentresolver.annotations.processor; | ||
- | ||
-import org.jetbrains.annotations.NotNull; | ||
- | ||
-import javax.lang.model.element.Element; | ||
- | ||
-/** | ||
- * Useful for logging errors from AnnotationProcessor, | ||
- * stores reference to {@link Element} that caused exception so IDE will show developer where is the problem | ||
- */ | ||
-public class ProcessingException extends RuntimeException { | ||
- | ||
- /** | ||
- * Element that caused exception | ||
- */ | ||
- @NotNull | ||
- private final Element element; | ||
- | ||
- public ProcessingException(@NotNull Element element, @NotNull String message) { | ||
- super(message); | ||
- this.element = element; | ||
- } | ||
- | ||
- /** | ||
- * @return non-null element that caused exception | ||
- */ | ||
- @NotNull | ||
- public Element element() { | ||
- return element; | ||
- } | ||
-} |
152
...orefresh/storio/contentresolver/annotations/processor/StorIOContentResolverProcessor.java
10
.../java/com/pushtorefresh/storio/contentresolver/annotations/processor/generate/Common.java
@@ -1,10 +0,0 @@ | ||
-package com.pushtorefresh.storio.contentresolver.annotations.processor.generate; | ||
- | ||
-import com.squareup.javapoet.ClassName; | ||
- | ||
-class Common { | ||
- | ||
- static final ClassName ANDROID_NON_NULL_ANNOTATION_CLASS_NAME = ClassName.get("android.support.annotation", "NonNull"); | ||
- | ||
- static final String INDENT = " "; // 4 spaces | ||
-} |
9
...efresh/storio/contentresolver/annotations/processor/generate/DeleteResolverGenerator.java
41
...torefresh/storio/contentresolver/annotations/processor/generate/GetResolverGenerator.java
13
...torefresh/storio/contentresolver/annotations/processor/generate/PutResolverGenerator.java
6
...m/pushtorefresh/storio/contentresolver/annotations/processor/generate/QueryGenerator.java
62
...om/pushtorefresh/storio/contentresolver/annotations/processor/introspection/JavaType.java
@@ -1,62 +0,0 @@ | ||
-package com.pushtorefresh.storio.contentresolver.annotations.processor.introspection; | ||
- | ||
-import org.jetbrains.annotations.NotNull; | ||
- | ||
-import javax.lang.model.type.TypeKind; | ||
-import javax.lang.model.type.TypeMirror; | ||
- | ||
-public enum JavaType { | ||
- | ||
- BOOLEAN, | ||
- BOOLEAN_OBJECT, | ||
- SHORT, | ||
- SHORT_OBJECT, | ||
- INTEGER, | ||
- INTEGER_OBJECT, | ||
- LONG, | ||
- LONG_OBJECT, | ||
- FLOAT, | ||
- FLOAT_OBJECT, | ||
- DOUBLE, | ||
- DOUBLE_OBJECT, | ||
- STRING, | ||
- BYTE_ARRAY; | ||
- | ||
- @NotNull | ||
- public static JavaType from(@NotNull TypeMirror typeMirror) { | ||
- final TypeKind typeKind = typeMirror.getKind(); | ||
- final String typeName = typeMirror.toString(); // fqn of type, for example java.lang.String | ||
- | ||
- if (typeKind == TypeKind.BOOLEAN) { | ||
- return BOOLEAN; | ||
- } else if (Boolean.class.getCanonicalName().equals(typeName)) { | ||
- return BOOLEAN_OBJECT; | ||
- } else if (typeKind == TypeKind.SHORT) { | ||
- return SHORT; | ||
- } else if (Short.class.getCanonicalName().equals(typeName)) { | ||
- return SHORT_OBJECT; | ||
- } else if (typeKind == TypeKind.INT) { | ||
- return INTEGER; | ||
- } else if (Integer.class.getCanonicalName().equals(typeName)) { | ||
- return INTEGER_OBJECT; | ||
- } else if (typeKind == TypeKind.LONG) { | ||
- return LONG; | ||
- } else if (Long.class.getCanonicalName().equals(typeName)) { | ||
- return LONG_OBJECT; | ||
- } else if (typeKind == TypeKind.FLOAT) { | ||
- return FLOAT; | ||
- } else if (Float.class.getCanonicalName().equals(typeName)) { | ||
- return FLOAT_OBJECT; | ||
- } else if (typeKind == TypeKind.DOUBLE) { | ||
- return DOUBLE; | ||
- } else if (Double.class.getCanonicalName().equals(typeName)) { | ||
- return DOUBLE_OBJECT; | ||
- } else if (String.class.getCanonicalName().equals(typeName)) { | ||
- return STRING; | ||
- } else if (byte[].class.getCanonicalName().equals(typeName)) { | ||
- return BYTE_ARRAY; | ||
- } else { | ||
- throw new IllegalArgumentException("Unsupported type: " + typeMirror); | ||
- } | ||
- } | ||
-} |
63
.../contentresolver/annotations/processor/introspection/StorIOContentResolverColumnMeta.java
@@ -1,74 +1,21 @@ | ||
package com.pushtorefresh.storio.contentresolver.annotations.processor.introspection; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOColumnMeta; | ||
import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverColumn; | ||
import org.jetbrains.annotations.NotNull; | ||
import javax.lang.model.element.Element; | ||
-public class StorIOContentResolverColumnMeta { | ||
- | ||
- @NotNull | ||
- public final Element enclosingElement; | ||
- | ||
- @NotNull | ||
- public final Element element; | ||
- | ||
- @NotNull | ||
- public final String fieldName; | ||
- | ||
- @NotNull | ||
- public final JavaType javaType; | ||
- | ||
- @NotNull | ||
- public final StorIOContentResolverColumn storIOContentResolverColumn; | ||
+public class StorIOContentResolverColumnMeta extends StorIOColumnMeta<StorIOContentResolverColumn> { | ||
public StorIOContentResolverColumnMeta( | ||
@NotNull Element enclosingElement, | ||
@NotNull Element element, | ||
@NotNull String fieldName, | ||
@NotNull JavaType javaType, | ||
- @NotNull StorIOContentResolverColumn storIOContentResolverColumn) { | ||
- this.enclosingElement = enclosingElement; | ||
- this.element = element; | ||
- this.fieldName = fieldName; | ||
- this.javaType = javaType; | ||
- this.storIOContentResolverColumn = storIOContentResolverColumn; | ||
- } | ||
- | ||
- @Override | ||
- public boolean equals(Object o) { | ||
- if (this == o) return true; | ||
- if (o == null || getClass() != o.getClass()) return false; | ||
- | ||
- StorIOContentResolverColumnMeta that = (StorIOContentResolverColumnMeta) o; | ||
- | ||
- if (!enclosingElement.equals(that.enclosingElement)) return false; | ||
- if (!element.equals(that.element)) return false; | ||
- if (!fieldName.equals(that.fieldName)) return false; | ||
- if (javaType != that.javaType) return false; | ||
- return storIOContentResolverColumn.equals(that.storIOContentResolverColumn); | ||
- | ||
- } | ||
- | ||
- @Override | ||
- public int hashCode() { | ||
- int result = enclosingElement.hashCode(); | ||
- result = 31 * result + element.hashCode(); | ||
- result = 31 * result + fieldName.hashCode(); | ||
- result = 31 * result + javaType.hashCode(); | ||
- result = 31 * result + storIOContentResolverColumn.hashCode(); | ||
- return result; | ||
- } | ||
- | ||
- @Override | ||
- public String toString() { | ||
- return "StorIOContentResolverColumnMeta{" + | ||
- "enclosingElement=" + enclosingElement + | ||
- ", element=" + element + | ||
- ", fieldName='" + fieldName + '\'' + | ||
- ", javaType=" + javaType + | ||
- ", storIOContentResolverColumn=" + storIOContentResolverColumn + | ||
- '}'; | ||
+ @NotNull StorIOContentResolverColumn storIOColumn) { | ||
+ super(enclosingElement, element, fieldName, javaType, storIOColumn); | ||
} | ||
} |
60
...io/contentresolver/annotations/processor/introspection/StorIOContentResolverTypeMeta.java
@@ -1,68 +1,16 @@ | ||
package com.pushtorefresh.storio.contentresolver.annotations.processor.introspection; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOTypeMeta; | ||
import com.pushtorefresh.storio.contentresolver.annotations.StorIOContentResolverType; | ||
import org.jetbrains.annotations.NotNull; | ||
-import java.util.HashMap; | ||
-import java.util.Map; | ||
- | ||
-public class StorIOContentResolverTypeMeta { | ||
- | ||
- @NotNull | ||
- public final String simpleName; | ||
- | ||
- @NotNull | ||
- public final String packageName; | ||
- | ||
- @NotNull | ||
- public final StorIOContentResolverType storIOContentResolverType; | ||
- | ||
- /** | ||
- * Yep, this is MODIFIABLE Map, please use it carefully | ||
- */ | ||
- @NotNull | ||
- public final Map<String, StorIOContentResolverColumnMeta> columns = new HashMap<String, StorIOContentResolverColumnMeta>(); | ||
+public class StorIOContentResolverTypeMeta extends StorIOTypeMeta<StorIOContentResolverType, StorIOContentResolverColumnMeta> { | ||
public StorIOContentResolverTypeMeta( | ||
@NotNull String simpleName, | ||
@NotNull String packageName, | ||
- @NotNull StorIOContentResolverType storIOContentResolverType) { | ||
- this.simpleName = simpleName; | ||
- this.packageName = packageName; | ||
- this.storIOContentResolverType = storIOContentResolverType; | ||
- } | ||
- | ||
- @Override | ||
- public boolean equals(Object o) { | ||
- if (this == o) return true; | ||
- if (o == null || getClass() != o.getClass()) return false; | ||
- | ||
- StorIOContentResolverTypeMeta that = (StorIOContentResolverTypeMeta) o; | ||
- | ||
- if (!simpleName.equals(that.simpleName)) return false; | ||
- if (!packageName.equals(that.packageName)) return false; | ||
- if (!storIOContentResolverType.equals(that.storIOContentResolverType)) return false; | ||
- return columns.equals(that.columns); | ||
- | ||
- } | ||
- | ||
- @Override | ||
- public int hashCode() { | ||
- int result = simpleName.hashCode(); | ||
- result = 31 * result + packageName.hashCode(); | ||
- result = 31 * result + storIOContentResolverType.hashCode(); | ||
- result = 31 * result + columns.hashCode(); | ||
- return result; | ||
- } | ||
- | ||
- @Override | ||
- public String toString() { | ||
- return "StorIOContentResolverTypeMeta{" + | ||
- "simpleName='" + simpleName + '\'' + | ||
- ", packageName='" + packageName + '\'' + | ||
- ", storIOContentResolverType=" + storIOContentResolverType + | ||
- ", columns=" + columns + | ||
- '}'; | ||
+ @NotNull StorIOContentResolverType storIOType) { | ||
+ super(simpleName, packageName, storIOType); | ||
} | ||
} |
2
...fresh/storio/contentresolver/annotations/processor/generate/GetResolverGeneratorTest.java
126
...ushtorefresh/storio/contentresolver/annotations/processor/introspection/JavaTypeTest.java
@@ -1,126 +0,0 @@ | ||
-package com.pushtorefresh.storio.contentresolver.annotations.processor.introspection; | ||
- | ||
-import org.jetbrains.annotations.NotNull; | ||
-import org.jetbrains.annotations.Nullable; | ||
-import org.junit.Test; | ||
- | ||
-import javax.lang.model.type.TypeKind; | ||
-import javax.lang.model.type.TypeMirror; | ||
- | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.BOOLEAN; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.BOOLEAN_OBJECT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.BYTE_ARRAY; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.DOUBLE; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.DOUBLE_OBJECT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.FLOAT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.FLOAT_OBJECT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.INTEGER; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.INTEGER_OBJECT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.LONG; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.LONG_OBJECT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.SHORT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.SHORT_OBJECT; | ||
-import static com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.JavaType.STRING; | ||
-import static org.assertj.core.api.Assertions.assertThat; | ||
-import static org.mockito.Mockito.mock; | ||
-import static org.mockito.Mockito.when; | ||
- | ||
-public class JavaTypeTest { | ||
- | ||
- @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; | ||
- } | ||
- | ||
- @Test | ||
- public void fromBoolean() { | ||
- final TypeMirror typeMirror = mockTypeMirror(TypeKind.BOOLEAN, null); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(BOOLEAN); | ||
- } | ||
- | ||
- @Test | ||
- public void fromBooleanObject() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, Boolean.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(BOOLEAN_OBJECT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromShort() { | ||
- final TypeMirror typeMirror = mockTypeMirror(TypeKind.SHORT, null); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(SHORT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromShortObject() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, Short.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(SHORT_OBJECT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromInteger() { | ||
- final TypeMirror typeMirror = mockTypeMirror(TypeKind.INT, null); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(INTEGER); | ||
- } | ||
- | ||
- @Test | ||
- public void fromIntegerObject() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, Integer.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(INTEGER_OBJECT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromLong() { | ||
- final TypeMirror typeMirror = mockTypeMirror(TypeKind.LONG, null); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(LONG); | ||
- } | ||
- | ||
- @Test | ||
- public void fromLongObject() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, Long.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(LONG_OBJECT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromFloat() { | ||
- final TypeMirror typeMirror = mockTypeMirror(TypeKind.FLOAT, null); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(FLOAT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromFloatObject() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, Float.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(FLOAT_OBJECT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromDouble() { | ||
- final TypeMirror typeMirror = mockTypeMirror(TypeKind.DOUBLE, null); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(DOUBLE); | ||
- } | ||
- | ||
- @Test | ||
- public void fromDoubleObject() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, Double.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(DOUBLE_OBJECT); | ||
- } | ||
- | ||
- @Test | ||
- public void fromString() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, String.class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(STRING); | ||
- } | ||
- | ||
- @Test | ||
- public void fromByteArray() { | ||
- final TypeMirror typeMirror = mockTypeMirror(null, byte[].class.getCanonicalName()); | ||
- assertThat(JavaType.from(typeMirror)).isEqualTo(BYTE_ARRAY); | ||
- } | ||
-} |
1
storio-sqlite-annotations-processor/build.gradle
196
...ain/java/com/pushtorefresh/storio/sqlite/annotations/processor/StorIOSQLiteProcessor.java
10
.../src/main/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/Common.java
@@ -1,10 +0,0 @@ | ||
-package com.pushtorefresh.storio.sqlite.annotations.processor.generate; | ||
- | ||
-import com.squareup.javapoet.ClassName; | ||
- | ||
-class Common { | ||
- | ||
- static final ClassName ANDROID_NON_NULL_ANNOTATION_CLASS_NAME = ClassName.get("android.support.annotation", "NonNull"); | ||
- | ||
- static final String INDENT = " "; // 4 spaces | ||
-} |
9
...m/pushtorefresh/storio/sqlite/annotations/processor/generate/DeleteResolverGenerator.java
41
.../com/pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGenerator.java
13
.../com/pushtorefresh/storio/sqlite/annotations/processor/generate/PutResolverGenerator.java
6
...n/java/com/pushtorefresh/storio/sqlite/annotations/processor/generate/QueryGenerator.java
67
...shtorefresh/storio/sqlite/annotations/processor/introspection/StorIOSQLiteColumnMeta.java
@@ -1,68 +1,21 @@ | ||
package com.pushtorefresh.storio.sqlite.annotations.processor.introspection; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.JavaType; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOColumnMeta; | ||
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteColumn; | ||
import org.jetbrains.annotations.NotNull; | ||
import javax.lang.model.element.Element; | ||
-public class StorIOSQLiteColumnMeta { | ||
+public class StorIOSQLiteColumnMeta extends StorIOColumnMeta<StorIOSQLiteColumn> { | ||
- @NotNull | ||
- public final Element enclosingElement; | ||
- | ||
- @NotNull | ||
- public final Element element; | ||
- | ||
- @NotNull | ||
- public final String fieldName; | ||
- | ||
- @NotNull | ||
- public final JavaType javaType; | ||
- | ||
- @NotNull | ||
- public final StorIOSQLiteColumn storIOSQLiteColumn; | ||
- | ||
- public StorIOSQLiteColumnMeta(@NotNull Element enclosingElement, @NotNull Element element, @NotNull String fieldName, @NotNull JavaType javaType, @NotNull StorIOSQLiteColumn storIOSQLiteColumn) { | ||
- this.enclosingElement = enclosingElement; | ||
- this.element = element; | ||
- this.fieldName = fieldName; | ||
- this.javaType = javaType; | ||
- this.storIOSQLiteColumn = storIOSQLiteColumn; | ||
- } | ||
- | ||
- @Override | ||
- public boolean equals(Object o) { | ||
- if (this == o) return true; | ||
- if (o == null || getClass() != o.getClass()) return false; | ||
- | ||
- StorIOSQLiteColumnMeta that = (StorIOSQLiteColumnMeta) o; | ||
- | ||
- if (!enclosingElement.equals(that.enclosingElement)) return false; | ||
- if (!element.equals(that.element)) return false; | ||
- if (!fieldName.equals(that.fieldName)) return false; | ||
- if (javaType != that.javaType) return false; | ||
- return storIOSQLiteColumn.equals(that.storIOSQLiteColumn); | ||
- } | ||
- | ||
- @Override | ||
- public int hashCode() { | ||
- int result = enclosingElement.hashCode(); | ||
- result = 31 * result + element.hashCode(); | ||
- result = 31 * result + fieldName.hashCode(); | ||
- result = 31 * result + javaType.hashCode(); | ||
- result = 31 * result + storIOSQLiteColumn.hashCode(); | ||
- return result; | ||
- } | ||
- | ||
- @Override | ||
- public String toString() { | ||
- return "StorIOSQLiteColumnMeta{" + | ||
- "enclosingElement=" + enclosingElement + | ||
- ", element=" + element + | ||
- ", fieldName='" + fieldName + '\'' + | ||
- ", javaType=" + javaType + | ||
- ", storIOSQLiteColumn=" + storIOSQLiteColumn + | ||
- '}'; | ||
+ public StorIOSQLiteColumnMeta( | ||
+ @NotNull Element enclosingElement, | ||
+ @NotNull Element element, | ||
+ @NotNull String fieldName, | ||
+ @NotNull JavaType javaType, | ||
+ @NotNull StorIOSQLiteColumn storIOColumn) { | ||
+ super(enclosingElement, element, fieldName, javaType, storIOColumn); | ||
} | ||
} |
64
...pushtorefresh/storio/sqlite/annotations/processor/introspection/StorIOSQLiteTypeMeta.java
@@ -1,64 +1,16 @@ | ||
package com.pushtorefresh.storio.sqlite.annotations.processor.introspection; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOTypeMeta; | ||
import com.pushtorefresh.storio.sqlite.annotations.StorIOSQLiteType; | ||
import org.jetbrains.annotations.NotNull; | ||
-import java.util.HashMap; | ||
-import java.util.Map; | ||
+public class StorIOSQLiteTypeMeta extends StorIOTypeMeta<StorIOSQLiteType, StorIOSQLiteColumnMeta> { | ||
-public class StorIOSQLiteTypeMeta { | ||
- | ||
- @NotNull | ||
- public final String simpleName; | ||
- | ||
- @NotNull | ||
- public final String packageName; | ||
- | ||
- @NotNull | ||
- public final StorIOSQLiteType storIOSQLiteType; | ||
- | ||
- /** | ||
- * Yep, this is MODIFIABLE Map, please use it carefully | ||
- */ | ||
- @NotNull | ||
- public final Map<String, StorIOSQLiteColumnMeta> columns = new HashMap<String, StorIOSQLiteColumnMeta>(); | ||
- | ||
- public StorIOSQLiteTypeMeta(@NotNull String simpleName, @NotNull String packageName, @NotNull StorIOSQLiteType storIOSQLiteType) { | ||
- this.simpleName = simpleName; | ||
- this.packageName = packageName; | ||
- this.storIOSQLiteType = storIOSQLiteType; | ||
- } | ||
- | ||
- @Override | ||
- public boolean equals(Object o) { | ||
- if (this == o) return true; | ||
- if (o == null || getClass() != o.getClass()) return false; | ||
- | ||
- StorIOSQLiteTypeMeta that = (StorIOSQLiteTypeMeta) o; | ||
- | ||
- if (!simpleName.equals(that.simpleName)) return false; | ||
- if (!packageName.equals(that.packageName)) return false; | ||
- if (!storIOSQLiteType.equals(that.storIOSQLiteType)) return false; | ||
- return columns.equals(that.columns); | ||
- } | ||
- | ||
- @Override | ||
- public int hashCode() { | ||
- int result = simpleName.hashCode(); | ||
- result = 31 * result + packageName.hashCode(); | ||
- result = 31 * result + storIOSQLiteType.hashCode(); | ||
- result = 31 * result + columns.hashCode(); | ||
- return result; | ||
- } | ||
- | ||
- @Override | ||
- public String toString() { | ||
- return "StorIOSQLiteTypeMeta{" + | ||
- "simpleName='" + simpleName + '\'' + | ||
- ", packageName='" + packageName + '\'' + | ||
- ", storIOSQLiteType=" + storIOSQLiteType + | ||
- ", columns=" + columns + | ||
- '}'; | ||
+ public StorIOSQLiteTypeMeta( | ||
+ @NotNull String simpleName, | ||
+ @NotNull String packageName, | ||
+ @NotNull StorIOSQLiteType storIOType) { | ||
+ super(simpleName, packageName, storIOType); | ||
} | ||
-} | ||
+} |
2
.../pushtorefresh/storio/sqlite/annotations/processor/generate/GetResolverGeneratorTest.java
0 comments on commit
5ed18e6