Skip to content
Merged
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
4 changes: 0 additions & 4 deletions ast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
id 'com.vanniktech.maven.publish'
}

kotlin {
jvmToolchain(11)
}

dependencies {
implementation deps.kotlin.stdlib
implementation deps.dagger
Expand Down
9 changes: 3 additions & 6 deletions ast/src/main/kotlin/motif/ast/IrAnnotated.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ interface IrAnnotated {

val annotations: List<IrAnnotation>

fun hasAnnotation(annotationClass: KClass<out Annotation>): Boolean {
return annotations.any { it.matchesClass(annotationClass) }
}
fun hasAnnotation(annotationClass: KClass<out Annotation>): Boolean =
annotations.any { it.matchesClass(annotationClass) }

fun isNullable(): Boolean {
return annotations.any { it.className?.endsWith("Nullable") == true }
}
fun isNullable(): Boolean = annotations.any { it.className?.endsWith("Nullable") == true }
}
11 changes: 4 additions & 7 deletions ast/src/main/kotlin/motif/ast/IrClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ interface IrClass : IrAnnotated, IrHasModifiers {
val simpleName: String
get() = type.simpleName

fun hasNonDefaultConstructor(): Boolean {
return constructors.any { it.hasParameters() }
}
fun hasNonDefaultConstructor(): Boolean = constructors.any { it.hasParameters() }

fun annotatedInnerClass(annotationClass: KClass<out Annotation>): IrClass? {
return nestedClasses.find { it.hasAnnotation(annotationClass) }
}
fun annotatedInnerClass(annotationClass: KClass<out Annotation>): IrClass? =
nestedClasses.find { it.hasAnnotation(annotationClass) }

enum class Kind {
CLASS,
INTERFACE
INTERFACE,
}
}
16 changes: 4 additions & 12 deletions ast/src/main/kotlin/motif/ast/IrHasModifiers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ interface IrHasModifiers {

val modifiers: Set<IrModifier>

fun isStatic(): Boolean {
return IrModifier.STATIC in modifiers
}
fun isStatic(): Boolean = IrModifier.STATIC in modifiers

fun isPrivate(): Boolean {
return IrModifier.PRIVATE in modifiers
}
fun isPrivate(): Boolean = IrModifier.PRIVATE in modifiers

fun isPublic(): Boolean {
return IrModifier.PUBLIC in modifiers
}
fun isPublic(): Boolean = IrModifier.PUBLIC in modifiers

fun isAbstract(): Boolean {
return IrModifier.ABSTRACT in modifiers
}
fun isAbstract(): Boolean = IrModifier.ABSTRACT in modifiers
}
8 changes: 2 additions & 6 deletions ast/src/main/kotlin/motif/ast/IrMethod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ interface IrMethod : IrAnnotated, IrHasModifiers {
val name: String
val isConstructor: Boolean

fun hasParameters(): Boolean {
return parameters.isNotEmpty()
}
fun hasParameters(): Boolean = parameters.isNotEmpty()

fun isVoid(): Boolean {
return returnType.isVoid
}
fun isVoid(): Boolean = returnType.isVoid
}
2 changes: 1 addition & 1 deletion ast/src/main/kotlin/motif/ast/IrModifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ enum class IrModifier {
VOLATILE,
DEFAULT,
OPEN,
TRANSITIVE
TRANSITIVE,
}
1 change: 1 addition & 0 deletions ast/src/main/kotlin/motif/ast/IrType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface IrType : IrEquivalence {
get() = simpleName(qualifiedName)

fun resolveClass(): IrClass?

fun isAssignableTo(type: IrType): Boolean
}

Expand Down
7 changes: 3 additions & 4 deletions ast/src/test/kotlin/motif/ast/SimpleNameTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ class SimpleNameTest(private val qualifiedName: String, private val expectedSimp
"java.util.List<? super java.lang.String>" to "List<? super String>",
"java.util.Map<java.lang.String, java.lang.Integer>" to "Map<String, Integer>",
"java.util.Map<? extends java.lang.String, ? super java.lang.Integer>" to
"Map<? extends String, ? super Integer>")
"Map<? extends String, ? super Integer>",
)

@JvmStatic
@Parameterized.Parameters(name = "{0}")
fun data(): Collection<Array<Any>> {
return tests.map { (key, value) -> arrayOf(key, value) }
}
fun data(): Collection<Array<Any>> = tests.map { (key, value) -> arrayOf(key, value) }
}

@Test
Expand Down
35 changes: 34 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ buildscript {
}
dependencies {
classpath deps.build.gradlePlugins.android
classpath deps.build.gradlePlugins.intellij
classpath deps.build.gradlePlugins.kotlin
classpath deps.build.gradlePlugins.ksp
classpath deps.build.gradlePlugins.dokka
Expand Down Expand Up @@ -64,12 +65,37 @@ subprojects {
}
boolean isKotlinLibrary = project.plugins.hasPlugin("org.jetbrains.kotlin.jvm") || project.plugins.hasPlugin("org.jetbrains.kotlin.android")
if (isKotlinLibrary) {
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(11))
}
kotlin {
jvmToolchain(11)
}
it.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs += extraKotlincArgs
}
}
}

boolean isAndroidLibraryOrApp = project.plugins.hasPlugin("org.jetbrains.kotlin.android")
if (isAndroidLibraryOrApp) {
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}
}

if (isKotlinLibrary && isAndroidLibraryOrApp) {
android {
kotlinOptions {
jvmTarget = "1.8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to target 1.8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could prolly target 11 since it's tooling, but trying to limit the scope of this already large change

}
}
}
}

if (project.path != ":tests") {
Expand All @@ -83,7 +109,14 @@ subprojects {
}
kotlin {
target "src/**/*.kt"
ktlint(deps.versions.ktlint).userData(['indent_size': '2', 'continuation_indent_size': '2'])
ktlint(deps.versions.ktlint).editorConfigOverride([
"indent_size": "2",
"continuation_indent_size": "4"
])
suppressLintsFor {
step = 'ktlint'
shortCode = 'standard:function-naming'
}
ktfmt(deps.versions.ktfmt)
licenseHeaderFile rootProject.file('config/spotless/copyright.kt')
trimTrailingWhitespace()
Expand Down
4 changes: 0 additions & 4 deletions compiler/ast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ plugins {
id 'com.vanniktech.maven.publish'
}

kotlin {
jvmToolchain(11)
}

dependencies {
implementation deps.kotlin.stdlib
implementation deps.autoCommon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,23 @@ import com.google.auto.common.AnnotationMirrors
* Used to find equivalence of two XAnnotation since AnnotationMirrors.equivalence() only applies to
* the Javac backend.
*/
fun XAnnotation.isEquivalent(other: XAnnotation, env: XProcessingEnv): Boolean {
return if (env.backend == XProcessingEnv.Backend.JAVAC) {
val key = AnnotationMirrors.equivalence().wrap(this.toJavac())
val otherKey = AnnotationMirrors.equivalence().wrap(other.toJavac())
key == otherKey
} else {
(type.isEquivalent(other.type, env) &&
annotationValues.size == other.annotationValues.size &&
annotationValues.zip(other.annotationValues).all { (lhs, rhs) -> lhs.isEquivalent(rhs) })
}
}
fun XAnnotation.isEquivalent(other: XAnnotation, env: XProcessingEnv): Boolean =
if (env.backend == XProcessingEnv.Backend.JAVAC) {
val key = AnnotationMirrors.equivalence().wrap(this.toJavac())
val otherKey = AnnotationMirrors.equivalence().wrap(other.toJavac())
key == otherKey
} else {
(type.isEquivalent(other.type, env) &&
annotationValues.size == other.annotationValues.size &&
annotationValues.zip(other.annotationValues).all { (lhs, rhs) -> lhs.isEquivalent(rhs) })
}

/**
* Used to find equivalence of two XAnnotation since AnnotationMirrors.equivalence() only applies to
* the Javac backend.
*/
fun XAnnotationValue.isEquivalent(other: XAnnotationValue): Boolean {
return this.name == other.name && this.value == other.value
}
fun XAnnotationValue.isEquivalent(other: XAnnotationValue): Boolean =
this.name == other.name && this.value == other.value

/** Cleans up differences in the toString() methods between the JAVAC and KSP backends. */
fun XAnnotation.toPrettyString(): String {
Expand All @@ -55,7 +53,9 @@ fun XAnnotation.toPrettyString(): String {
.map {
if (it.name == "value") {
"\"${it.value}\""
} else "${it.name} = ${it.value}"
} else {
"${it.name} = ${it.value}"
}
}
.joinToString(", ")
val annotationValuesList =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ val XElement.modifiers: List<Modifier>
if (isFinal()) modifiers += Modifier.FINAL
if (isTransient()) modifiers += Modifier.TRANSIENT
return@let modifiers
}
?: emptyList()
} ?: emptyList()
}

val XElement.modifierNames: List<String>
get() = modifiers.map { it.name }

fun XHasModifiers.isPackagePrivate(): Boolean {
return !isPrivate() && !isProtected() && !isPublic()
}
fun XHasModifiers.isPackagePrivate(): Boolean = !isPrivate() && !isProtected() && !isPublic()
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ object XOverrides {
return when (env.backend) {
XProcessingEnv.Backend.JAVAC -> {
MoreElements.overrides(
overrider.toJavac(), overridden.toJavac(), inType.toJavac(), env.toJavac().typeUtils)
overrider.toJavac(),
overridden.toJavac(),
inType.toJavac(),
env.toJavac().typeUtils,
)
false
}
XProcessingEnv.Backend.KSP -> {
Expand Down Expand Up @@ -141,7 +145,8 @@ enum class Visibility {
DEFAULT,
PROTECTED,
INTERNAL,
PUBLIC;
PUBLIC,
;

companion object {
fun of(element: XMethodElement) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ val XProcessingEnv.typeUtils
get() = XTypeUtils

/** Provides access to KSP's resolver since XProcessing does not give us access */
fun XProcessingEnv.resolver(): Resolver? {
return if (backend == XProcessingEnv.Backend.KSP) {
Class.forName("androidx.room.compiler.processing.ksp.KspProcessingEnv")
?.getDeclaredField("_resolver")
?.apply { isAccessible = true }
?.get(this) as
Resolver?
} else {
null
}
}
fun XProcessingEnv.resolver(): Resolver? =
if (backend == XProcessingEnv.Backend.KSP) {
Class.forName("androidx.room.compiler.processing.ksp.KspProcessingEnv")
?.getDeclaredField("_resolver")
?.apply { isAccessible = true }
?.get(this) as Resolver?
} else {
null
}
Loading