diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index ed972173ab3..69340c2e5a4 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -155,6 +155,7 @@ import org.jetbrains.kotlin.kapt3.test.AbstractKotlinKaptContextTest import org.jetbrains.kotlin.nj2k.AbstractNewJavaToKotlinConverterSingleFileTest import org.jetbrains.kotlin.nj2k.AbstractNewJavaToKotlinCopyPasteConversionTest import org.jetbrains.kotlin.nj2k.AbstractNullabilityAnalysisTest +import org.jetbrains.kotlin.nj2k.AbstractTextNewJavaToKotlinCopyPasteConversionTest import org.jetbrains.kotlin.noarg.AbstractBlackBoxCodegenTestForNoArg import org.jetbrains.kotlin.noarg.AbstractBytecodeListingTestForNoArg import org.jetbrains.kotlin.psi.patternMatching.AbstractPsiUnifierTest @@ -985,6 +986,9 @@ fun main(args: Array) { testClass { model("copyPaste", pattern = """^([^\.]+)\.java$""") } + testClass { + model("copyPastePlainText", pattern = """^([^\.]+)\.txt$""") + } testClass { model("nullabilityAnalysis") } diff --git a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJ2kCopyPasteTest.kt b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJ2kCopyPasteTest.kt new file mode 100644 index 00000000000..4689afd88c7 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJ2kCopyPasteTest.kt @@ -0,0 +1,18 @@ +/* + * 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.idea.conversion.copy + +import com.intellij.openapi.util.registry.Registry +import org.jetbrains.kotlin.idea.AbstractCopyPasteTest + +abstract class AbstractJ2kCopyPasteTest : AbstractCopyPasteTest() { + protected open fun isNewJ2K(): Boolean = false + + override fun setUp() { + super.setUp() + Registry.get("kotlin.use.new.j2k").setValue(isNewJ2K()) + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJavaToKotlinCopyPasteConversionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJavaToKotlinCopyPasteConversionTest.kt index 6e1513b9def..04231874add 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJavaToKotlinCopyPasteConversionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractJavaToKotlinCopyPasteConversionTest.kt @@ -16,20 +16,17 @@ import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File import kotlin.test.assertEquals -abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractCopyPasteTest() { +abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractJ2kCopyPasteTest() { private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/conversion" private var oldEditorOptions: KotlinEditorOptions? = null override fun getTestDataPath() = BASE_PATH - protected open fun isNewJ2K(): Boolean = false - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE override fun setUp() { super.setUp() - Registry.get("kotlin.use.new.j2k").setValue(isNewJ2K()) oldEditorOptions = KotlinEditorOptions.getInstance().state KotlinEditorOptions.getInstance().isEnableJavaToKotlinConversion = true KotlinEditorOptions.getInstance().isDonTShowConversionDialog = true diff --git a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt index 3d3c5cc45a7..e3381e62b15 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/conversion/copy/AbstractTextJavaToKotlinCopyPasteConversionTest.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File -abstract class AbstractTextJavaToKotlinCopyPasteConversionTest : AbstractCopyPasteTest() { +abstract class AbstractTextJavaToKotlinCopyPasteConversionTest : AbstractJ2kCopyPasteTest() { private val BASE_PATH = PluginTestCaseBase.getTestDataPathBase() + "/copyPaste/plainTextConversion" private var oldEditorOptions: KotlinEditorOptions? = null diff --git a/nj2k/testData/copyPastePlainText/AsExpression.expected.kt b/nj2k/testData/copyPastePlainText/AsExpression.expected.kt new file mode 100644 index 00000000000..65fc3b8bb1b --- /dev/null +++ b/nj2k/testData/copyPastePlainText/AsExpression.expected.kt @@ -0,0 +1,7 @@ + +import java.util.ArrayList + + +fun foo() { + bar(ArrayList()) +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/AsExpression.to.kt b/nj2k/testData/copyPastePlainText/AsExpression.to.kt new file mode 100644 index 00000000000..0c936e38f40 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/AsExpression.to.kt @@ -0,0 +1,3 @@ +fun foo() { + bar() +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/AsExpression.txt b/nj2k/testData/copyPastePlainText/AsExpression.txt new file mode 100644 index 00000000000..377d2c349c7 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/AsExpression.txt @@ -0,0 +1 @@ +new ArrayList() \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/AsExpressionBody.expected.kt b/nj2k/testData/copyPastePlainText/AsExpressionBody.expected.kt new file mode 100644 index 00000000000..fa4a1e80add --- /dev/null +++ b/nj2k/testData/copyPastePlainText/AsExpressionBody.expected.kt @@ -0,0 +1,5 @@ + +import java.util.ArrayList + + +fun foo() = ArrayList() \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/AsExpressionBody.to.kt b/nj2k/testData/copyPastePlainText/AsExpressionBody.to.kt new file mode 100644 index 00000000000..bda72b29d3a --- /dev/null +++ b/nj2k/testData/copyPastePlainText/AsExpressionBody.to.kt @@ -0,0 +1 @@ +fun foo() = \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/AsExpressionBody.txt b/nj2k/testData/copyPastePlainText/AsExpressionBody.txt new file mode 100644 index 00000000000..377d2c349c7 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/AsExpressionBody.txt @@ -0,0 +1 @@ +new ArrayList() \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportFromTarget.expected.kt b/nj2k/testData/copyPastePlainText/ImportFromTarget.expected.kt new file mode 100644 index 00000000000..85ca628988d --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportFromTarget.expected.kt @@ -0,0 +1,10 @@ +package com.example + +import java.util.UUID + + +class ExampleClass { + override fun toString(): String { + return UUID.randomUUID().toString() + } +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportFromTarget.to.kt b/nj2k/testData/copyPastePlainText/ImportFromTarget.to.kt new file mode 100644 index 00000000000..8282a03857a --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportFromTarget.to.kt @@ -0,0 +1,8 @@ +package com.example + +import java.util.UUID + + +class ExampleClass { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportFromTarget.txt b/nj2k/testData/copyPastePlainText/ImportFromTarget.txt new file mode 100644 index 00000000000..16b4583035e --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportFromTarget.txt @@ -0,0 +1,4 @@ +@Override +public String toString() { + return UUID.randomUUID().toString(); +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportResolve.dependency.java b/nj2k/testData/copyPastePlainText/ImportResolve.dependency.java new file mode 100644 index 00000000000..e7213189c67 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportResolve.dependency.java @@ -0,0 +1,34 @@ +package test; + +public class ToBeImportedJava { + public static final String TO_BE_IMPORTED_CONST = "!!!"; + + public static void staticMethod() { + } +} + +public interface IAmbiguousJava { + +} + +public interface AmbiguousJava { + +} + +public interface IAmbiguous { + +} + +public interface Ambiguous { + +} + +public class Z { + public interface IAmbiguousJava { + + } + + public interface AmbiguousJava { + + } +} diff --git a/nj2k/testData/copyPastePlainText/ImportResolve.dependency.kt b/nj2k/testData/copyPastePlainText/ImportResolve.dependency.kt new file mode 100644 index 00000000000..6540512c12e --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportResolve.dependency.kt @@ -0,0 +1,32 @@ +package test + +class ToBeImportedKotlin { + +} + +interface IAmbiguous { + +} + +interface Ambiguous { + +} + + +interface IAmbiguousKotlin { + +} + +interface AmbiguousKotlin { + +} + +class Z { + interface IAmbiguousKotlin { + + } + + interface AmbiguousKotlin { + + } +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportResolve.expected.kt b/nj2k/testData/copyPastePlainText/ImportResolve.expected.kt new file mode 100644 index 00000000000..a2c721bf84f --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportResolve.expected.kt @@ -0,0 +1,32 @@ +import test.ToBeImportedJava +import test.ToBeImportedJava.TO_BE_IMPORTED_CONST +import test.ToBeImportedJava.staticMethod +import test.ToBeImportedKotlin +import java.util.ArrayList +import java.util.HashMap + + +class Target { + var listOfPlatformType: List = ArrayList() + + var unresolved: UnresolvedInterface? = UnresolvedImplementation() // Should not add import + + + var hashMapOfNotImported: Map = HashMap() + + internal fun acceptKotlinClass(tbi: ToBeImportedKotlin?) {} + + internal fun acceptJavaClass(tbi: ToBeImportedJava?) {} + + var ambiguousKotlin: IAmbiguousKotlin? = AmbiguousKotlin() // Should not add import in case of 2 declarations in Kotlin + + var ambiguous: IAmbiguous? = Ambiguous() // Should not add import in case of ambiguous declarations in Kotlin and in Java + + var ambiguousJava: IAmbiguousJava? = AmbiguousJava() // Should not add import in case of 2 declarations in Java + + + internal fun workWithStatics() { + val a = TO_BE_IMPORTED_CONST + staticMethod() + } +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportResolve.to.kt b/nj2k/testData/copyPastePlainText/ImportResolve.to.kt new file mode 100644 index 00000000000..dee11740046 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportResolve.to.kt @@ -0,0 +1,3 @@ +class Target { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/ImportResolve.txt b/nj2k/testData/copyPastePlainText/ImportResolve.txt new file mode 100644 index 00000000000..97ffd68a1b6 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/ImportResolve.txt @@ -0,0 +1,22 @@ +public List listOfPlatformType = new ArrayList(); + +UnresolvedInterface unresolved = new UnresolvedImplementation<>(); // Should not add import + +Map hashMapOfNotImported = new HashMap<>(); + +void acceptKotlinClass(ToBeImportedKotlin tbi) { + +} + +void acceptJavaClass(ToBeImportedJava tbi) { + +} + +IAmbiguousKotlin ambiguousKotlin = new AmbiguousKotlin(); // Should not add import in case of 2 declarations in Kotlin +IAmbiguous ambiguous = new Ambiguous(); // Should not add import in case of ambiguous declarations in Kotlin and in Java +IAmbiguousJava ambiguousJava = new AmbiguousJava(); // Should not add import in case of 2 declarations in Java + +void workWithStatics() { + String a = TO_BE_IMPORTED_CONST; + staticMethod(); +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/InsideIdentifier.expected.kt b/nj2k/testData/copyPastePlainText/InsideIdentifier.expected.kt new file mode 100644 index 00000000000..3c1d5bfc6d3 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/InsideIdentifier.expected.kt @@ -0,0 +1,4 @@ +fun foo() { + bArrayList list = new ArrayList(); +// NO_CONVERSION_EXPECTEDar() +} diff --git a/nj2k/testData/copyPastePlainText/InsideIdentifier.to.kt b/nj2k/testData/copyPastePlainText/InsideIdentifier.to.kt new file mode 100644 index 00000000000..eb0412a03dd --- /dev/null +++ b/nj2k/testData/copyPastePlainText/InsideIdentifier.to.kt @@ -0,0 +1,3 @@ +fun foo() { + bar() +} diff --git a/nj2k/testData/copyPastePlainText/InsideIdentifier.to.kt.after b/nj2k/testData/copyPastePlainText/InsideIdentifier.to.kt.after new file mode 100644 index 00000000000..eb0412a03dd --- /dev/null +++ b/nj2k/testData/copyPastePlainText/InsideIdentifier.to.kt.after @@ -0,0 +1,3 @@ +fun foo() { + bar() +} diff --git a/nj2k/testData/copyPastePlainText/InsideIdentifier.txt b/nj2k/testData/copyPastePlainText/InsideIdentifier.txt new file mode 100644 index 00000000000..2934e0d0dee --- /dev/null +++ b/nj2k/testData/copyPastePlainText/InsideIdentifier.txt @@ -0,0 +1,2 @@ +ArrayList list = new ArrayList(); +// NO_CONVERSION_EXPECTED \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/IntoComment.expected.kt b/nj2k/testData/copyPastePlainText/IntoComment.expected.kt new file mode 100644 index 00000000000..4768e2c1abb --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoComment.expected.kt @@ -0,0 +1,2 @@ +// ArrayList list = new ArrayList(); +//// NO_CONVERSION_EXPECTED diff --git a/nj2k/testData/copyPastePlainText/IntoComment.to.kt b/nj2k/testData/copyPastePlainText/IntoComment.to.kt new file mode 100644 index 00000000000..7a864bde8d4 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoComment.to.kt @@ -0,0 +1 @@ +// \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/IntoComment.txt b/nj2k/testData/copyPastePlainText/IntoComment.txt new file mode 100644 index 00000000000..2934e0d0dee --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoComment.txt @@ -0,0 +1,2 @@ +ArrayList list = new ArrayList(); +// NO_CONVERSION_EXPECTED \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.expected.kt b/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.expected.kt new file mode 100644 index 00000000000..184fc0803a4 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.expected.kt @@ -0,0 +1,7 @@ +fun foo() { + val v = """ +ArrayList list = new ArrayList(); +// NO_CONVERSION_EXPECTED + +""" +} diff --git a/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.to.kt b/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.to.kt new file mode 100644 index 00000000000..55776cb2719 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.to.kt @@ -0,0 +1,5 @@ +fun foo() { + val v = """ + +""" +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.txt b/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.txt new file mode 100644 index 00000000000..4ae9947ba23 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoRawStringLiteral.txt @@ -0,0 +1,2 @@ +ArrayList list = new ArrayList(); +// NO_CONVERSION_EXPECTED diff --git a/nj2k/testData/copyPastePlainText/IntoStringLiteral.expected.kt b/nj2k/testData/copyPastePlainText/IntoStringLiteral.expected.kt new file mode 100644 index 00000000000..c716d8e38c3 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoStringLiteral.expected.kt @@ -0,0 +1,4 @@ +fun foo() { + val v = "ArrayList list = new ArrayList();\n" + + "// NO_CONVERSION_EXPECTED\n" +} diff --git a/nj2k/testData/copyPastePlainText/IntoStringLiteral.to.kt b/nj2k/testData/copyPastePlainText/IntoStringLiteral.to.kt new file mode 100644 index 00000000000..22d07efec3f --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoStringLiteral.to.kt @@ -0,0 +1,3 @@ +fun foo() { + val v = "" +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/IntoStringLiteral.txt b/nj2k/testData/copyPastePlainText/IntoStringLiteral.txt new file mode 100644 index 00000000000..4ae9947ba23 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/IntoStringLiteral.txt @@ -0,0 +1,2 @@ +ArrayList list = new ArrayList(); +// NO_CONVERSION_EXPECTED diff --git a/nj2k/testData/copyPastePlainText/KT13529.expected.kt b/nj2k/testData/copyPastePlainText/KT13529.expected.kt new file mode 100644 index 00000000000..e3e51280dec --- /dev/null +++ b/nj2k/testData/copyPastePlainText/KT13529.expected.kt @@ -0,0 +1,9 @@ +package com.bignerdranch.beatbox.data + +/** + * Created by Panel on 18.08.2016. + */ +object BeatBox { + private const val TAG = "BeatBox" + private const val SOUNDS_FOLDER = "sample_sounds" +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/KT13529.to.kt b/nj2k/testData/copyPastePlainText/KT13529.to.kt new file mode 100644 index 00000000000..61d142b4ffe --- /dev/null +++ b/nj2k/testData/copyPastePlainText/KT13529.to.kt @@ -0,0 +1,6 @@ +package com.bignerdranch.beatbox.data + +/** + * Created by Panel on 18.08.2016. + */ + \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/KT13529.txt b/nj2k/testData/copyPastePlainText/KT13529.txt new file mode 100644 index 00000000000..b39760f1511 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/KT13529.txt @@ -0,0 +1,4 @@ +public class BeatBox { + private static final String TAG = "BeatBox"; + private static final String SOUNDS_FOLDER = "sample_sounds"; +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/KT13529_1.expected.kt b/nj2k/testData/copyPastePlainText/KT13529_1.expected.kt new file mode 100644 index 00000000000..a042bb2ee7d --- /dev/null +++ b/nj2k/testData/copyPastePlainText/KT13529_1.expected.kt @@ -0,0 +1,7 @@ + +import java.util.ArrayList + + +fun foo() { + bar(/*comment*/ArrayList()) +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/KT13529_1.to.kt b/nj2k/testData/copyPastePlainText/KT13529_1.to.kt new file mode 100644 index 00000000000..86886a8d875 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/KT13529_1.to.kt @@ -0,0 +1,3 @@ +fun foo() { + bar(/*comment*/) +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/KT13529_1.txt b/nj2k/testData/copyPastePlainText/KT13529_1.txt new file mode 100644 index 00000000000..377d2c349c7 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/KT13529_1.txt @@ -0,0 +1 @@ +new ArrayList() \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/MembersIntoClass.expected.kt b/nj2k/testData/copyPastePlainText/MembersIntoClass.expected.kt new file mode 100644 index 00000000000..10ba5dfcc8b --- /dev/null +++ b/nj2k/testData/copyPastePlainText/MembersIntoClass.expected.kt @@ -0,0 +1,13 @@ + +import java.util.ArrayList + + +class A { + internal fun foo() { + val list = ArrayList() + list.add(1) + } + + internal fun bar() {} + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/MembersIntoClass.to.kt b/nj2k/testData/copyPastePlainText/MembersIntoClass.to.kt new file mode 100644 index 00000000000..9515b31e1d9 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/MembersIntoClass.to.kt @@ -0,0 +1,3 @@ +class A { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/MembersIntoClass.to.kt.expected b/nj2k/testData/copyPastePlainText/MembersIntoClass.to.kt.expected new file mode 100644 index 00000000000..9515b31e1d9 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/MembersIntoClass.to.kt.expected @@ -0,0 +1,3 @@ +class A { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/MembersIntoClass.txt b/nj2k/testData/copyPastePlainText/MembersIntoClass.txt new file mode 100644 index 00000000000..b028b2d8735 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/MembersIntoClass.txt @@ -0,0 +1,7 @@ + void foo() { + ArrayList list = new ArrayList(); + list.add(1); + } + + void bar() { + } diff --git a/nj2k/testData/copyPastePlainText/MembersToTopLevel.expected.kt b/nj2k/testData/copyPastePlainText/MembersToTopLevel.expected.kt new file mode 100644 index 00000000000..e66a554e086 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/MembersToTopLevel.expected.kt @@ -0,0 +1,11 @@ +package to + +import java.util.ArrayList + + +internal fun foo() { + val list = ArrayList() + list.add(1) +} + +internal fun bar() {} diff --git a/nj2k/testData/copyPastePlainText/MembersToTopLevel.txt b/nj2k/testData/copyPastePlainText/MembersToTopLevel.txt new file mode 100644 index 00000000000..b028b2d8735 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/MembersToTopLevel.txt @@ -0,0 +1,7 @@ + void foo() { + ArrayList list = new ArrayList(); + list.add(1); + } + + void bar() { + } diff --git a/nj2k/testData/copyPastePlainText/Override.dependency.java b/nj2k/testData/copyPastePlainText/Override.dependency.java new file mode 100644 index 00000000000..7527edd8a75 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/Override.dependency.java @@ -0,0 +1,5 @@ +package test; + +public class JavaParent { + public void subject() {} +} diff --git a/nj2k/testData/copyPastePlainText/Override.expected.kt b/nj2k/testData/copyPastePlainText/Override.expected.kt new file mode 100644 index 00000000000..54502cbde89 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/Override.expected.kt @@ -0,0 +1,5 @@ +import test.JavaParent + +class KotlinChild : JavaParent() { + override fun subject() {} +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/Override.to.kt b/nj2k/testData/copyPastePlainText/Override.to.kt new file mode 100644 index 00000000000..6ea3d0de688 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/Override.to.kt @@ -0,0 +1,5 @@ +import test.JavaParent + +class KotlinChild : JavaParent() { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/Override.txt b/nj2k/testData/copyPastePlainText/Override.txt new file mode 100644 index 00000000000..018332ad677 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/Override.txt @@ -0,0 +1 @@ +@Override public void subject() {} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/OverrideInterface.dependency.java b/nj2k/testData/copyPastePlainText/OverrideInterface.dependency.java new file mode 100644 index 00000000000..cf6159d5eab --- /dev/null +++ b/nj2k/testData/copyPastePlainText/OverrideInterface.dependency.java @@ -0,0 +1,7 @@ +package test; + +import org.jetbrains.annotations.Nullable; + +public interface JavaInterface { + void subject(@Nullable String s) +} diff --git a/nj2k/testData/copyPastePlainText/OverrideInterface.expected.kt b/nj2k/testData/copyPastePlainText/OverrideInterface.expected.kt new file mode 100644 index 00000000000..9e9527856b3 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/OverrideInterface.expected.kt @@ -0,0 +1,5 @@ +import test.JavaInterface + +class KotlinChild : JavaInterface() { + override fun subject(s: String?) {} +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/OverrideInterface.to.kt b/nj2k/testData/copyPastePlainText/OverrideInterface.to.kt new file mode 100644 index 00000000000..8dbc5b3f3b6 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/OverrideInterface.to.kt @@ -0,0 +1,5 @@ +import test.JavaInterface + +class KotlinChild : JavaInterface() { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/OverrideInterface.txt b/nj2k/testData/copyPastePlainText/OverrideInterface.txt new file mode 100644 index 00000000000..d8a6cbf58b8 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/OverrideInterface.txt @@ -0,0 +1 @@ +@Override public void subject(String s) {} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/PostProcessing.expected.kt b/nj2k/testData/copyPastePlainText/PostProcessing.expected.kt new file mode 100644 index 00000000000..1898bdff7a4 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/PostProcessing.expected.kt @@ -0,0 +1,15 @@ +package to + +import java.io.File +import java.util.ArrayList + + +class JavaClass { + internal fun foo(file: File?, target: List?) { + val list = ArrayList() + if (file != null) { + list.add(file.name) + } + target?.addAll(list) + } +} diff --git a/nj2k/testData/copyPastePlainText/PostProcessing.txt b/nj2k/testData/copyPastePlainText/PostProcessing.txt new file mode 100644 index 00000000000..ad0a1bef34e --- /dev/null +++ b/nj2k/testData/copyPastePlainText/PostProcessing.txt @@ -0,0 +1,15 @@ +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +class JavaClass { + void foo(File file, List target) { + ArrayList list = new ArrayList(); + if (file != null) { + list.add(file.getName()); + } + if (target != null) { + target.addAll(list); + } + } +} diff --git a/nj2k/testData/copyPastePlainText/StatementsIntoFunction.expected.kt b/nj2k/testData/copyPastePlainText/StatementsIntoFunction.expected.kt new file mode 100644 index 00000000000..8a1a2b09e04 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/StatementsIntoFunction.expected.kt @@ -0,0 +1,9 @@ + +import java.util.ArrayList + + +fun foo() { + val list = ArrayList() + list.add(1) + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/StatementsIntoFunction.to.kt b/nj2k/testData/copyPastePlainText/StatementsIntoFunction.to.kt new file mode 100644 index 00000000000..352e90baa62 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/StatementsIntoFunction.to.kt @@ -0,0 +1,3 @@ +fun foo() { + +} \ No newline at end of file diff --git a/nj2k/testData/copyPastePlainText/StatementsIntoFunction.txt b/nj2k/testData/copyPastePlainText/StatementsIntoFunction.txt new file mode 100644 index 00000000000..100265e0e13 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/StatementsIntoFunction.txt @@ -0,0 +1,2 @@ + ArrayList list = new ArrayList(); + list.add(1); diff --git a/nj2k/testData/copyPastePlainText/WholeFile.expected.kt b/nj2k/testData/copyPastePlainText/WholeFile.expected.kt new file mode 100644 index 00000000000..11a8cf7b1fc --- /dev/null +++ b/nj2k/testData/copyPastePlainText/WholeFile.expected.kt @@ -0,0 +1,11 @@ +package to + +import java.util.ArrayList + + +class JavaClass { + internal fun foo() { + val list = ArrayList() + list.add(1) + } +} diff --git a/nj2k/testData/copyPastePlainText/WholeFile.txt b/nj2k/testData/copyPastePlainText/WholeFile.txt new file mode 100644 index 00000000000..3729ff8e398 --- /dev/null +++ b/nj2k/testData/copyPastePlainText/WholeFile.txt @@ -0,0 +1,8 @@ +import java.util.ArrayList; + +class JavaClass { + void foo() { + ArrayList list = new ArrayList(); + list.add(1); + } +} diff --git a/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt b/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt new file mode 100644 index 00000000000..273b01f977e --- /dev/null +++ b/nj2k/tests/org/jetbrains/kotlin/nj2k/AbstractTextJavaToKotlinCopyPasteConversionTest.kt @@ -0,0 +1,12 @@ +/* + * 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.nj2k + +import org.jetbrains.kotlin.idea.conversion.copy.AbstractTextJavaToKotlinCopyPasteConversionTest + +abstract class AbstractTextNewJavaToKotlinCopyPasteConversionTest : AbstractTextJavaToKotlinCopyPasteConversionTest() { + override fun isNewJ2K(): Boolean = true +} \ No newline at end of file diff --git a/nj2k/tests/org/jetbrains/kotlin/nj2k/TextNewJavaToKotlinCopyPasteConversionTestGenerated.java b/nj2k/tests/org/jetbrains/kotlin/nj2k/TextNewJavaToKotlinCopyPasteConversionTestGenerated.java new file mode 100644 index 00000000000..5abe3ddf688 --- /dev/null +++ b/nj2k/tests/org/jetbrains/kotlin/nj2k/TextNewJavaToKotlinCopyPasteConversionTestGenerated.java @@ -0,0 +1,116 @@ +/* + * 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.nj2k; + +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("nj2k/testData/copyPastePlainText") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class TextNewJavaToKotlinCopyPasteConversionTestGenerated extends AbstractTextNewJavaToKotlinCopyPasteConversionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInCopyPastePlainText() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("nj2k/testData/copyPastePlainText"), Pattern.compile("^([^\\.]+)\\.txt$"), TargetBackend.ANY, true); + } + + @TestMetadata("AsExpression.txt") + public void testAsExpression() throws Exception { + runTest("nj2k/testData/copyPastePlainText/AsExpression.txt"); + } + + @TestMetadata("AsExpressionBody.txt") + public void testAsExpressionBody() throws Exception { + runTest("nj2k/testData/copyPastePlainText/AsExpressionBody.txt"); + } + + @TestMetadata("ImportFromTarget.txt") + public void testImportFromTarget() throws Exception { + runTest("nj2k/testData/copyPastePlainText/ImportFromTarget.txt"); + } + + @TestMetadata("ImportResolve.txt") + public void testImportResolve() throws Exception { + runTest("nj2k/testData/copyPastePlainText/ImportResolve.txt"); + } + + @TestMetadata("InsideIdentifier.txt") + public void testInsideIdentifier() throws Exception { + runTest("nj2k/testData/copyPastePlainText/InsideIdentifier.txt"); + } + + @TestMetadata("IntoComment.txt") + public void testIntoComment() throws Exception { + runTest("nj2k/testData/copyPastePlainText/IntoComment.txt"); + } + + @TestMetadata("IntoRawStringLiteral.txt") + public void testIntoRawStringLiteral() throws Exception { + runTest("nj2k/testData/copyPastePlainText/IntoRawStringLiteral.txt"); + } + + @TestMetadata("IntoStringLiteral.txt") + public void testIntoStringLiteral() throws Exception { + runTest("nj2k/testData/copyPastePlainText/IntoStringLiteral.txt"); + } + + @TestMetadata("KT13529.txt") + public void testKT13529() throws Exception { + runTest("nj2k/testData/copyPastePlainText/KT13529.txt"); + } + + @TestMetadata("KT13529_1.txt") + public void testKT13529_1() throws Exception { + runTest("nj2k/testData/copyPastePlainText/KT13529_1.txt"); + } + + @TestMetadata("MembersIntoClass.txt") + public void testMembersIntoClass() throws Exception { + runTest("nj2k/testData/copyPastePlainText/MembersIntoClass.txt"); + } + + @TestMetadata("MembersToTopLevel.txt") + public void testMembersToTopLevel() throws Exception { + runTest("nj2k/testData/copyPastePlainText/MembersToTopLevel.txt"); + } + + @TestMetadata("Override.txt") + public void testOverride() throws Exception { + runTest("nj2k/testData/copyPastePlainText/Override.txt"); + } + + @TestMetadata("OverrideInterface.txt") + public void testOverrideInterface() throws Exception { + runTest("nj2k/testData/copyPastePlainText/OverrideInterface.txt"); + } + + @TestMetadata("PostProcessing.txt") + public void testPostProcessing() throws Exception { + runTest("nj2k/testData/copyPastePlainText/PostProcessing.txt"); + } + + @TestMetadata("StatementsIntoFunction.txt") + public void testStatementsIntoFunction() throws Exception { + runTest("nj2k/testData/copyPastePlainText/StatementsIntoFunction.txt"); + } + + @TestMetadata("WholeFile.txt") + public void testWholeFile() throws Exception { + runTest("nj2k/testData/copyPastePlainText/WholeFile.txt"); + } +}