Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Updating deps to new XProcessor and KT 1.6.0 #1256

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions blessedDeps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ rootProject.ext.ANDROID_DATA_BINDING = "1.3.1"
rootProject.ext.ANDROID_RUNTIME_VERSION = "4.1.1.4"
rootProject.ext.ANDROID_TEST_RUNNER = "1.4.0"
rootProject.ext.ASSERTJ_VERSION = "1.7.1"
rootProject.ext.AUTO_VALUE_VERSION = "1.7.4"
rootProject.ext.AUTO_VALUE_VERSION = "1.8.2"
rootProject.ext.GLIDE_VERSION = "4.12.0"
rootProject.ext.GOOGLE_TESTING_COMPILE_VERSION = "0.19"
rootProject.ext.INCAP_VERSION = "0.3"
rootProject.ext.JUNIT_VERSION = "4.13.1"
rootProject.ext.KOTLIN_COROUTINES_TEST_VERSION = "1.4.1"
rootProject.ext.KOTLIN_COROUTINES_VERSION = "1.3.9"
rootProject.ext.KOTLIN_COROUTINES_TEST_VERSION = "1.5.1"
rootProject.ext.KOTLIN_COROUTINES_VERSION = "1.5.2"
rootProject.ext.KOTLINX_METADATA = "0.3.0"
rootProject.ext.LOTTIE_VERSION = "2.8.0"
rootProject.ext.MOCKITO_VERSION = "3.7.7"
rootProject.ext.PARIS_VERSION = "2.0.1"
rootProject.ext.ROBOLECTRIC_VERSION = "4.5.1"
rootProject.ext.SQUARE_JAVAPOET_VERSION = "1.13.0"
rootProject.ext.SQUARE_KOTLINPOET_VERSION = "1.10.2"
rootProject.ext.COMPOSE_VERSION = "1.0.4"
rootProject.ext.COMPOSE_VERSION = "1.0.5"
rootProject.ext.COMPOSE_ACTIVITY_VERSION = "1.3.1"
rootProject.ext.KOTLINX_LIFECYCLE_RUNTIME_VERSION = "2.3.0"
rootProject.ext.KSP_VERSION = "1.5.31-1.0.0"
rootProject.ext.XPROCESSING_VERSION = "2.4.0-beta01"
rootProject.ext.KOTLIN_TESTING_COMPILE_VERSION = '1.4.5'
rootProject.ext.KSP_VERSION = "1.6.0-1.0.1"
rootProject.ext.XPROCESSING_VERSION = "2.4.0-SNAPSHOT"
rootProject.ext.KOTLIN_TESTING_COMPILE_VERSION = '1.4.6'

rootProject.ext.deps = [
activityCompose : "androidx.activity:activity-compose:$COMPOSE_ACTIVITY_VERSION",
Expand Down
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

ext.KOTLIN_VERSION = "1.5.31"
ext.KOTLIN_VERSION = "1.6.0"
ext.ANDROID_PLUGIN_VERSION = '7.0.3'
ext.KSP_VERSION = '1.5.31-1.0.0'
ext.KSP_VERSION = '1.6.0-1.0.1'

repositories {
google()
mavenCentral()
gradlePluginPortal()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$ANDROID_PLUGIN_VERSION"
Expand All @@ -32,7 +31,7 @@ allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://androidx.dev/snapshots/builds/7932053/artifacts/repository/" }
}

// Prevent javadoc task complaining about errors with kotlin files
Expand Down
8 changes: 5 additions & 3 deletions epoxy-kspsample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += "-Xjvm-default=all"
jvmTarget = "11"
targetCompatibility = "11"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.airbnb.epoxy.EpoxyRecyclerView
import com.airbnb.epoxy.ksp.sample.epoxyviews.headerView
import com.airbnb.epoxy.ksp.sample.epoxyviews.footerView

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -15,6 +16,10 @@ class MainActivity : AppCompatActivity() {
id("header")
title("Hello World")
}
footerView {
id("footer")
text("footer")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.airbnb.epoxy.ksp.sample.epoxyviews

import android.widget.LinearLayout
import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.ksp.sample.R

@EpoxyModelClass
abstract class FooterView : EpoxyModel<LinearLayout>() {

@EpoxyAttribute
lateinit var text: String

override fun getDefaultLayout(): Int = R.layout.footer_view

override fun bind(view: LinearLayout) {
super.bind(view)
view.findViewById<TextView>(R.id.footer_text).text = text
}
}
18 changes: 18 additions & 0 deletions epoxy-kspsample/src/main/res/layout/footer_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/footer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp"
tools:text="caption" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class BaseProcessor(val kspEnvironment: SymbolProcessorEnvironment? = n
Asyncable,
SymbolProcessor {

val processorName = this@BaseProcessor::class.java.simpleName
private val processorName: String = this@BaseProcessor::class.java.simpleName

lateinit var environment: XProcessingEnv
private set
Expand Down Expand Up @@ -287,7 +287,7 @@ abstract class BaseProcessor(val kspEnvironment: SymbolProcessorEnvironment? = n

generatedClasses
.flatMap { it.attributeInfo }
.mapNotNull { attributeInfo ->
.map { attributeInfo ->
if (configManager.requiresHashCode(attributeInfo) &&
attributeInfo.useInHash &&
!attributeInfo.ignoreRequireHashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ class EpoxyProcessor @JvmOverloads constructor(
modelInfo.superClassElement.getAnnotation(EpoxyModelClass::class)?.value?.layout == 0 &&
modelInfo.boundObjectTypeElement?.hasStyleableAnnotation() == true
}
.toSet()
timer.markStepCompleted("check for styleable models")

styleableModelsToWrite.addAll(styleableModels)

modelInfos.minus(styleableModels).mapNotNull {
writeModel(it, memoizer)
}
modelInfos.minus(styleableModels).map { writeModel(it, memoizer) }

styleableModelsToWrite.mapNotNull { modelInfo ->
if (tryAddStyleBuilderAttribute(modelInfo, environment, memoizer)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ModelViewInfo(
// Only include the interface if the view has one of the interface methods annotated with a prop annotation
val interfaceMethods = interfaceElement.getDeclaredMethods()
methodsOnView.any { viewMethod ->
viewMethod.hasAnyOf(*ModelViewProcessor.modelPropAnnotationsArray) &&
viewMethod.hasAnyAnnotation(*ModelViewProcessor.modelPropAnnotationsArray) &&
interfaceMethods.any { interfaceMethod ->
// To keep this simple we only compare name and ignore parameters, should be close enough
viewMethod.name == interfaceMethod.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ class ModelViewProcessor @JvmOverloads constructor(
if (prop is XMethodElement &&
prop.parameters.isEmpty() &&
info.viewElement.findOverload(
prop,
1
)?.hasAnyOf(*modelPropAnnotationsArray) == true
prop,
1
)?.hasAnyAnnotation(*modelPropAnnotationsArray) == true
) {
return@mapNotNull null
}
Expand Down Expand Up @@ -468,23 +468,24 @@ class ModelViewProcessor @JvmOverloads constructor(
classTypes: List<XTypeElement>,
memoizer: Memoizer
) {
classTypes.getElementsAnnotatedWith(OnVisibilityChanged::class).mapNotNull { visibilityMethod ->
if (!validateVisibilityChangedElement(visibilityMethod, memoizer)) {
return@mapNotNull null
}
classTypes.getElementsAnnotatedWith(OnVisibilityChanged::class)
.mapNotNull { visibilityMethod ->
if (!validateVisibilityChangedElement(visibilityMethod, memoizer)) {
return@mapNotNull null
}

val info = getModelInfoForPropElement(visibilityMethod)
if (info == null) {
logger.logError(
visibilityMethod,
"%s annotation can only be used in classes annotated with %s",
OnVisibilityChanged::class.java, ModelView::class.java
)
return@mapNotNull null
}
val info = getModelInfoForPropElement(visibilityMethod)
if (info == null) {
logger.logError(
visibilityMethod,
"%s annotation can only be used in classes annotated with %s",
OnVisibilityChanged::class.java, ModelView::class.java
)
return@mapNotNull null
}

visibilityMethod.expectName to info
}.forEach { (methodName, modelInfo) ->
visibilityMethod.expectName to info
}.forEach { (methodName, modelInfo) ->
// Do this after, synchronously, to preserve function ordering in the view.
// If there are multiple functions with this annotation this allows them
// to be called in predictable order from top to bottom of the class, which
Expand Down Expand Up @@ -658,7 +659,10 @@ class ModelViewProcessor @JvmOverloads constructor(
)
}

private fun validateVisibilityChangedElement(visibilityMethod: XElement, memoizer: Memoizer): Boolean {
private fun validateVisibilityChangedElement(
visibilityMethod: XElement,
memoizer: Memoizer
): Boolean {
contract {
returns(true) implies (visibilityMethod is XMethodElement)
}
Expand All @@ -667,7 +671,12 @@ class ModelViewProcessor @JvmOverloads constructor(
visibilityMethod,
OnVisibilityChanged::class.java,
4,
checkTypeParameters = listOf(TypeName.FLOAT, TypeName.FLOAT, TypeName.INT, TypeName.INT),
checkTypeParameters = listOf(
TypeName.FLOAT,
TypeName.FLOAT,
TypeName.INT,
TypeName.INT
),
memoizer = memoizer
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ internal object Utils {
@JvmStatic
@Throws(EpoxyProcessorException::class)
fun throwError(msg: String?, vararg args: Any?) {
throw EpoxyProcessorException(String.format(msg!!, *args))
throw EpoxyProcessorException(msg!!.format(*args))
}

@JvmStatic
fun buildEpoxyException(
msg: String?,
vararg args: Any?
): EpoxyProcessorException {
return EpoxyProcessorException(String.format(msg!!, *args))
return EpoxyProcessorException(msg!!.format(*args))
}

fun buildEpoxyException(
Expand All @@ -62,7 +62,7 @@ internal object Utils {
vararg args: Any?
): EpoxyProcessorException {
return EpoxyProcessorException(
message = String.format(msg!!, *args),
message = msg!!.format(*args),
element = element
)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ internal object Utils {
* Returns the type of the Epoxy model.
*
* Eg for "class MyModel extends EpoxyModel<TextView>" it would return TextView.
</TextView> */
</TextView> */
fun getEpoxyObjectType(
clazz: XTypeElement,
memoizer: Memoizer
Expand Down Expand Up @@ -285,7 +285,7 @@ internal object Utils {
fun capitalizeFirstLetter(original: String?): String? {
return if (original == null || original.isEmpty()) {
original
} else original.substring(0, 1).toUpperCase() + original.substring(1)
} else original.substring(0, 1).uppercase() + original.substring(1)
}

@JvmStatic
Expand All @@ -303,11 +303,11 @@ internal object Utils {
return if (!PATTERN_STARTS_WITH_SET.matcher(string).matches()) {
string
} else string[3].toString()
.toLowerCase() + string.substring(4)
.lowercase() + string.substring(4)
}

fun toSnakeCase(s: String): String {
return s.replace("([^_A-Z])([A-Z])".toRegex(), "$1_$2").toLowerCase()
return s.replace("([^_A-Z])([A-Z])".toRegex(), "$1_$2").lowercase()
}

fun getDefaultValue(attributeType: TypeName): String {
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading