Noarg: somewhat refactor tests
Extract method that registers components, merge abstract test classes into one file.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.noarg
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.*
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
@@ -66,7 +67,7 @@ class NoArgCommandLineProcessor : CommandLineProcessor {
|
||||
required = false, allowMultipleOccurrences = false
|
||||
)
|
||||
|
||||
val PLUGIN_ID = "org.jetbrains.kotlin.noarg"
|
||||
const val PLUGIN_ID = "org.jetbrains.kotlin.noarg"
|
||||
}
|
||||
|
||||
override val pluginId = PLUGIN_ID
|
||||
@@ -82,16 +83,20 @@ class NoArgCommandLineProcessor : CommandLineProcessor {
|
||||
|
||||
class NoArgComponentRegistrar : ComponentRegistrar {
|
||||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
|
||||
val annotations = configuration.get(ANNOTATION)?.toMutableList() ?: mutableListOf()
|
||||
val annotations = configuration.get(ANNOTATION).orEmpty().toMutableList()
|
||||
configuration.get(PRESET)?.forEach { preset ->
|
||||
SUPPORTED_PRESETS[preset]?.let { annotations += it }
|
||||
}
|
||||
if (annotations.isEmpty()) return
|
||||
if (annotations.isNotEmpty()) {
|
||||
registerNoArgComponents(project, annotations, configuration.getBoolean(INVOKE_INITIALIZERS))
|
||||
}
|
||||
}
|
||||
|
||||
StorageComponentContainerContributor.registerExtension(project, CliNoArgComponentContainerContributor(annotations))
|
||||
|
||||
val invokeInitializers = configuration[INVOKE_INITIALIZERS] ?: false
|
||||
ExpressionCodegenExtension.registerExtension(project, CliNoArgExpressionCodegenExtension(annotations, invokeInitializers))
|
||||
internal companion object {
|
||||
fun registerNoArgComponents(project: Project, annotations: List<String>, invokeInitializers: Boolean) {
|
||||
StorageComponentContainerContributor.registerExtension(project, CliNoArgComponentContainerContributor(annotations))
|
||||
ExpressionCodegenExtension.registerExtension(project, CliNoArgExpressionCodegenExtension(annotations, invokeInitializers))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +108,4 @@ class CliNoArgComponentContainerContributor(val annotations: List<String>) : Sto
|
||||
|
||||
container.useInstance(CliNoArgDeclarationChecker(annotations))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.noarg
|
||||
|
||||
import org.jetbrains.kotlin.codegen.AbstractBlackBoxCodegenTest
|
||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor.Companion.registerExtension
|
||||
import org.jetbrains.kotlin.noarg.AbstractBytecodeListingTestForNoArg.Companion.NOARG_ANNOTATIONS
|
||||
|
||||
abstract class AbstractBlackBoxCodegenTestForNoArg : AbstractBlackBoxCodegenTest() {
|
||||
override fun loadMultiFiles(files: MutableList<TestFile>) {
|
||||
val project = myEnvironment.project
|
||||
registerExtension(project, CliNoArgComponentContainerContributor(NOARG_ANNOTATIONS))
|
||||
val invokeInitializers = files.any { "// INVOKE_INITIALIZERS" in it.content }
|
||||
ExpressionCodegenExtension.registerExtension(project, CliNoArgExpressionCodegenExtension(NOARG_ANNOTATIONS, invokeInitializers))
|
||||
|
||||
super.loadMultiFiles(files)
|
||||
}
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.noarg
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.AbstractBytecodeListingTest
|
||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
|
||||
|
||||
abstract class AbstractBytecodeListingTestForNoArg : AbstractBytecodeListingTest() {
|
||||
internal companion object {
|
||||
val NOARG_ANNOTATIONS = listOf("NoArg", "NoArg2", "test.NoArg")
|
||||
}
|
||||
|
||||
override fun setupEnvironment(environment: KotlinCoreEnvironment) {
|
||||
val project = environment.project
|
||||
StorageComponentContainerContributor.registerExtension(project, CliNoArgComponentContainerContributor(NOARG_ANNOTATIONS))
|
||||
ExpressionCodegenExtension.registerExtension(project, CliNoArgExpressionCodegenExtension(NOARG_ANNOTATIONS, false))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.noarg
|
||||
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.AbstractBlackBoxCodegenTest
|
||||
import org.jetbrains.kotlin.codegen.AbstractBytecodeListingTest
|
||||
|
||||
internal val NOARG_ANNOTATIONS = listOf("NoArg", "NoArg2", "test.NoArg")
|
||||
|
||||
abstract class AbstractBlackBoxCodegenTestForNoArg : AbstractBlackBoxCodegenTest() {
|
||||
override fun loadMultiFiles(files: MutableList<TestFile>) {
|
||||
NoArgComponentRegistrar.registerNoArgComponents(
|
||||
myEnvironment.project,
|
||||
NOARG_ANNOTATIONS,
|
||||
files.any { it.directives.contains("INVOKE_INITIALIZERS") },
|
||||
)
|
||||
|
||||
super.loadMultiFiles(files)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractBytecodeListingTestForNoArg : AbstractBytecodeListingTest() {
|
||||
override fun setupEnvironment(environment: KotlinCoreEnvironment) {
|
||||
NoArgComponentRegistrar.registerNoArgComponents(environment.project, NOARG_ANNOTATIONS, false)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user