diff --git a/ChangeLog.md b/ChangeLog.md index 5f5ee5eb3c0..a520c1a62b2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,7 @@ Issues fixed: - [KT-11145](https://youtrack.jetbrains.com/issue/KT-11145) Use progress indicator when searching usages in Introduce Parameter +- [KT-11155](https://youtrack.jetbrains.com/issue/KT-11155) Allow running multiple Kotlin classes as well as running mixtures of Kotlin and Java classes #### Debugger diff --git a/idea/src/META-INF/junit.xml b/idea/src/META-INF/junit.xml index 7484657e0f0..94aa5be13c8 100644 --- a/idea/src/META-INF/junit.xml +++ b/idea/src/META-INF/junit.xml @@ -1,5 +1,6 @@ + diff --git a/idea/src/org/jetbrains/kotlin/idea/run/KotlinPatternConfigurationProducer.kt b/idea/src/org/jetbrains/kotlin/idea/run/KotlinPatternConfigurationProducer.kt new file mode 100644 index 00000000000..a48f7e22ef0 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/run/KotlinPatternConfigurationProducer.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * 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 org.jetbrains.kotlin.idea.run + +import com.intellij.execution.actions.ConfigurationContext +import com.intellij.execution.actions.ConfigurationFromContext +import com.intellij.execution.junit.JUnitConfiguration +import com.intellij.execution.junit.PatternConfigurationProducer +import com.intellij.execution.junit.TestClassConfigurationProducer +import com.intellij.openapi.util.Ref +import com.intellij.psi.PsiElement +import com.intellij.psi.search.PsiElementProcessor +import org.jetbrains.kotlin.asJava.toLightClass +import org.jetbrains.kotlin.psi.KtClassOrObject + +class KotlinPatternConfigurationProducer : PatternConfigurationProducer() { + override fun setupConfigurationFromContext( + configuration: JUnitConfiguration, + context: ConfigurationContext, + sourceElement: Ref + ): Boolean { + return super.setupConfigurationFromContext(configuration, context, sourceElement) + } + + override fun collectTestMembers( + psiElements: Array, + checkAbstract: Boolean, + checkIsTest: Boolean, + collectingProcessor: PsiElementProcessor.CollectElements + ) { + val adjustedElements = psiElements.mapNotNull { if (it is KtClassOrObject) it.toLightClass() else it }.toTypedArray() + super.collectTestMembers(adjustedElements, checkAbstract, checkIsTest, collectingProcessor) + } + + override fun shouldReplace(self: ConfigurationFromContext, other: ConfigurationFromContext): Boolean { + return other.isProducedBy(PatternConfigurationProducer::class.java) + || other.isProducedBy(TestClassConfigurationProducer::class.java) + || other.isProducedBy(KotlinJUnitRunConfigurationProducer::class.java) + } +}