anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: square/anvil
Issue: Support named import

The following class is processed successfully by Dagger compiler but not by Anvil
```
package com.squareup.test

import dagger.Module
import dagger.Provides
import java.lang.Runnable as NamedRunnable
        
@Module
object DaggerModule1 {
    @Provides fun provideRunner(): NamedRunnable = NamedRunnable {}
}
```

Changed files:
compiler/src/main/java/com/squareup/anvil/compiler/codegen/PsiUtils.kt
compiler/src/test/java/com/squareup/anvil/compiler/dagger/ProvidesMethodFactoryGeneratorTest.kt

diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/PsiUtils.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/PsiUtils.kt
index dd590fa..cbe7b68 100644
--- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/PsiUtils.kt
+++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/PsiUtils.kt
@@ -278,6 +278,12 @@ internal fun PsiElement.requireFqName(
         module.findClassOrTypeAlias(importFqName, classReference)?.let { return it.fqNameSafe }
       }
 
+  // Check if it's a named import.
+  containingKtFile.importDirectives
+    .firstOrNull { classReference == it.importPath?.importedName?.asString() }
+    ?.importedFqName
+    ?.let { return it }
+
   // Everything else isn't supported.
   throw AnvilCompilationException(
       "Couldn't resolve FqName $classReference for Psi element: $text",
diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/ProvidesMethodFactoryGeneratorTest.kt b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/ProvidesMethodFactoryGeneratorTest.kt
index fe31178..b0b8ca6 100644
--- a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/ProvidesMethodFactoryGeneratorTest.kt
+++ b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/ProvidesMethodFactoryGeneratorTest.kt
@@ -2226,6 +2226,29 @@ public final class DaggerComponentInterface implements ComponentInterface {
     }
   }
 
+  @Test
+  fun `a factory class is generated for a method returning a class with a named import`() {
+    compile(
+      """
+        package com.squareup.test
+        
+        import dagger.Module
+        import dagger.Provides
+        import java.lang.Runnable as NamedRunnable
+        
+        @Module
+        object DaggerModule1 {
+          @Provides fun provideRunner(): NamedRunnable = NamedRunnable {}
+        }
+        """
+    ) {
+      val factoryClass = daggerModule1.moduleFactoryClass("provideRunner")
+
+      val constructor = factoryClass.declaredConstructors.single()
+      assertThat(constructor.parameterTypes.toList()).isEmpty()
+    }
+  }
+
   private fun compile(
     source: String,
     block: Result.() -> Unit = { }
Repository: fasterxml/jackson-module-kotlin
Issue: Minor bugs in `SimpleModule.addSerializer`/`addDeserializer`

**Describe the bug**
The current process is as follows.
Although it is a guess since there are no comments, the registration is done for both `kClass.java` and `kClass.javaObjectType`, which seems to be aimed at preventing registration omissions when `T` is a `primitive` type.

```kotlin
inline fun <reified T : Any> SimpleModule.addSerializer(kClass: KClass<T>, serializer: JsonSerializer<T>) = this.apply {
    addSerializer(kClass.java, serializer)
    addSerializer(kClass.javaObjectType, serializer)
}
```

On the other hand, as shown below, if you specify a wrapper type for the `primitive` type, `kClass.java` will return the wrapper type.
In other words, this pattern omits registration for the `primitive` type.

```kotlin
val klazz = Integer::class
// -> java.lang.Integer
println(klazz.java.name)
// -> java.lang.Integer
println(klazz.javaObjectType.name)
```

**Additional context**
If it is a straightforward fix, it could be modified to register only when `kClass.javaPrimitiveType` is `non-null`.
However, I personally feel that it would be better to keep only `addSerializer(kClass.java, serializer)` to match the `Jackson` behavior.

Changed files:
src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt

diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt
index 7b1571d..4179a17 100644
--- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt
+++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt
@@ -97,13 +97,13 @@ operator fun JsonNode.contains(index: Int) = has(index)
 internal fun JsonMappingException.wrapWithPath(refFrom: Any?, refFieldName: String) = JsonMappingException.wrapWithPath(this, refFrom, refFieldName)
 internal fun JsonMappingException.wrapWithPath(refFrom: Any?, index: Int) = JsonMappingException.wrapWithPath(this, refFrom, index)
 
-inline fun <reified T : Any> SimpleModule.addSerializer(kClass: KClass<T>, serializer: JsonSerializer<T>) = this.apply {
-    addSerializer(kClass.java, serializer)
+fun <T : Any> SimpleModule.addSerializer(kClass: KClass<T>, serializer: JsonSerializer<T>): SimpleModule = this.apply {
+    kClass.javaPrimitiveType?.let { addSerializer(it, serializer) }
     addSerializer(kClass.javaObjectType, serializer)
 }
 
-inline fun <reified T : Any> SimpleModule.addDeserializer(kClass: KClass<T>, deserializer: JsonDeserializer<T>) = this.apply {
-    addDeserializer(kClass.java, deserializer)
+fun <T : Any> SimpleModule.addDeserializer(kClass: KClass<T>, deserializer: JsonDeserializer<T>): SimpleModule = this.apply {
+    kClass.javaPrimitiveType?.let { addDeserializer(it, deserializer) }
     addDeserializer(kClass.javaObjectType, deserializer)
 }