diff --git a/ast/build.gradle b/ast/build.gradle index 800c2361..8814d457 100644 --- a/ast/build.gradle +++ b/ast/build.gradle @@ -1,11 +1,12 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -apply plugin: 'kotlin-kapt' - -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} dependencies { implementation deps.kotlin.stdlib @@ -14,5 +15,3 @@ dependencies { testImplementation deps.test.junit testImplementation deps.test.truth } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/compiler/ast/build.gradle b/compiler/ast/build.gradle index df0669ad..2000d89a 100644 --- a/compiler/ast/build.gradle +++ b/compiler/ast/build.gradle @@ -1,12 +1,12 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -apply plugin: 'kotlin-kapt' - -sourceCompatibility = 1.8 - +kotlin { + jvmToolchain(11) +} dependencies { implementation deps.kotlin.stdlib @@ -22,5 +22,3 @@ dependencies { testImplementation deps.test.compileTesting testImplementation deps.test.roomCompilerProcessingTesting } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/compiler/build.gradle b/compiler/build.gradle index 768ca945..9898e8ce 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -1,9 +1,12 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} dependencies { implementation deps.kotlin.stdlib @@ -35,5 +38,3 @@ dependencies { test { inputs.files(file("$rootDir/tests/src")) } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/compiler/ksp/build.gradle b/compiler/ksp/build.gradle index 660d1c69..50c907d7 100644 --- a/compiler/ksp/build.gradle +++ b/compiler/ksp/build.gradle @@ -1,8 +1,11 @@ plugins { id 'org.jetbrains.kotlin.jvm' + id 'com.vanniktech.maven.publish' } -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} dependencies { implementation deps.kotlin.stdlib @@ -27,5 +30,3 @@ dependencies { testImplementation deps.test.compileTesting testImplementation deps.test.compileTestingKotlin } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/compiler/src/main/kotlin/motif/compiler/XFunSpec.kt b/compiler/src/main/kotlin/motif/compiler/XFunSpec.kt index 22547fca..8ce264d5 100644 --- a/compiler/src/main/kotlin/motif/compiler/XFunSpec.kt +++ b/compiler/src/main/kotlin/motif/compiler/XFunSpec.kt @@ -23,13 +23,10 @@ import com.squareup.kotlinpoet.AnnotationSpec import com.squareup.kotlinpoet.FunSpec import com.squareup.kotlinpoet.KModifier import com.squareup.kotlinpoet.ParameterSpec -import com.squareup.kotlinpoet.javapoet.KotlinPoetJavaPoetPreview -import com.squareup.kotlinpoet.javapoet.toKTypeName import com.uber.xprocessing.ext.modifiers import javax.lang.model.element.Modifier import motif.compiler.KotlinTypeWorkaround.javaToKotlinType -@OptIn(KotlinPoetJavaPoetPreview::class) object XFunSpec { /** Copied from [FunSpec.overriding] and modified to leverage [javaToKotlinType]& XProcessing. */ fun overriding( @@ -50,23 +47,13 @@ object XFunSpec { env.requireType(method.returnType.typeName) } - val builder = overriding(methodElement) - builder.returns(javaToKotlinType(returnType)) - - var i = 0 - val size = builder.parameters.size - val resolvedParameterTypes = method.parameterTypes - while (i < size) { - val parameter = builder.parameters[i] - val type = javaToKotlinType(resolvedParameterTypes[i]) - builder.parameters[i] = parameter.toBuilder(parameter.name, type).build() - i++ - } - - return builder + return overriding(methodElement, method.parameterTypes).returns(javaToKotlinType(returnType)) } - private fun overriding(method: XMethodElement): FunSpec.Builder { + private fun overriding( + method: XMethodElement, + resolvedParameterTypes: List + ): FunSpec.Builder { var modifiers: Set = method.modifiers.toMutableSet() require( Modifier.PRIVATE !in modifiers && @@ -90,9 +77,10 @@ object XFunSpec { .forEach { funBuilder.addTypeVariable(it) } */ - method.parameters.forEach { + method.parameters.forEachIndexed { index, parameter -> funBuilder.addParameter( - ParameterSpec.builder(it.name, it.type.typeName.toKTypeName()).build()) + ParameterSpec.builder(parameter.name, javaToKotlinType(resolvedParameterTypes[index])) + .build()) } if (method.isVarArgs()) { funBuilder.parameters[funBuilder.parameters.lastIndex] = diff --git a/core/build.gradle b/core/build.gradle index c1eba4b3..54698cdb 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,14 +1,15 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} dependencies { api project(':models') implementation deps.kotlin.stdlib } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/errormessage/build.gradle b/errormessage/build.gradle index eda0a098..15eefe39 100644 --- a/errormessage/build.gradle +++ b/errormessage/build.gradle @@ -1,14 +1,14 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -sourceCompatibility = 1.8 - +kotlin { + jvmToolchain(11) +} dependencies { implementation deps.kotlin.stdlib implementation project(':core') } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index c2b0f3ce..08290f26 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -42,13 +42,13 @@ ext.deps = [ targetSdkVersion: 30, gradlePlugins: [ - android: 'com.android.tools.build:gradle:4.2.0', + android: 'com.android.tools.build:gradle:7.4.2', kotlin: "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}", ksp: "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:${versions.ksp}", dokka: "org.jetbrains.dokka:dokka-gradle-plugin:${versions.dokka}", mavenPublish: 'com.vanniktech:gradle-maven-publish-plugin:0.18.0', spotless: "com.diffplug.spotless:spotless-plugin-gradle:5.11.0", - shadow: "com.github.jengelman.gradle.plugins:shadow:6.1.0", + shadow: "com.github.johnrengelman:shadow:8.1.0", ] ], "kotlin": [ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb702..1f017e4e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/intellij/ast/build.gradle b/intellij/ast/build.gradle index 6ffafded..be8451fe 100644 --- a/intellij/ast/build.gradle +++ b/intellij/ast/build.gradle @@ -2,6 +2,7 @@ plugins { id "org.jetbrains.intellij" version "1.15.0" id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } intellij { @@ -32,5 +33,3 @@ tasks { enabled = false } } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/intellij/build.gradle b/intellij/build.gradle index a9b28868..8f347d89 100644 --- a/intellij/build.gradle +++ b/intellij/build.gradle @@ -2,6 +2,7 @@ plugins { id "org.jetbrains.intellij" version "1.15.0" id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } intellij { @@ -42,5 +43,3 @@ tasks { enabled = false } } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/lib/build.gradle b/lib/build.gradle index 016a1b67..e5b5bc47 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,4 +1,7 @@ -apply plugin: 'java-library' +plugins { + id 'java-library' + id 'com.vanniktech.maven.publish' +} sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -7,5 +10,3 @@ dependencies { // Dagger is part of the API since we generate code which depends on Dagger's API in the consuming gradle module. api deps.dagger } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/models/build.gradle b/models/build.gradle index 7ec1c7b1..9bc86355 100644 --- a/models/build.gradle +++ b/models/build.gradle @@ -1,12 +1,12 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -apply plugin: 'kotlin-kapt' - -sourceCompatibility = 1.8 - +kotlin { + jvmToolchain(11) +} dependencies { api project(':ast') @@ -19,5 +19,3 @@ dependencies { testImplementation deps.test.truth testImplementation deps.test.compileTesting } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/samples/sample-kotlin-ksp/build.gradle b/samples/sample-kotlin-ksp/build.gradle index fd8cdecf..fef42637 100644 --- a/samples/sample-kotlin-ksp/build.gradle +++ b/samples/sample-kotlin-ksp/build.gradle @@ -4,6 +4,10 @@ plugins { id 'org.jetbrains.kotlin.android' } +kotlin { + jvmToolchain(11) +} + android { compileSdkVersion deps.build.compileSdkVersion buildToolsVersion deps.build.buildToolsVersion @@ -26,8 +30,8 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } variantFilter { variant -> diff --git a/samples/sample-kotlin/build.gradle b/samples/sample-kotlin/build.gradle index d3a8bca6..bedc5f63 100644 --- a/samples/sample-kotlin/build.gradle +++ b/samples/sample-kotlin/build.gradle @@ -1,8 +1,12 @@ plugins { id 'com.android.application' + id 'kotlin-android' + id 'kotlin-kapt' +} + +kotlin { + jvmToolchain(11) } -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' android { compileSdkVersion deps.build.compileSdkVersion @@ -25,8 +29,8 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } variantFilter { variant -> diff --git a/samples/sample-lib-ksp/build.gradle b/samples/sample-lib-ksp/build.gradle index 8d5b1cb9..6975623f 100644 --- a/samples/sample-lib-ksp/build.gradle +++ b/samples/sample-lib-ksp/build.gradle @@ -4,6 +4,10 @@ plugins { id 'org.jetbrains.kotlin.android' } +kotlin { + jvmToolchain(11) +} + android { namespace 'com.example.sample_lib_ksp' compileSdkVersion deps.build.compileSdkVersion @@ -26,8 +30,8 @@ android { } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } androidComponents { diff --git a/tests/build.gradle b/tests/build.gradle index 0b5a6326..840b3db7 100644 --- a/tests/build.gradle +++ b/tests/build.gradle @@ -1,12 +1,13 @@ plugins { id 'com.google.devtools.ksp' + id 'java-library' + id 'kotlin' + id 'kotlin-kapt' } -apply plugin: 'java-library' -apply plugin: 'kotlin' -apply plugin: 'kotlin-kapt' - -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} kotlin { sourceSets { diff --git a/tests/compiler/build.gradle b/tests/compiler/build.gradle index 7e1404fb..640c8f4e 100644 --- a/tests/compiler/build.gradle +++ b/tests/compiler/build.gradle @@ -2,7 +2,9 @@ plugins { id 'org.jetbrains.kotlin.jvm' } -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} dependencies { implementation deps.autoCommon diff --git a/tests/src/main/java/testcases/KT006_reference_self/Child.kt b/tests/src/main/java/testcases/KT006_reference_self/Child.kt new file mode 100644 index 00000000..0ccfeed6 --- /dev/null +++ b/tests/src/main/java/testcases/KT006_reference_self/Child.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package testcases.KT006_reference_self + +@motif.Scope +interface Child { + + @motif.Objects + abstract class Objects : ObjectComponent + +} \ No newline at end of file diff --git a/tests/src/main/java/testcases/KT006_reference_self/Foo.kt b/tests/src/main/java/testcases/KT006_reference_self/Foo.kt new file mode 100644 index 00000000..b68ef420 --- /dev/null +++ b/tests/src/main/java/testcases/KT006_reference_self/Foo.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package testcases.KT006_reference_self + +interface Foo +class Bar : Foo +interface ObjectComponent> { + fun generic(someFoo: T): Foo +} \ No newline at end of file diff --git a/tests/src/main/java/testcases/KT006_reference_self/GRAPH.txt b/tests/src/main/java/testcases/KT006_reference_self/GRAPH.txt new file mode 100644 index 00000000..33bc45a4 --- /dev/null +++ b/tests/src/main/java/testcases/KT006_reference_self/GRAPH.txt @@ -0,0 +1,57 @@ +######################################################################## +# # +# This file is auto-generated by running the Motif compiler tests and # +# serves a as validation of graph correctness. IntelliJ plugin tests # +# also rely on this file to ensure that the plugin graph understanding # +# is equivalent to the compiler's. # +# # +# - Do not edit manually. # +# - Commit changes to source control. # +# - Since this file is autogenerated, code review changes carefully to # +# ensure correctness. # +# # +######################################################################## + + ------- +| Scope | + ------- + + ==== Required ==== + + ==== Provides ==== + + ---- Bar | Objects.bar ---- + [ Required ] + [ Consumed By ] + * Child | Objects.generic(someFoo) + + ---- Scope | implicit ---- + [ Required ] + [ Consumed By ] + + ------- + | Child | + ------- + + ==== Required ==== + + ---- Bar ---- + [ Provided By ] + * Scope | Objects.bar + [ Consumed By ] + * Child | Objects.generic(someFoo) + + ==== Provides ==== + + ---- Child | implicit ---- + [ Required ] + [ Consumed By ] + + ---- Foo | Objects.generic ---- + [ Required ] + Bar + [ Provided By ] + * Scope | Objects.bar + [ Consumed By ] + + diff --git a/tests/src/main/java/testcases/KT006_reference_self/Scope.kt b/tests/src/main/java/testcases/KT006_reference_self/Scope.kt new file mode 100644 index 00000000..6138d23c --- /dev/null +++ b/tests/src/main/java/testcases/KT006_reference_self/Scope.kt @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package testcases.KT006_reference_self + +import motif.Expose + +@motif.Scope +interface Scope { + + fun child(): Child + + @motif.Objects + abstract class Objects { + + @Expose + fun bar(): Bar = Bar() + } +} \ No newline at end of file diff --git a/tests/src/main/java/testcases/KT006_reference_self/Test.java b/tests/src/main/java/testcases/KT006_reference_self/Test.java new file mode 100644 index 00000000..21ed2131 --- /dev/null +++ b/tests/src/main/java/testcases/KT006_reference_self/Test.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package testcases.KT006_reference_self; + +import static com.google.common.truth.Truth.assertThat; + +public class Test { + + public static void run() { + Scope scope = new ScopeImpl(); + assertThat(scope.child()).isNotNull(); + } +} diff --git a/viewmodel/build.gradle b/viewmodel/build.gradle index 386cacda..96283119 100644 --- a/viewmodel/build.gradle +++ b/viewmodel/build.gradle @@ -1,9 +1,12 @@ plugins { id 'org.jetbrains.kotlin.jvm' id 'org.jetbrains.dokka' + id 'com.vanniktech.maven.publish' } -sourceCompatibility = 1.8 +kotlin { + jvmToolchain(11) +} dependencies { api project(':core') @@ -12,5 +15,3 @@ dependencies { implementation deps.kotlin.stdlib } - -apply plugin: 'com.vanniktech.maven.publish' diff --git a/xprocessing-testing/build.gradle b/xprocessing-testing/build.gradle index 2985bfd5..75c06fb6 100644 --- a/xprocessing-testing/build.gradle +++ b/xprocessing-testing/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' + id 'com.vanniktech.maven.publish' } java { @@ -21,7 +22,7 @@ shadowJar { dependencies { include dependency(deps.test.roomCompilerProcessingTesting) } - classifier = '' + archiveClassifier = '' configurations = [shadedConfig] mergeServiceFiles() relocate 'androidx.room.compiler.processing', 'motif.compiler.processing' @@ -43,5 +44,3 @@ artifacts { runtimeOnly shadowJar archives shadowJar } - -apply plugin: "com.vanniktech.maven.publish" diff --git a/xprocessing/build.gradle b/xprocessing/build.gradle index 2e4e8383..41eb88c7 100644 --- a/xprocessing/build.gradle +++ b/xprocessing/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'com.github.johnrengelman.shadow' + id 'com.vanniktech.maven.publish' } java { @@ -21,7 +22,7 @@ shadowJar { dependencies { include dependency(deps.roomCompilerProcessing) } - classifier = '' + archiveClassifier = '' configurations = [shadedConfig] mergeServiceFiles() relocate 'androidx.room.compiler.processing', 'motif.compiler.processing' @@ -43,5 +44,3 @@ artifacts { runtimeOnly shadowJar archives shadowJar } - -apply plugin: "com.vanniktech.maven.publish"