Repository: evant/kotlin-inject (kotlin)

Issue:
Remove java.lang.String import from generated components
This snippet
 ```
import me.tatarka.inject.annotations.Component
import me.tatarka.inject.annotations.Inject
import me.tatarka.inject.annotations.Provides

fun main() {
    TestComponent::class.create("Hello World").factory.print()
}

@Component
abstract class TestComponent(@get:Provides protected val string: String) {
    abstract val factory: HelloWorldFactory
}

@Inject class HelloWorldFactory(private val string: String) {

    fun print() = println(string)
}
```
Generates this: 
```
import java.lang.String
import kotlin.reflect.KClass

class InjectTestComponent(
  string: String
) : TestComponent(string) {
  override val factory: HelloWorldFactory
    get() = HelloWorldFactory(string)}

fun KClass<TestComponent>.create(string: String): TestComponent = InjectTestComponent(string)
```

Which yields this error: 
```
Type mismatch.
Required:java.lang.String
Found:kotlin.String
```
![image](https://user-images.githubusercontent.com/1403243/90938325-d5eff200-e3d6-11ea-8942-40cd61c6898a.png)

Pull request:
Fixes #45

Patch:
diff --git a/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/ModelAst.kt b/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/ModelAst.kt
index 3d9406ab..aca31146 100644
--- a/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/ModelAst.kt
+++ b/kotlin-inject-compiler-kapt/src/main/kotlin/me/tatarka/inject/compiler/kapt/ModelAst.kt
@@ -569,7 +569,9 @@ private class ModelAstParam(
         ModelAstType(this, element.asType(), kmValueParameter?.type)
     }
 
-    override fun asParameterSpec(): ParameterSpec = ParameterSpec.get(element)
+    override fun asParameterSpec(): ParameterSpec {
+        return ParameterSpec(name, type.asTypeName())
+    }
 }
 
 private val KmClass.type: KmType


Test patch:
diff --git a/integration-tests/src/test/kotlin/me/tatarka/inject/test/ProvidesTest.kt b/integration-tests/src/test/kotlin/me/tatarka/inject/test/ProvidesTest.kt
index a43aabb1..733b40cd 100644
--- a/integration-tests/src/test/kotlin/me/tatarka/inject/test/ProvidesTest.kt
+++ b/integration-tests/src/test/kotlin/me/tatarka/inject/test/ProvidesTest.kt
@@ -156,6 +156,18 @@ class StringArrayFoo(val stringArray: Array<String>)
         @Provides get() = StringArrayFoo(this)
 }
 
+@Inject class ValConstructorBasicTypes(
+    val boolean: Boolean,
+    val string: String
+)
+
+@Component abstract class ProvidesValConstructorBasicTypes(
+    @get:Provides val boolean: Boolean,
+    @get:Provides val string: String
+) {
+    abstract val basicType: ValConstructorBasicTypes
+}
+
 class ProvidesTest {
 
     @Test fun generates_a_component_that_provides_a_dep_from_a_function() {
@@ -210,7 +222,7 @@ class ProvidesTest {
         assertThat(component.foo4).isNotNull()
     }
 
-    @Test fun generates_a_conmponent_that_provides_basic_types() {
+    @Test fun generates_a_component_that_provides_basic_types() {
         val component = ProvidesBasicTypes::class.create()
 
         assertThat(component.basicType.boolean).isTrue()
@@ -228,5 +240,15 @@ class ProvidesTest {
         assertThat(component.basicType.intArrayFoo.intArray.toTypedArray()).containsExactly(7)
         assertThat(component.basicType.stringArrayFoo.stringArray).containsExactly("c")
     }
+
+    @Test fun generates_a_component_that_provides_val_constructor_basic_types() {
+        val component = ProvidesValConstructorBasicTypes::class.create(
+            true,
+            "a"
+        )
+
+        assertThat(component.basicType.boolean).isTrue()
+        assertThat(component.basicType.string).isEqualTo("a")
+    }
 }