forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the javac element to get the @BindsInstance parameter name.
This CL fixes an issue where the parameter name for a ComponentRequirement causes a cache-miss for that requirement. This occurs because one ComponentRequirement uses the name from JavacMethodParameter.getName() which pulls the original parameter name from the KotlinMetadata, and the other uses VariableElement.getSimpleName() which may match the original parameter in some cases but may be "arg0" if the name comes from a precompiled class. This difference in name causes the cache miss. I'll need to look into if this is something we should fix on the XProcessing side, e.g. have the user explicitly choose if they want to use the name from the kotlin metadata. Fixes #2997 Fixes #3032 RELNOTES=N/A PiperOrigin-RevId: 411640088
- Loading branch information
Showing
10 changed files
with
139 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger Authors. | ||
* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id 'application' | ||
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" | ||
id 'org.jetbrains.kotlin.kapt' version "$kotlin_version" | ||
} | ||
|
||
java { | ||
// Make sure the generated source is compatible with Java 8. | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
dependencies { | ||
implementation project(path: ':kotlin-library') | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'com.google.dagger:dagger:LOCAL-SNAPSHOT' | ||
kapt 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT' | ||
|
||
// This is testImplementation rather than kaptTest because we're actually | ||
// testing the reference to ComponentProcessor. | ||
// See https://github.com/google/dagger/issues/2765 | ||
testImplementation 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT' | ||
testImplementation 'com.google.truth:truth:1.0.1' | ||
testImplementation 'junit:junit:4.13' | ||
} | ||
|
||
application { | ||
mainClass = 'dagger.simple.SimpleApplicationKt' | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
javatests/artifacts/dagger/simpleKotlin/kotlin-library/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger Authors. | ||
* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version" | ||
id 'org.jetbrains.kotlin.kapt' version "$kotlin_version" | ||
} | ||
|
||
java { | ||
// Make sure the generated source is compatible with Java 8. | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'com.google.dagger:dagger:LOCAL-SNAPSHOT' | ||
kapt 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT' | ||
|
||
// This is testImplementation rather than kaptTest because we're actually | ||
// testing the reference to ComponentProcessor. | ||
// See https://github.com/google/dagger/issues/2765 | ||
testImplementation 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT' | ||
testImplementation 'com.google.truth:truth:1.0.1' | ||
testImplementation 'junit:junit:4.13' | ||
} |
35 changes: 35 additions & 0 deletions
35
...ts/dagger/simpleKotlin/kotlin-library/src/main/java/dagger/simpleKotlin/MySubcomponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2021 The Dagger Authors. | ||
* | ||
* 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 dagger.simpleKotlin | ||
|
||
import dagger.BindsInstance | ||
import dagger.Subcomponent | ||
|
||
/** | ||
* This subcomponent reproduces a regression in https://github.com/google/dagger/issues/2997. | ||
*/ | ||
@Subcomponent | ||
abstract class MySubcomponent { | ||
abstract fun instance(): InstanceType | ||
|
||
@Subcomponent.Factory | ||
interface Factory { | ||
fun create(@BindsInstance instance: InstanceType): MySubcomponent | ||
} | ||
} | ||
|
||
class InstanceType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rootProject.name='Simple Kotlin Dagger' | ||
include ':app' | ||
include ':kotlin-library' |