Skip to content

Commit

Permalink
Merge pull request #1101 from Raizlabs/develop
Browse files Browse the repository at this point in the history
Version 4.0.0-beta3
  • Loading branch information
agrosner authored Dec 12, 2016
2 parents 660fc6f + 3c521c1 commit 279fe41
Show file tree
Hide file tree
Showing 408 changed files with 8,303 additions and 9,314 deletions.
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,9 @@ Changes exist in the [releases tab](https://github.com/Raizlabs/DBFlow/releases)
For more detailed usage, check out it out [here](/usage2/Intro.md)

# Including in your project
If you use KAPT (Kotlin's APT), then skip this first step.

We need to include the [apt plugin](https://bitbucket.org/hvisser/android-apt) in our classpath to enable Annotation Processing:

```groovy
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
allProjects {
repositories {
// required to find the project's artifacts
Expand All @@ -53,15 +41,16 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl

```groovy
apply plugin: 'com.neenbedankt.android-apt'
def dbflow_version = "4.0.0-beta2"
def dbflow_version = "4.0.0-beta3"
// or dbflow_version = "develop-SNAPSHOT" for grabbing latest dependency in your project on the develop branch
// or 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet)
dependencies {
apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
// use kapt for kotlin apt
annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
// use kapt for kotlin apt if you're a Kotlin user
kapt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Expand All @@ -13,3 +13,7 @@ allprojects {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,9 @@
*/
String columnName();

/**
* Needs to match both tables!
*
* @return The type of columns between tables
*/
Class<?> columnType();

/**
* @return The column name in the referenced table
*/
String foreignKeyColumnName();

/**
* @return True here if the referenced field is private. It must have a getter with the same name available such
* that a field "name" has "getName()".
*/
boolean referencedFieldIsPrivate() default false;

/**
* @return True here if the referenced field is package private. It will use the "_Helper" class
* generated automatically to access the value of the field. Also, its required that the {@link ForeignKey#tableClass()}
* is set or known at compile time via a Model object.
*/
boolean referencedFieldIsPackagePrivate() default false;

/**
* @return sets the name of the referenced field getter.
* @see Column#getterName() for more information.
*/
String referencedGetterName() default "";

/**
* @return Sets the name of the referenced field setter.
* @see Column#setterName() for more information.
*/
String referencedSetterName() default "";
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.raizlabs.android.dbflow.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Description: Specifies that a {@link Column} is not null.
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface NotNull {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum SQLiteType {
put(Double.class.getName(), SQLiteType.REAL);
put(Boolean.class.getName(), SQLiteType.INTEGER);
put(Character.class.getName(), SQLiteType.TEXT);
put(CharSequence.class.getName(), SQLiteType.TEXT);
put(String.class.getName(), SQLiteType.TEXT);
put(Byte[].class.getName(), SQLiteType.BLOB);
put(Blob.class.getName(), SQLiteType.BLOB);
Expand Down
2 changes: 1 addition & 1 deletion dbflow-kotlinextensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
compile project("${dbflow_project_prefix}dbflow")
}
buildscript {
ext.kotlin_version = '1.0.4'
ext.kotlin_version = '1.0.5-2'
repositories {
mavenCentral()
}
Expand Down
2 changes: 1 addition & 1 deletion dbflow-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {

apply from: '../java-artifacts.gradle'
buildscript {
ext.kotlin_version = '1.0.4'
ext.kotlin_version = '1.0.5-2'
repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.raizlabs.android.dbflow.annotation.TypeConverter;
import com.raizlabs.android.dbflow.annotation.provider.ContentProvider;
import com.raizlabs.android.dbflow.annotation.provider.TableEndpoint;
import com.raizlabs.android.dbflow.processor.definition.DatabaseHolderDefinition;

import java.util.LinkedHashSet;
import java.util.Set;
Expand Down Expand Up @@ -53,6 +54,13 @@ public Set<String> getSupportedAnnotationTypes() {
return supportedTypes;
}

@Override
public Set<String> getSupportedOptions() {
Set<String> supportedOptions = new LinkedHashSet<>();
supportedOptions.add(DatabaseHolderDefinition.OPTION_TARGET_MODULE_NAME);
return supportedOptions;
}

/**
* If the processor class is annotated with {@link
* javax.annotation.processing.SupportedSourceVersion}, return the source version in the
Expand All @@ -71,14 +79,14 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
manager = new ProcessorManager(processingEnv);
manager.addHandlers(
new MigrationHandler(),
new TypeConverterHandler(),
new DatabaseHandler(),
new TableHandler(),
new QueryModelHandler(),
new ModelViewHandler(),
new ContentProviderHandler(),
new TableEndpointHandler());
new MigrationHandler(),
new TypeConverterHandler(),
new DatabaseHandler(),
new TableHandler(),
new QueryModelHandler(),
new ModelViewHandler(),
new ContentProviderHandler(),
new TableEndpointHandler());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.raizlabs.android.dbflow.processor

import com.raizlabs.android.dbflow.processor.ProcessorManager.Companion.manager
import com.raizlabs.android.dbflow.processor.utils.ElementUtility
import com.squareup.javapoet.ClassName
import javax.annotation.processing.ProcessingEnvironment
import javax.lang.model.element.Element
import javax.lang.model.element.Modifier
import javax.lang.model.element.TypeElement
import javax.lang.model.type.TypeMirror
import javax.tools.Diagnostic
Expand All @@ -28,15 +30,15 @@ object ProcessorUtils {
val typeElement = processingEnvironment.elementUtils.getTypeElement(fqTn)
if (typeElement == null) {
processingEnvironment.messager.printMessage(Diagnostic.Kind.ERROR, "Type Element was null for: " + fqTn + "" +
"ensure that the visibility of the class is not private.")
"ensure that the visibility of the class is not private.")
return false
} else {
var classMirror: TypeMirror? = typeElement.asType()
if (classMirror != null) {
classMirror = processingEnvironment.typeUtils.erasure(classMirror)
}
return classMirror != null && element != null && element.asType() != null &&
processingEnvironment.typeUtils.isAssignable(element.asType(), classMirror)
processingEnvironment.typeUtils.isAssignable(element.asType(), classMirror)
}
}

Expand All @@ -55,7 +57,7 @@ object ProcessorUtils {
val typeElement = processingEnvironment.elementUtils.getTypeElement(fqTn)
if (typeElement == null) {
processingEnvironment.messager.printMessage(Diagnostic.Kind.ERROR, "Type Element was null for: " + fqTn + "" +
"ensure that the visibility of the class is not private.")
"ensure that the visibility of the class is not private.")
return false
} else {
val classMirror = typeElement.asType()
Expand Down Expand Up @@ -94,4 +96,18 @@ object ProcessorUtils {
return typeElement
}

fun ensureVisibleStatic(element: Element, typeElement: TypeElement,
name: String) {
if (element.modifiers.contains(Modifier.PRIVATE)
|| element.modifiers.contains(Modifier.PROTECTED)) {
manager.logError("$name must be visible from: " + typeElement)
}
if (!element.modifiers.contains(Modifier.STATIC)) {
manager.logError("$name must be static from: " + typeElement)
}

if (!element.modifiers.contains(Modifier.FINAL)) {
manager.logError("The $name must be final")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.raizlabs.android.dbflow.processor.definition

import com.raizlabs.android.dbflow.processor.ClassNames
import com.raizlabs.android.dbflow.processor.definition.DatabaseDefinition
import com.raizlabs.android.dbflow.processor.DatabaseHandler
import com.raizlabs.android.dbflow.processor.ProcessorManager
import com.squareup.javapoet.MethodSpec
Expand Down Expand Up @@ -30,14 +29,14 @@ class DatabaseHolderDefinition(private val processorManager: ProcessorManager) :
override val typeSpec: TypeSpec
get() {
val typeBuilder = TypeSpec.classBuilder(this.className)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.superclass(ClassNames.DATABASE_HOLDER)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.superclass(ClassNames.DATABASE_HOLDER)

val constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC)

processorManager.getTypeConverters().forEach {
constructor.addStatement("\$L.put(\$T.class, new \$T())",
DatabaseHandler.TYPE_CONVERTER_MAP_FIELD_NAME, it.modelTypeName, it.className)
DatabaseHandler.TYPE_CONVERTER_MAP_FIELD_NAME, it.modelTypeName, it.className)
}

processorManager.getDatabaseHolderDefinitionMap().forEach { databaseDefinition ->
Expand All @@ -52,6 +51,7 @@ class DatabaseHolderDefinition(private val processorManager: ProcessorManager) :

companion object {

private val OPTION_TARGET_MODULE_NAME = "targetModuleName"
@JvmField
val OPTION_TARGET_MODULE_NAME = "targetModuleName"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.squareup.javapoet.CodeBlock
import com.squareup.javapoet.FieldSpec
import com.squareup.javapoet.ParameterizedTypeName
import java.util.*
import java.util.concurrent.atomic.AtomicInteger
import javax.lang.model.element.Modifier

/**
Expand All @@ -33,7 +34,11 @@ class IndexGroupsDefinition(private val tableDefinition: TableDefinition, indexG
val initializer = CodeBlock.builder().add("new \$T<>(\$S, \$L, \$T.class", ClassNames.INDEX_PROPERTY,
indexName, isUnique, tableDefinition.elementTypeName)

columnDefinitionList.forEach { initializer.add(", \$L", it.columnName) }
if (columnDefinitionList.isNotEmpty()) {
initializer.add(",")
}
val index = AtomicInteger(0)
columnDefinitionList.forEach { it.appendIndexInitializer(initializer, index) }
initializer.add(")")

fieldBuilder.initializer(initializer.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab

if (element is TypeElement) {
implementsLoadFromCursorListener = ProcessorUtils.implementsClass(manager.processingEnvironment,
ClassNames.LOAD_FROM_CURSOR_LISTENER.toString(), element)
ClassNames.LOAD_FROM_CURSOR_LISTENER.toString(), element)
} else {
implementsLoadFromCursorListener = false
}
Expand Down Expand Up @@ -104,23 +104,14 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
}

if (columnDefinition.isPrimaryKey || columnDefinition is ForeignKeyColumnDefinition
|| columnDefinition.isPrimaryKeyAutoIncrement || columnDefinition.isRowId) {
|| columnDefinition.isPrimaryKeyAutoIncrement || columnDefinition.isRowId) {
manager.logError("ModelViews cannot have primary or foreign keys")
}
} else if (variableElement.getAnnotation(ModelViewQuery::class.java) != null) {
if (!queryFieldName.isNullOrEmpty()) {
manager.logError("Found duplicate ")
}
if (!variableElement.modifiers.contains(Modifier.PUBLIC)) {
manager.logError("The ModelViewQuery must be public")
}
if (!variableElement.modifiers.contains(Modifier.STATIC)) {
manager.logError("The ModelViewQuery must be static")
}

if (!variableElement.modifiers.contains(Modifier.FINAL)) {
manager.logError("The ModelViewQuery must be final")
}
ProcessorUtils.ensureVisibleStatic(variableElement, typeElement, "ModelViewQuery")

val element = manager.elements.getTypeElement(variableElement.asType().toString())
if (!ProcessorUtils.implementsClass(manager.processingEnvironment, ClassNames.QUERY.toString(), element)) {
Expand Down Expand Up @@ -148,7 +139,7 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
override fun onWriteDefinition(typeBuilder: TypeSpec.Builder) {

typeBuilder.addField(FieldSpec.builder(ClassName.get(String::class.java),
"VIEW_NAME", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).initializer("\$S", name!!).build())
"VIEW_NAME", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL).initializer("\$S", name!!).build())
elementClassName?.let {
columnDefinitions.forEach {
columnDefinition ->
Expand All @@ -175,22 +166,22 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
InternalAdapterHelper.writeGetModelClass(typeBuilder, elementClassName)

typeBuilder.addMethod(MethodSpec.methodBuilder("getCreationQuery")
.addAnnotation(Override::class.java)
.addModifiers(DatabaseHandler.METHOD_MODIFIERS)
.addStatement("return \$T.\$L.getQuery()", elementClassName, queryFieldName)
.returns(ClassName.get(String::class.java)).build())
.addAnnotation(Override::class.java)
.addModifiers(DatabaseHandler.METHOD_MODIFIERS)
.addStatement("return \$T.\$L.getQuery()", elementClassName, queryFieldName)
.returns(ClassName.get(String::class.java)).build())

typeBuilder.addMethod(MethodSpec.methodBuilder("getViewName")
.addAnnotation(Override::class.java)
.addModifiers(DatabaseHandler.METHOD_MODIFIERS)
.addStatement("return \$S", name!!)
.returns(ClassName.get(String::class.java)).build())
.addAnnotation(Override::class.java)
.addModifiers(DatabaseHandler.METHOD_MODIFIERS)
.addStatement("return \$S", name!!)
.returns(ClassName.get(String::class.java)).build())

typeBuilder.addMethod(MethodSpec.methodBuilder("newInstance")
.addAnnotation(Override::class.java)
.addModifiers(DatabaseHandler.METHOD_MODIFIERS)
.addStatement("return new \$T()", elementClassName)
.returns(elementClassName).build())
.addAnnotation(Override::class.java)
.addModifiers(DatabaseHandler.METHOD_MODIFIERS)
.addStatement("return new \$T()", elementClassName)
.returns(elementClassName).build())
}

override fun compareTo(other: ModelViewDefinition): Int {
Expand Down
Loading

0 comments on commit 279fe41

Please sign in to comment.