Remove StorageComponentContainerContributor::onContainerComposed

Rename addDeclarations -> registerModuleComponents
Use it to provide SamWithReceiverResolver extensions instead

Post construction on container composition can be achieved
    but manually inserting injections where it seems appropriate
    is bug prone
This fixes a bug where SamWithReceiverPlugin extension was not registered
    for some containers in IDE which led to incorrect highlighting in IDE
Add IDE test for applying SamWithReceiver plugin

 #KT-18062 Fixed
This commit is contained in:
Pavel V. Talanov
2017-08-17 17:33:03 +03:00
parent 6f180416b1
commit 6424b6760f
26 changed files with 199 additions and 75 deletions
+1
View File
@@ -70,5 +70,6 @@
<orderEntry type="module" module-name="backend.jvm" />
<orderEntry type="library" name="kotlin-reflect" level="project" />
<orderEntry type="module" module-name="idea-gradle" scope="TEST" />
<orderEntry type="module" module-name="sam-with-receiver-cli" scope="TEST" />
</component>
</module>
@@ -0,0 +1,4 @@
package anno
annotation class A
annotation class B
@@ -0,0 +1,8 @@
package javaInterface;
public class API {
public <T> void useM1A(InterfaceM1A<T> m1A);
public <G> void useM1B(InterfaceM1B<G> m1B);
public <T> void useM2A(InterfaceM2A<T> m1A);
public <G> void useM2B(InterfaceM2B<G> m1B);
}
@@ -0,0 +1,6 @@
package javaInterface;
@anno.A
interface InterfaceM1A<T> {
void foo(T t);
}
@@ -0,0 +1,6 @@
package javaInterface;
@anno.B
interface InterfaceM1B<T> {
void foo(T t);
}
@@ -0,0 +1,31 @@
package m1
public fun testUseAsReceiver(api: javaInterface.API) {
api.useM1A<String> {
this.length
}
api.useM1B<String> {
<error>this</error>.length
}
api.useM2A<String> {
this.length
}
api.useM2B<String> {
<error>this</error>.length
}
}
public fun testUseAsParameter(api: javaInterface.API) {
api.useM1A<String> {
<error>it</error>.length
}
api.useM1B<String> {
it.length
}
api.useM2A<String> {
<error>it</error>.length
}
api.useM2B<String> {
it.length
}
}
@@ -0,0 +1,6 @@
package javaInterface;
@anno.A
interface InterfaceM2A<T> {
void foo(T t);
}
@@ -0,0 +1,6 @@
package javaInterface;
@anno.B
interface InterfaceM2B<T> {
void foo(T t);
}
@@ -0,0 +1,31 @@
package m2
public fun testUseAsReceiver(api: javaInterface.API) {
api.useM1A<String> {
<error>this</error>.length
}
api.useM1B<String> {
this.length
}
api.useM2A<String> {
<error>this</error>.length
}
api.useM2B<String> {
this.length
}
}
public fun testUseAsParameter(api: javaInterface.API) {
api.useM1A<String> {
it.length
}
api.useM1B<String> {
<error>it</error>.length
}
api.useM2A<String> {
it.length
}
api.useM2B<String> {
<error>it</error>.length
}
}
@@ -44,6 +44,8 @@ import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.idea.util.projectStructure.sdk
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor.Companion.ANNOTATION_OPTION
import org.jetbrains.kotlin.samWithReceiver.SamWithReceiverCommandLineProcessor.Companion.PLUGIN_ID
import org.jetbrains.kotlin.test.TestJdkKind.FULL_JDK
open class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
@@ -193,6 +195,25 @@ open class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
checkHighlightingInAllFiles()
}
fun testSamWithReceiverExtension() {
val module1 = module("m1").setupKotlinFacet {
settings.compilerArguments!!.pluginOptions =
arrayOf("plugin:${PLUGIN_ID}:${ANNOTATION_OPTION.name}=anno.A")
}
val module2 = module("m2").setupKotlinFacet {
settings.compilerArguments!!.pluginOptions =
arrayOf("plugin:${PLUGIN_ID}:${ANNOTATION_OPTION.name}=anno.B")
}
module1.addDependency(module2)
module2.addDependency(module1)
checkHighlightingInAllFiles()
}
private fun Module.setupKotlinFacet(configure: KotlinFacetConfiguration.() -> Unit) = apply {
runWriteAction {
val facet = FacetManager.getInstance(this).addFacet(KotlinFacetType.INSTANCE, KotlinFacetType.NAME, null)