New J2K: add plain text copy-paste conversion test for new J2K

This commit is contained in:
Ilya Kirillov
2019-07-09 16:09:57 +03:00
parent 041677ab1b
commit f0dd21790a
60 changed files with 526 additions and 5 deletions
@@ -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<String>) {
testClass<AbstractNewJavaToKotlinCopyPasteConversionTest> {
model("copyPaste", pattern = """^([^\.]+)\.java$""")
}
testClass<AbstractTextNewJavaToKotlinCopyPasteConversionTest> {
model("copyPastePlainText", pattern = """^([^\.]+)\.txt$""")
}
testClass<AbstractNullabilityAnalysisTest> {
model("nullabilityAnalysis")
}
@@ -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())
}
}
@@ -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
@@ -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
@@ -0,0 +1,7 @@
import java.util.ArrayList
fun foo() {
bar(ArrayList<String>())
}
+3
View File
@@ -0,0 +1,3 @@
fun foo() {
bar(<caret>)
}
+1
View File
@@ -0,0 +1 @@
new ArrayList<String>()
@@ -0,0 +1,5 @@
import java.util.ArrayList
fun foo() = ArrayList<String>()
@@ -0,0 +1 @@
fun foo() = <caret>
+1
View File
@@ -0,0 +1 @@
new ArrayList<String>()
@@ -0,0 +1,10 @@
package com.example
import java.util.UUID
class ExampleClass {
override fun toString(): String {
return UUID.randomUUID().toString()
}
}
@@ -0,0 +1,8 @@
package com.example
import java.util.UUID
class ExampleClass {
<caret>
}
+4
View File
@@ -0,0 +1,4 @@
@Override
public String toString() {
return UUID.randomUUID().toString();
}
@@ -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 {
}
}
@@ -0,0 +1,32 @@
package test
class ToBeImportedKotlin {
}
interface IAmbiguous {
}
interface Ambiguous {
}
interface IAmbiguousKotlin {
}
interface AmbiguousKotlin {
}
class Z {
interface IAmbiguousKotlin {
}
interface AmbiguousKotlin {
}
}
@@ -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<String> = ArrayList()
var unresolved: UnresolvedInterface<UnresolvedGeneric?>? = UnresolvedImplementation() // Should not add import
var hashMapOfNotImported: Map<ToBeImportedJava, ToBeImportedKotlin> = 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()
}
}
+3
View File
@@ -0,0 +1,3 @@
class Target {
<caret>
}
+22
View File
@@ -0,0 +1,22 @@
public List<String> listOfPlatformType = new ArrayList<String>();
UnresolvedInterface<UnresolvedGeneric> unresolved = new UnresolvedImplementation<>(); // Should not add import
Map<ToBeImportedJava, ToBeImportedKotlin> 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();
}
@@ -0,0 +1,4 @@
fun foo() {
bArrayList<String> list = new ArrayList<String>();
// NO_CONVERSION_EXPECTEDar()
}
@@ -0,0 +1,3 @@
fun foo() {
b<caret>ar()
}
@@ -0,0 +1,3 @@
fun foo() {
b<caret>ar()
}
+2
View File
@@ -0,0 +1,2 @@
ArrayList<String> list = new ArrayList<String>();
// NO_CONVERSION_EXPECTED
@@ -0,0 +1,2 @@
// ArrayList<String> list = new ArrayList<String>();
//// NO_CONVERSION_EXPECTED
+1
View File
@@ -0,0 +1 @@
// <caret>
+2
View File
@@ -0,0 +1,2 @@
ArrayList<String> list = new ArrayList<String>();
// NO_CONVERSION_EXPECTED
@@ -0,0 +1,7 @@
fun foo() {
val v = """
ArrayList<String> list = new ArrayList<String>();
// NO_CONVERSION_EXPECTED
"""
}
@@ -0,0 +1,5 @@
fun foo() {
val v = """
<caret>
"""
}
@@ -0,0 +1,2 @@
ArrayList<String> list = new ArrayList<String>();
// NO_CONVERSION_EXPECTED
@@ -0,0 +1,4 @@
fun foo() {
val v = "ArrayList<String> list = new ArrayList<String>();\n" +
"// NO_CONVERSION_EXPECTED\n"
}
@@ -0,0 +1,3 @@
fun foo() {
val v = "<caret>"
}
@@ -0,0 +1,2 @@
ArrayList<String> list = new ArrayList<String>();
// NO_CONVERSION_EXPECTED
+9
View File
@@ -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"
}
+6
View File
@@ -0,0 +1,6 @@
package com.bignerdranch.beatbox.data
/**
* Created by Panel on 18.08.2016.
*/
<caret>
+4
View File
@@ -0,0 +1,4 @@
public class BeatBox {
private static final String TAG = "BeatBox";
private static final String SOUNDS_FOLDER = "sample_sounds";
}
@@ -0,0 +1,7 @@
import java.util.ArrayList
fun foo() {
bar(/*comment*/ArrayList<String>())
}
+3
View File
@@ -0,0 +1,3 @@
fun foo() {
bar(/*comment*/<caret>)
}
+1
View File
@@ -0,0 +1 @@
new ArrayList<String>()
@@ -0,0 +1,13 @@
import java.util.ArrayList
class A {
internal fun foo() {
val list = ArrayList<String>()
list.add(1)
}
internal fun bar() {}
}
@@ -0,0 +1,3 @@
class A {
<caret>
}
@@ -0,0 +1,3 @@
class A {
<caret>
}
+7
View File
@@ -0,0 +1,7 @@
void foo() {
ArrayList<String> list = new ArrayList<String>();
list.add(1);
}
void bar() {
}
@@ -0,0 +1,11 @@
package to
import java.util.ArrayList
internal fun foo() {
val list = ArrayList<String>()
list.add(1)
}
internal fun bar() {}
@@ -0,0 +1,7 @@
void foo() {
ArrayList<String> list = new ArrayList<String>();
list.add(1);
}
void bar() {
}
@@ -0,0 +1,5 @@
package test;
public class JavaParent {
public void subject() {}
}
+5
View File
@@ -0,0 +1,5 @@
import test.JavaParent
class KotlinChild : JavaParent() {
override fun subject() {}
}
+5
View File
@@ -0,0 +1,5 @@
import test.JavaParent
class KotlinChild : JavaParent() {
<caret>
}
+1
View File
@@ -0,0 +1 @@
@Override public void subject() {}
@@ -0,0 +1,7 @@
package test;
import org.jetbrains.annotations.Nullable;
public interface JavaInterface {
void subject(@Nullable String s)
}
@@ -0,0 +1,5 @@
import test.JavaInterface
class KotlinChild : JavaInterface() {
override fun subject(s: String?) {}
}
@@ -0,0 +1,5 @@
import test.JavaInterface
class KotlinChild : JavaInterface() {
<caret>
}
@@ -0,0 +1 @@
@Override public void subject(String s) {}
@@ -0,0 +1,15 @@
package to
import java.io.File
import java.util.ArrayList
class JavaClass {
internal fun foo(file: File?, target: List<String?>?) {
val list = ArrayList<String?>()
if (file != null) {
list.add(file.name)
}
target?.addAll(list)
}
}
+15
View File
@@ -0,0 +1,15 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
class JavaClass {
void foo(File file, List<String> target) {
ArrayList<String> list = new ArrayList<String>();
if (file != null) {
list.add(file.getName());
}
if (target != null) {
target.addAll(list);
}
}
}
@@ -0,0 +1,9 @@
import java.util.ArrayList
fun foo() {
val list = ArrayList<String>()
list.add(1)
}
@@ -0,0 +1,3 @@
fun foo() {
<caret>
}
@@ -0,0 +1,2 @@
ArrayList<String> list = new ArrayList<String>();
list.add(1);
+11
View File
@@ -0,0 +1,11 @@
package to
import java.util.ArrayList
class JavaClass {
internal fun foo() {
val list = ArrayList<String>()
list.add(1)
}
}
+8
View File
@@ -0,0 +1,8 @@
import java.util.ArrayList;
class JavaClass {
void foo() {
ArrayList<String> list = new ArrayList<String>();
list.add(1);
}
}
@@ -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
}
@@ -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");
}
}