JVM IR: support noarg compiler plugin
#KT-41265 Fixed
This commit is contained in:
@@ -78,17 +78,17 @@ import org.jetbrains.kotlin.idea.editor.AbstractMultiLineStringIndentTest
|
||||
import org.jetbrains.kotlin.idea.editor.backspaceHandler.AbstractBackspaceHandlerTest
|
||||
import org.jetbrains.kotlin.idea.editor.quickDoc.AbstractQuickDocProviderTest
|
||||
import org.jetbrains.kotlin.idea.filters.AbstractKotlinExceptionFilterTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirMultiModuleResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.AbstractKtDeclarationAndFirDeclarationEqualityChecker
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyDeclarationResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLazyResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirMultiModuleLazyResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirMultiModuleResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureAndOutOfBlockModificationTrackerConsistencyTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.file.structure.AbstractFileStructureTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.sessions.AbstractSessionsInvalidationTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.trackers.AbstractProjectWideOutOfBlockKotlinModificationTrackerTest
|
||||
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.fir.AbstractResolveCallTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.trackers.AbstractProjectWideOutOfBlockKotlinModificationTrackerTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.scopes.AbstractMemberScopeByFqNameTest
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.*
|
||||
import org.jetbrains.kotlin.idea.hierarchy.AbstractHierarchyTest
|
||||
@@ -167,12 +167,12 @@ import org.jetbrains.kotlin.nj2k.inference.common.AbstractCommonConstraintCollec
|
||||
import org.jetbrains.kotlin.nj2k.inference.mutability.AbstractMutabilityInferenceTest
|
||||
import org.jetbrains.kotlin.nj2k.inference.nullability.AbstractNullabilityInferenceTest
|
||||
import org.jetbrains.kotlin.noarg.*
|
||||
import org.jetbrains.kotlin.pacelize.ide.test.AbstractParcelizeCheckerTest
|
||||
import org.jetbrains.kotlin.pacelize.ide.test.AbstractParcelizeQuickFixTest
|
||||
import org.jetbrains.kotlin.parcelize.test.AbstractParcelizeBoxTest
|
||||
import org.jetbrains.kotlin.parcelize.test.AbstractParcelizeBytecodeListingTest
|
||||
import org.jetbrains.kotlin.parcelize.test.AbstractParcelizeIrBoxTest
|
||||
import org.jetbrains.kotlin.parcelize.test.AbstractParcelizeIrBytecodeListingTest
|
||||
import org.jetbrains.kotlin.pacelize.ide.test.AbstractParcelizeCheckerTest
|
||||
import org.jetbrains.kotlin.pacelize.ide.test.AbstractParcelizeQuickFixTest
|
||||
import org.jetbrains.kotlin.psi.patternMatching.AbstractPsiUnifierTest
|
||||
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest
|
||||
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest
|
||||
@@ -1666,12 +1666,14 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractDiagnosticsTestForNoArg> { model("diagnostics", extension = "kt") }
|
||||
|
||||
testClass<AbstractBytecodeListingTestForNoArg> {
|
||||
model("bytecodeListing", extension = "kt")
|
||||
model("bytecodeListing", extension = "kt", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
testClass<AbstractIrBytecodeListingTestForNoArg> {
|
||||
model("bytecodeListing", extension = "kt", targetBackend = TargetBackend.JVM_IR)
|
||||
}
|
||||
|
||||
testClass<AbstractBlackBoxCodegenTestForNoArg> {
|
||||
model("box", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
testClass<AbstractBlackBoxCodegenTestForNoArg> { model("box", targetBackend = TargetBackend.JVM) }
|
||||
testClass<AbstractIrBlackBoxCodegenTestForNoArg> { model("box", targetBackend = TargetBackend.JVM_IR) }
|
||||
}
|
||||
|
||||
testGroup("plugins/sam-with-receiver/sam-with-receiver-cli/test", "plugins/sam-with-receiver/sam-with-receiver-cli/testData") {
|
||||
|
||||
@@ -1190,12 +1190,14 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractDiagnosticsTestForNoArg> { model("diagnostics", extension = "kt") }
|
||||
|
||||
testClass<AbstractBytecodeListingTestForNoArg> {
|
||||
model("bytecodeListing", extension = "kt")
|
||||
model("bytecodeListing", extension = "kt", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
testClass<AbstractIrBytecodeListingTestForNoArg> {
|
||||
model("bytecodeListing", extension = "kt", targetBackend = TargetBackend.JVM_IR)
|
||||
}
|
||||
|
||||
testClass<AbstractBlackBoxCodegenTestForNoArg> {
|
||||
model("box", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
testClass<AbstractBlackBoxCodegenTestForNoArg> { model("box", targetBackend = TargetBackend.JVM) }
|
||||
testClass<AbstractIrBlackBoxCodegenTestForNoArg> { model("box", targetBackend = TargetBackend.JVM_IR) }
|
||||
}
|
||||
|
||||
testGroup("plugins/sam-with-receiver/sam-with-receiver-cli/test", "plugins/sam-with-receiver/sam-with-receiver-cli/testData") {
|
||||
|
||||
@@ -1114,12 +1114,14 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractDiagnosticsTestForNoArg> { model("diagnostics", extension = "kt") }
|
||||
|
||||
testClass<AbstractBytecodeListingTestForNoArg> {
|
||||
model("bytecodeListing", extension = "kt")
|
||||
model("bytecodeListing", extension = "kt", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
testClass<AbstractIrBytecodeListingTestForNoArg> {
|
||||
model("bytecodeListing", extension = "kt", targetBackend = TargetBackend.JVM_IR)
|
||||
}
|
||||
|
||||
testClass<AbstractBlackBoxCodegenTestForNoArg> {
|
||||
model("box", targetBackend = TargetBackend.JVM)
|
||||
}
|
||||
testClass<AbstractBlackBoxCodegenTestForNoArg> { model("box", targetBackend = TargetBackend.JVM) }
|
||||
testClass<AbstractIrBlackBoxCodegenTestForNoArg> { model("box", targetBackend = TargetBackend.JVM_IR) }
|
||||
}
|
||||
|
||||
testGroup("plugins/sam-with-receiver/sam-with-receiver-cli/test", "plugins/sam-with-receiver/sam-with-receiver-cli/testData") {
|
||||
|
||||
@@ -72,6 +72,10 @@
|
||||
<goals> <goal>compile</goal> </goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
||||
@@ -12,6 +12,7 @@ dependencies {
|
||||
compileOnly(project(":compiler:backend"))
|
||||
compileOnly(project(":compiler:util"))
|
||||
compileOnly(project(":compiler:plugin-api"))
|
||||
compileOnly(project(":compiler:ir.backend.common"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeJars("asm-all", rootProject = rootProject) }
|
||||
runtime(kotlinStdlib())
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.SYNTHESIZED_INIT_BLOCK
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.extensions.AnnotationBasedExtension
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBlock
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.psi.KtModifierListOwner
|
||||
import org.jetbrains.kotlin.resolve.jvm.annotations.JVM_OVERLOADS_FQ_NAME
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal class NoArgIrGenerationExtension(
|
||||
private val annotations: List<String>,
|
||||
private val invokeInitializers: Boolean,
|
||||
) : IrGenerationExtension {
|
||||
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
|
||||
moduleFragment.accept(NoArgIrTransformer(pluginContext, annotations, invokeInitializers), null)
|
||||
}
|
||||
}
|
||||
|
||||
private class NoArgIrTransformer(
|
||||
private val context: IrPluginContext,
|
||||
private val annotations: List<String>,
|
||||
private val invokeInitializers: Boolean,
|
||||
) : AnnotationBasedExtension, IrElementVisitorVoid {
|
||||
override fun getAnnotationFqNames(modifierListOwner: KtModifierListOwner?): List<String> = annotations
|
||||
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildren(this, null)
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass) {
|
||||
super.visitClass(declaration)
|
||||
|
||||
if (declaration.kind == ClassKind.CLASS &&
|
||||
declaration.isAnnotatedWithNoarg() &&
|
||||
declaration.constructors.none(::isZeroParameterConstructor)
|
||||
) {
|
||||
declaration.declarations.add(getOrGenerateNoArgConstructor(declaration))
|
||||
}
|
||||
}
|
||||
|
||||
private val noArgConstructors = mutableMapOf<IrClass, IrConstructor>()
|
||||
|
||||
private fun getOrGenerateNoArgConstructor(klass: IrClass): IrConstructor = noArgConstructors.getOrPut(klass) {
|
||||
val superClass =
|
||||
klass.superTypes.mapNotNull(IrType::getClass).singleOrNull { it.kind == ClassKind.CLASS }
|
||||
?: context.irBuiltIns.anyClass.owner
|
||||
|
||||
val superConstructor =
|
||||
if (superClass.isAnnotatedWithNoarg())
|
||||
getOrGenerateNoArgConstructor(superClass)
|
||||
else superClass.constructors.singleOrNull { it.valueParameters.isEmpty() }
|
||||
?: error("No noarg super constructor for ${klass.render()}:\n" + superClass.constructors.joinToString("\n") { it.render() })
|
||||
|
||||
context.irFactory.buildConstructor {
|
||||
returnType = klass.defaultType
|
||||
}.also { ctor ->
|
||||
ctor.parent = klass
|
||||
ctor.body = context.irFactory.createBlockBody(
|
||||
ctor.startOffset, ctor.endOffset,
|
||||
listOfNotNull(
|
||||
IrDelegatingConstructorCallImpl(
|
||||
ctor.startOffset, ctor.endOffset, context.irBuiltIns.unitType,
|
||||
superConstructor.symbol, 0, superConstructor.valueParameters.size
|
||||
),
|
||||
if (invokeInitializers)
|
||||
NoArgInitializersLowering(context.irBuiltIns).createInitializersBlock(ctor)
|
||||
else null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrClass.isAnnotatedWithNoarg(): Boolean =
|
||||
toIrBasedDescriptor().hasSpecialAnnotation(null)
|
||||
|
||||
private fun isZeroParameterConstructor(constructor: IrConstructor): Boolean {
|
||||
val parameters = constructor.valueParameters
|
||||
return parameters.isEmpty() ||
|
||||
(parameters.all { it.defaultValue != null } && (constructor.isPrimary || constructor.hasAnnotation(JVM_OVERLOADS_FQ_NAME)))
|
||||
}
|
||||
}
|
||||
|
||||
/** Main parts copied from [org.jetbrains.kotlin.backend.common.lower.InitializersLowering]. */
|
||||
private class NoArgInitializersLowering(private val builtIns: IrBuiltIns) {
|
||||
fun createInitializersBlock(ctor: IrConstructor): IrBlock {
|
||||
val irClass = ctor.constructedClass
|
||||
return IrBlockImpl(irClass.startOffset, irClass.endOffset, builtIns.unitType, null, extractInitializers(irClass))
|
||||
.deepCopyWithSymbols(ctor)
|
||||
}
|
||||
|
||||
private fun extractInitializers(irClass: IrClass): List<IrStatement> {
|
||||
val result = mutableListOf<IrStatement>()
|
||||
for (declaration in irClass.declarations) {
|
||||
when (declaration) {
|
||||
is IrAnonymousInitializer -> if (!declaration.isStatic) {
|
||||
result.add(with(declaration) {
|
||||
IrBlockImpl(startOffset, endOffset, builtIns.unitType, SYNTHESIZED_INIT_BLOCK, body.statements)
|
||||
})
|
||||
}
|
||||
is IrProperty -> declaration.backingField.let { field ->
|
||||
if (field != null && !field.isStatic) {
|
||||
val initializer = field.initializer
|
||||
// Take all field initializers except those for properties in the primary constructor, for which we have no values
|
||||
// in the noarg constructor (and thus those properties will be uninitialized).
|
||||
if (initializer != null && initializer.expression.safeAs<IrGetValue>()?.origin !=
|
||||
IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
) {
|
||||
result.add(with(initializer) {
|
||||
IrSetFieldImpl(
|
||||
startOffset, endOffset, field.symbol,
|
||||
IrGetValueImpl(startOffset, endOffset, irClass.thisReceiver!!.type, irClass.thisReceiver!!.symbol),
|
||||
expression, builtIns.unitType, IrStatementOrigin.INITIALIZE_FIELD
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.noarg
|
||||
|
||||
import com.intellij.mock.MockProject
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
|
||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
|
||||
import org.jetbrains.kotlin.compiler.plugin.*
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
@@ -99,6 +100,7 @@ class NoArgComponentRegistrar : ComponentRegistrar {
|
||||
fun registerNoArgComponents(project: Project, annotations: List<String>, useIr: Boolean, invokeInitializers: Boolean) {
|
||||
StorageComponentContainerContributor.registerExtension(project, CliNoArgComponentContainerContributor(annotations, useIr))
|
||||
ExpressionCodegenExtension.registerExtension(project, CliNoArgExpressionCodegenExtension(annotations, invokeInitializers))
|
||||
IrGenerationExtension.registerExtension(project, NoArgIrGenerationExtension(annotations, invokeInitializers))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+10
@@ -54,6 +54,16 @@ public class BlackBoxCodegenTestForNoArgGenerated extends AbstractBlackBoxCodege
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/kt18668.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localClassInInitiailzer.kt")
|
||||
public void testLocalClassInInitiailzer() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/localClassInInitiailzer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/nestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/simple.kt");
|
||||
|
||||
Generated
+13
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.noarg;
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -21,11 +22,11 @@ import java.util.regex.Pattern;
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class BytecodeListingTestForNoArgGenerated extends AbstractBytecodeListingTestForNoArg {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBytecodeListing() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/noarg/noarg-cli/testData/bytecodeListing"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/noarg/noarg-cli/testData/bytecodeListing"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annoOnNotClass.kt")
|
||||
@@ -33,6 +34,11 @@ public class BytecodeListingTestForNoArgGenerated extends AbstractBytecodeListin
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/annoOnNotClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorVisibility.kt")
|
||||
public void testConstructorVisibility() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/constructorVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParameters.kt")
|
||||
public void testDefaultParameters() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/defaultParameters.kt");
|
||||
@@ -43,6 +49,11 @@ public class BytecodeListingTestForNoArgGenerated extends AbstractBytecodeListin
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/inherited.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/nestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noNoArg.kt")
|
||||
public void testNoNoArg() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/noNoArg.kt");
|
||||
|
||||
Generated
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("plugins/noarg/noarg-cli/testData/box")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class IrBlackBoxCodegenTestForNoArgGenerated extends AbstractIrBlackBoxCodegenTestForNoArg {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBox() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/noarg/noarg-cli/testData/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("initializers.kt")
|
||||
public void testInitializers() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/initializers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("initializersWithoutInvokeInitializers.kt")
|
||||
public void testInitializersWithoutInvokeInitializers() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/initializersWithoutInvokeInitializers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt18245.kt")
|
||||
public void testKt18245() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/kt18245.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt18667.kt")
|
||||
public void testKt18667() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/kt18667.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt18668.kt")
|
||||
public void testKt18668() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/kt18668.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localClassInInitiailzer.kt")
|
||||
public void testLocalClassInInitiailzer() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/localClassInInitiailzer.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/nestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/box/simple.kt");
|
||||
}
|
||||
}
|
||||
Generated
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("plugins/noarg/noarg-cli/testData/bytecodeListing")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class IrBytecodeListingTestForNoArgGenerated extends AbstractIrBytecodeListingTestForNoArg {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBytecodeListing() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/noarg/noarg-cli/testData/bytecodeListing"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("annoOnNotClass.kt")
|
||||
public void testAnnoOnNotClass() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/annoOnNotClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("constructorVisibility.kt")
|
||||
public void testConstructorVisibility() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/constructorVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParameters.kt")
|
||||
public void testDefaultParameters() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/defaultParameters.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inherited.kt")
|
||||
public void testInherited() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/inherited.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass.kt")
|
||||
public void testNestedClass() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/nestedClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noNoArg.kt")
|
||||
public void testNoNoArg() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/noNoArg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("severalNoArg.kt")
|
||||
public void testSeveralNoArg() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/severalNoArg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/simple.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("superTypes.kt")
|
||||
public void testSuperTypes() throws Exception {
|
||||
runTest("plugins/noarg/noarg-cli/testData/bytecodeListing/superTypes.kt");
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.AbstractBlackBoxCodegenTest
|
||||
import org.jetbrains.kotlin.codegen.AbstractBytecodeListingTest
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
|
||||
internal val NOARG_ANNOTATIONS = listOf("NoArg", "NoArg2", "test.NoArg")
|
||||
|
||||
@@ -31,6 +32,14 @@ abstract class AbstractBytecodeListingTestForNoArg : AbstractBytecodeListingTest
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractIrBlackBoxCodegenTestForNoArg : AbstractBlackBoxCodegenTestForNoArg() {
|
||||
override val backend: TargetBackend get() = TargetBackend.JVM_IR
|
||||
}
|
||||
|
||||
abstract class AbstractIrBytecodeListingTestForNoArg : AbstractBytecodeListingTestForNoArg() {
|
||||
override val backend: TargetBackend get() = TargetBackend.JVM_IR
|
||||
}
|
||||
|
||||
abstract class AbstractDiagnosticsTestForNoArg : AbstractDiagnosticsTest() {
|
||||
override fun setupEnvironment(environment: KotlinCoreEnvironment) {
|
||||
NoArgComponentRegistrar.registerNoArgComponents(environment.project, NOARG_ANNOTATIONS, backend.isIR, false)
|
||||
|
||||
+14
-19
@@ -13,24 +13,19 @@ class Test(val a: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val test = Test::class.java.newInstance()
|
||||
val test = Test::class.java.newInstance()
|
||||
|
||||
if (test.x != 5) {
|
||||
return "Bad 5"
|
||||
}
|
||||
|
||||
if (test.y == null || test.y.a != "Hello, world!") {
|
||||
return "Bad Hello, world!"
|
||||
}
|
||||
|
||||
if (test.z != "TEST") {
|
||||
return "Bad TEST"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
return "Fail"
|
||||
if (test.x != 5) {
|
||||
return "Bad 5"
|
||||
}
|
||||
}
|
||||
|
||||
if (test.y == null || test.y.a != "Hello, world!") {
|
||||
return "Bad Hello, world!"
|
||||
}
|
||||
|
||||
if (test.z != "TEST") {
|
||||
return "Bad TEST"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+10
-15
@@ -11,20 +11,15 @@ class Test(val a: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
val test = Test::class.java.newInstance()
|
||||
val test = Test::class.java.newInstance()
|
||||
|
||||
if (test.x != 0) {
|
||||
return "Bad 5"
|
||||
}
|
||||
|
||||
if (test.y != null) {
|
||||
return "Bad Hello, world!"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
return "Fail"
|
||||
if (test.x != 0) {
|
||||
return "Bad 5"
|
||||
}
|
||||
}
|
||||
|
||||
if (test.y != null) {
|
||||
return "Bad Hello, world!"
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
// INVOKE_INITIALIZERS
|
||||
|
||||
annotation class NoArg
|
||||
|
||||
@NoArg
|
||||
class Test(val a: String) {
|
||||
val lc = run {
|
||||
class Local(val result: String)
|
||||
Local("OK").result
|
||||
}
|
||||
|
||||
val obj = object { val result = "OK" }.result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val t = Test::class.java.newInstance()
|
||||
if (t.lc != "OK") return "Fail 1"
|
||||
return t.obj
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
annotation class NoArg
|
||||
|
||||
class Outer {
|
||||
@NoArg
|
||||
class Nested(val a: String)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
Outer.Nested::class.java.newInstance()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+3
-7
@@ -6,10 +6,6 @@ annotation class NoArg
|
||||
class Test(val a: String)
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
Test::class.java.newInstance()
|
||||
return "OK"
|
||||
} catch (_: Throwable) {
|
||||
return "Fail"
|
||||
}
|
||||
}
|
||||
Test::class.java.newInstance()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
annotation class NoArg
|
||||
|
||||
@NoArg
|
||||
class Internal internal constructor(z: Boolean)
|
||||
|
||||
@NoArg
|
||||
abstract class Protected protected constructor(c: Char)
|
||||
|
||||
@NoArg
|
||||
class Private private constructor(ia: IntArray)
|
||||
@@ -0,0 +1,29 @@
|
||||
@NoArg
|
||||
@kotlin.Metadata
|
||||
public final class Internal {
|
||||
// source: 'constructorVisibility.kt'
|
||||
public method <init>(): void
|
||||
public method <init>(p0: boolean): void
|
||||
}
|
||||
|
||||
@java.lang.annotation.Retention
|
||||
@kotlin.Metadata
|
||||
public annotation class NoArg {
|
||||
// source: 'constructorVisibility.kt'
|
||||
}
|
||||
|
||||
@NoArg
|
||||
@kotlin.Metadata
|
||||
public final class Private {
|
||||
// source: 'constructorVisibility.kt'
|
||||
public method <init>(): void
|
||||
private method <init>(p0: int[]): void
|
||||
}
|
||||
|
||||
@NoArg
|
||||
@kotlin.Metadata
|
||||
public abstract class Protected {
|
||||
// source: 'constructorVisibility.kt'
|
||||
public method <init>(): void
|
||||
protected method <init>(p0: char): void
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
annotation class NoArg
|
||||
|
||||
class Outer {
|
||||
@NoArg
|
||||
class Nested(a: Long)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
@java.lang.annotation.Retention
|
||||
@kotlin.Metadata
|
||||
public annotation class NoArg {
|
||||
// source: 'nestedClass.kt'
|
||||
}
|
||||
|
||||
@NoArg
|
||||
@kotlin.Metadata
|
||||
public final class Outer$Nested {
|
||||
// source: 'nestedClass.kt'
|
||||
public method <init>(): void
|
||||
public method <init>(p0: long): void
|
||||
public final inner class Outer$Nested
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class Outer {
|
||||
// source: 'nestedClass.kt'
|
||||
public method <init>(): void
|
||||
public final inner class Outer$Nested
|
||||
}
|
||||
Reference in New Issue
Block a user