Skip to content

Commit

Permalink
Use kotlin dsl marker for model building receivers (#1180)
Browse files Browse the repository at this point in the history
* Use kotlin dsl marker for model building receivers

* fix tests

* check passes
  • Loading branch information
elihart committed May 11, 2021
1 parent 35d3f77 commit 393a0a6
Show file tree
Hide file tree
Showing 23 changed files with 84 additions and 6 deletions.
4 changes: 2 additions & 2 deletions blessedDeps.gradle
Expand Up @@ -7,8 +7,8 @@
* gradle file, then applying it back in as necessary.
*/

rootProject.ext.JAVA_SOURCE_VERSION = JavaVersion.VERSION_1_7
rootProject.ext.JAVA_TARGET_VERSION = JavaVersion.VERSION_1_7
rootProject.ext.JAVA_SOURCE_VERSION = JavaVersion.VERSION_1_8
rootProject.ext.JAVA_TARGET_VERSION = JavaVersion.VERSION_1_8

rootProject.ext.TARGET_SDK_VERSION = 28
rootProject.ext.COMPILE_SDK_VERSION = 28
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

ext.KOTLIN_VERSION = "1.4.32"
ext.KOTLIN_VERSION = "1.5.0"
ext.ANDROID_PLUGIN_VERSION = '4.1.3'

repositories {
Expand Down
5 changes: 5 additions & 0 deletions epoxy-adapter/build.gradle
Expand Up @@ -15,6 +15,11 @@ android {

testOptions.unitTests.includeAndroidResources = true

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes.all { buildType ->
buildType.javaCompileOptions.annotationProcessorOptions.arguments =
[
Expand Down
2 changes: 2 additions & 0 deletions epoxy-adapter/lint.xml
Expand Up @@ -6,4 +6,6 @@
<issue id="PluralsCandidate" severity="ignore" />
<issue id="Typos" severity="ignore" />
<issue id="InvalidPackage" severity="ignore" />
<!-- Bug in lint agp 4.1 incorrectly thinks kotlin forEach is using java 8 API's. Fixed in AGP 4.2. -->
<issue id="NewApi" severity="ignore" />
</lint>
Expand Up @@ -4,6 +4,7 @@ package com.airbnb.epoxy
* Interface used to collect models. Used by [EpoxyController]. It is also convenient to build DSL
* helpers for carousel: @link https://github.com/airbnb/epoxy/issues/847.
*/
@EpoxyBuildScope
interface ModelCollector {

fun add(model: EpoxyModel<*>)
Expand Down
7 changes: 7 additions & 0 deletions epoxy-annotations/build.gradle
@@ -1,9 +1,16 @@
apply plugin: 'java'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: "com.vanniktech.maven.publish"

sourceCompatibility = rootProject.JAVA_SOURCE_VERSION
targetCompatibility = rootProject.JAVA_TARGET_VERSION

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation rootProject.deps.androidAnnotations
// Allow us to use android support library annotations (@LayoutRes) in this project.
Expand Down
@@ -0,0 +1,9 @@
package com.airbnb.epoxy

/**
* Used to mark Epoxy model building DSLs so that when using generated kotlin extension functions
* for building models you cannot incorrectly nest models and also don't see cluttered, incorrect
* code completion suggestions.
*/
@DslMarker
annotation class EpoxyBuildScope
5 changes: 5 additions & 0 deletions epoxy-databinding/build.gradle
Expand Up @@ -14,6 +14,11 @@ android {
// Ignoring it for now until we can figure out how to fix it.
enabled = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

configurations.all { strategy ->
Expand Down
5 changes: 5 additions & 0 deletions epoxy-glide-preloader/build.gradle
Expand Up @@ -11,6 +11,11 @@ android {
targetSdkVersion rootProject.TARGET_SDK_VERSION
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions epoxy-modelfactory/build.gradle
Expand Up @@ -9,6 +9,11 @@ android {
minSdkVersion 16
targetSdkVersion rootProject.TARGET_SDK_VERSION
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions epoxy-modelfactorytest/build.gradle
Expand Up @@ -14,6 +14,11 @@ android {
}

testOptions.unitTests.includeAndroidResources = true

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

configurations.all { strategy ->
Expand Down
5 changes: 5 additions & 0 deletions epoxy-paging/build.gradle
Expand Up @@ -11,6 +11,11 @@ android {
targetSdkVersion rootProject.TARGET_SDK_VERSION
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions epoxy-paging3/build.gradle
Expand Up @@ -11,6 +11,11 @@ android {
targetSdkVersion rootProject.TARGET_SDK_VERSION
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions epoxy-pagingsample/build.gradle
Expand Up @@ -14,6 +14,11 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions epoxy-preloadersample/build.gradle
Expand Up @@ -19,6 +19,11 @@ android {
buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Expand Up @@ -12,7 +12,7 @@ class ImagesController(private val isPreloading: Boolean) : TypedEpoxyController
id("image_id_$url")
imageUrl(url)
text("Image Number: $index")
preloading(isPreloading)
preloading(this@ImagesController.isPreloading)
}
}
}
Expand Down
@@ -1,5 +1,6 @@
package com.airbnb.epoxy.processor

import com.airbnb.epoxy.EpoxyBuildScope
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.JavaFile
import com.squareup.javapoet.MethodSpec
Expand Down Expand Up @@ -81,6 +82,7 @@ class ModelBuilderInterfaceWriter(
addModifiers(Modifier.PUBLIC)
addTypeVariables(modelInfo.typeVariables)
addMethods(interfaceMethods)
addAnnotation(EpoxyBuildScope::class.java)

if (modelInfo.memoizer.implementsModelCollector(modelInfo.superClassElement)) {
// If the model implements "ModelCollector" we want the builder too
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.lang.String;
import java.util.List;

@EpoxyBuildScope
public interface ModelWithAllFieldTypesBuilder {
ModelWithAllFieldTypesBuilder onBind(
OnModelBoundListener<ModelWithAllFieldTypes_, Object> listener);
Expand Down
Expand Up @@ -16,6 +16,7 @@
import java.lang.String;
import java.util.List;

@EpoxyBuildScope
public interface TestManyTypesViewModelBuilder {
TestManyTypesViewModelBuilder onBind(
OnModelBoundListener<TestManyTypesViewModel_, TestManyTypesView> listener);
Expand Down
5 changes: 5 additions & 0 deletions epoxy-processortest2/build.gradle
Expand Up @@ -7,6 +7,11 @@ android {
minSdkVersion rootProject.MIN_SDK_VERSION
targetSdkVersion rootProject.TARGET_SDK_VERSION
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
5 changes: 5 additions & 0 deletions kotlinsample/build.gradle
Expand Up @@ -20,6 +20,11 @@ android {
viewBinding {
enabled = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Expand Up @@ -22,14 +22,14 @@ class StickyHeaderController(
id("sticky-header $i")
title("Sticky header $i")
listener {
Toast.makeText(context, "clicked", Toast.LENGTH_LONG).show()
Toast.makeText(this@StickyHeaderController.context, "clicked", Toast.LENGTH_LONG).show()
}
}
else -> itemEpoxyHolder {
id("view holder $i")
title("this is a View Holder item")
listener {
Toast.makeText(context, "clicked", Toast.LENGTH_LONG)
Toast.makeText(this@StickyHeaderController.context, "clicked", Toast.LENGTH_LONG)
.show()
}
}
Expand Down
Empty file modified update_processor_test_resources.rb 100644 → 100755
Empty file.

0 comments on commit 393a0a6

Please sign in to comment.