Repository: square/anvil (kotlin)

Issue:
Anvil treats named imports as normal imports
Assume we have 
```
import java.util.Date as Instant
import com.squareup.test.*
```
where the package `com.squareup.test` contains a `Date` class, then Anvil will resolve the class as `java.util.Date`. This is because named imports are not filtered out when we try to resolve a class

Pull request description:
Fixes #137

Patch:
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 78ee39696..48e790aa7 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
@@ -239,12 +239,14 @@ internal fun PsiElement.requireFqName(
   // First look in the imports for the reference name. If the class is imported, then we know the
   // fully qualified name.
   importPaths
+      .filter { it.alias == null }
       .firstOrNull {
         it.fqName.shortName().asString() == classReference
       }
       ?.let { return it.fqName }
 
   importPaths
+      .filter { it.alias == null }
       .firstOrNull {
         it.fqName.shortName().asString() == classReferenceOuter
       }


Test patch:
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 dd72026ad..4312a3a8c 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
@@ -16,6 +16,7 @@ import org.junit.runner.RunWith
 import org.junit.runners.Parameterized
 import org.junit.runners.Parameterized.Parameters
 import java.io.File
+import java.util.Date
 import javax.inject.Provider
 
 @Suppress("UNCHECKED_CAST")
@@ -2250,6 +2251,42 @@ public final class DaggerComponentInterface implements ComponentInterface {
     }
   }
 
+  @Test
+  fun `a factory class is generated ignoring the named import original path`() {
+    compile(
+      """
+        package com.squareup.test
+        
+        import dagger.Module
+        import dagger.Provides
+        import java.util.*
+        import com.squareup.anvil.compiler.dagger.Date as AnotherDate
+
+        @Module
+        object DaggerModule1 {
+          @Provides fun provideDate(): Date = Date(1000)
+        }
+        """
+    ) {
+      val factoryClass = daggerModule1.moduleFactoryClass("provideDate")
+
+      val constructor = factoryClass.declaredConstructors.single()
+      assertThat(constructor.parameterTypes.toList()).isEmpty()
+
+      val staticMethods = factoryClass.declaredMethods.filter { it.isStatic }
+
+      val factoryInstance = staticMethods.single { it.name == "create" }
+        .invoke(null) as Factory<Any>
+      assertThat(factoryInstance::class.java).isEqualTo(factoryClass)
+
+      val providedContributingObject = staticMethods
+        .single { it.name == "provideDate" }
+        .invoke(null)
+
+      assertThat(providedContributingObject).isInstanceOf(Date::class.java)
+    }
+  }
+
   @Test fun `a return type for a provider method is required`() {
     compile(
         """
diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/TestClasses.kt b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/TestClasses.kt
index 84c7c4b45..73579e631 100644
--- a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/TestClasses.kt
+++ b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/TestClasses.kt
@@ -6,6 +6,8 @@ package com.squareup.anvil.compiler.dagger
 
 object Factory
 
+object Date
+
 abstract class OuterClass constructor(innerClass: InnerClass) {
   class InnerClass
 }