New J2K: add copy-paste tests for new j2k
This commit is contained in:
@@ -154,6 +154,7 @@ import org.jetbrains.kotlin.kapt.cli.test.AbstractKaptToolIntegrationTest
|
||||
import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTest
|
||||
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.noarg.AbstractBlackBoxCodegenTestForNoArg
|
||||
import org.jetbrains.kotlin.noarg.AbstractBytecodeListingTestForNoArg
|
||||
@@ -982,6 +983,9 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractNewJavaToKotlinConverterSingleFileTest> {
|
||||
model("newJ2k", extension = "java")
|
||||
}
|
||||
testClass<AbstractNewJavaToKotlinCopyPasteConversionTest> {
|
||||
model("copyPaste", pattern = """^([^\.]+)\.java$""")
|
||||
}
|
||||
testClass<AbstractNullabilityAnalysisTest> {
|
||||
model("nullabilityAnalysis")
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ import org.jetbrains.kotlin.kapt.cli.test.AbstractKaptToolIntegrationTest
|
||||
import org.jetbrains.kotlin.kapt3.test.AbstractClassFileToSourceStubConverterTest
|
||||
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.noarg.AbstractBlackBoxCodegenTestForNoArg
|
||||
import org.jetbrains.kotlin.noarg.AbstractBytecodeListingTestForNoArg
|
||||
@@ -950,6 +951,9 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractNewJavaToKotlinConverterSingleFileTest> {
|
||||
model("newJ2k", extension = "java")
|
||||
}
|
||||
testClass<AbstractNewJavaToKotlinCopyPasteConversionTest> {
|
||||
model("copyPaste", pattern = """^([^\.]+)\.java$""")
|
||||
}
|
||||
testClass<AbstractNullabilityAnalysisTest> {
|
||||
model("nullabilityAnalysis")
|
||||
}
|
||||
|
||||
+4
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.idea.conversion.copy
|
||||
|
||||
import com.intellij.openapi.actionSystem.IdeActions
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import org.jetbrains.kotlin.idea.AbstractCopyPasteTest
|
||||
import org.jetbrains.kotlin.idea.editor.KotlinEditorOptions
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
@@ -22,10 +23,13 @@ abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractCopyPasteTe
|
||||
|
||||
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
|
||||
|
||||
@@ -31,6 +31,7 @@ dependencies {
|
||||
|
||||
testCompile(project(":idea"))
|
||||
testCompile(projectTests(":j2k"))
|
||||
testCompile(projectTests(":idea"))
|
||||
testCompile(project(":nj2k:nj2k-services"))
|
||||
testCompile(projectTests(":idea:idea-test-framework"))
|
||||
testCompile(project(":compiler:light-classes"))
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import java.io.File
|
||||
|
||||
internal fun foo(file: File?): List<String> {
|
||||
return emptyList()
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class C {
|
||||
<selection> List<String> foo(File file) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
</selection>}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<caret>
|
||||
@@ -0,0 +1,3 @@
|
||||
import java.io.File
|
||||
|
||||
fun foo(): List<File>
|
||||
@@ -0,0 +1,10 @@
|
||||
// NO_CONVERSION_EXPECTED
|
||||
import java.io.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
class C {
|
||||
<selection>List<File></selection> foo() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun foo(): <caret>
|
||||
@@ -0,0 +1,5 @@
|
||||
import java.io.File
|
||||
|
||||
fun foo() {
|
||||
list.add(File.separatorChar)
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package ppp
|
||||
|
||||
public object Dependency {
|
||||
@JvmStatic
|
||||
public val FIELD: Int = 1
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import ppp.Dependency
|
||||
|
||||
fun f() {
|
||||
return Dependency.FIELD
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package ppp
|
||||
|
||||
class C {
|
||||
char foo() {
|
||||
<selection>return Dependency.FIELD;</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun f() {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package ppp
|
||||
|
||||
class dummy0
|
||||
@@ -0,0 +1,5 @@
|
||||
import ppp.dummy0
|
||||
|
||||
fun f() {
|
||||
return dummy0()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import ppp.*
|
||||
|
||||
class C {
|
||||
dummy0 foo() {
|
||||
<selection>return dummy0();</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun f() {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.io.File
|
||||
|
||||
class C {
|
||||
private fun memberFun(file: File?) {}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import java.io.File;
|
||||
|
||||
<selection>class C {
|
||||
public static void main(String[] args) { }
|
||||
private void memberFun(File file) {}
|
||||
}</selection>
|
||||
@@ -0,0 +1 @@
|
||||
<caret>
|
||||
@@ -0,0 +1,5 @@
|
||||
package to
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val value: KClass<*>)
|
||||
@@ -0,0 +1,6 @@
|
||||
<selection>@interface Ann {
|
||||
Class value();
|
||||
}</selection>
|
||||
|
||||
class X {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
val v = b - c + d
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// NO_CONVERSION_EXPECTED
|
||||
public static void main(String[]args){
|
||||
a + <selection>b - c + d</selection> - e
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
val v = <caret>
|
||||
@@ -0,0 +1,5 @@
|
||||
package to
|
||||
|
||||
class JavaClass : Runnable {
|
||||
override fun run() {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Doc comment for JavaClass
|
||||
*/
|
||||
<selection>public class JavaClass implements Runnable{
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}
|
||||
</selection>
|
||||
@@ -0,0 +1,8 @@
|
||||
package javaPack
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface I {
|
||||
@NotNull
|
||||
String foo();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package to
|
||||
|
||||
import javaPack.I
|
||||
|
||||
class C : I {
|
||||
override fun foo(): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package javaPack
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
<selection>public class C implements I {
|
||||
@NotNull
|
||||
@Override
|
||||
public String foo() {
|
||||
return "";
|
||||
}
|
||||
}</selection>
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
A()
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
<selection>new A()</selection>;
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class Dependency {
|
||||
fun getInt(): Int = 1
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
internal fun foo(p: Dependency): Double {
|
||||
return p.getInt().toDouble() // explicit conversion to Double must be added on conversion (if type Dependency) is correctly resolved
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class C {
|
||||
<selection> double foo(Dependency p) {
|
||||
return p.getInt(); // explicit conversion to Double must be added on conversion (if type Dependency) is correctly resolved
|
||||
}
|
||||
</selection>}
|
||||
@@ -0,0 +1 @@
|
||||
<caret>
|
||||
@@ -0,0 +1,2 @@
|
||||
@Ann(String::class)
|
||||
class X
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
@interface Ann {
|
||||
Class value();
|
||||
}
|
||||
|
||||
<selection>@Ann(String.class)
|
||||
</selection>class C {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<caret>class X
|
||||
@@ -0,0 +1 @@
|
||||
class B : X<String, X<Int, Any>>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class X<T, U> {
|
||||
|
||||
}
|
||||
|
||||
class A extends <selection>X<String, X<Integer, Object>></selection> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class B : <caret>
|
||||
@@ -0,0 +1,3 @@
|
||||
package to
|
||||
|
||||
private const val field = 1
|
||||
@@ -0,0 +1,3 @@
|
||||
public class JavaClass {
|
||||
<selection>private int field = 1;</selection> // comment for field
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package to
|
||||
|
||||
@Volatile
|
||||
internal var field = 1
|
||||
@@ -0,0 +1,3 @@
|
||||
public class JavaClass {
|
||||
public <selection>volatile int field = 1</selection>;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package to
|
||||
|
||||
object JavaClass {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello, world!")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package helloWorld;
|
||||
|
||||
// sample class
|
||||
<selection>public class JavaClass {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, world!");
|
||||
}
|
||||
}
|
||||
</selection>
|
||||
@@ -0,0 +1,10 @@
|
||||
class A {
|
||||
|
||||
|
||||
internal fun foo() {}
|
||||
|
||||
internal fun bar() {}
|
||||
|
||||
|
||||
fun f() {}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class A {
|
||||
|
||||
<selection>
|
||||
void foo() {}
|
||||
|
||||
void bar() {}
|
||||
|
||||
</selection>
|
||||
void foobar() {}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
|
||||
<caret>
|
||||
|
||||
fun f() {}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class B : X<String, X<Int, Any>>
|
||||
@@ -0,0 +1,7 @@
|
||||
interface X<T, U> {
|
||||
|
||||
}
|
||||
|
||||
class A implements <selection>X<String, X<Integer, Object>></selection> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class B : <caret>
|
||||
@@ -0,0 +1,7 @@
|
||||
import a.b.c
|
||||
import g.e.v
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<selection>import java.util.List;
|
||||
import a.b.c;
|
||||
import java.util.Set;
|
||||
import g.e.v;</selection>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<caret>
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
<selection>import java.util.List;</selection>
|
||||
import a.b.c;
|
||||
import java.util.Set;
|
||||
import g.e.v;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<caret>
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import g.e.v
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import java.util.List;
|
||||
import a.b.c;
|
||||
import java.util.Set;
|
||||
<selection>import g.e.v;</selection>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<caret>
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
if (x > 0) x = 2 else x = 3
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
public static void main(String[]args){
|
||||
<selection>if (x > 0)
|
||||
x = 2;
|
||||
else
|
||||
x = 3;</selection>
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
fun main(args: Array<String>) { <caret>
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// String s = 1;
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
<selection>String s = 1;</selection>
|
||||
}
|
||||
}
|
||||
|
||||
// NO_CONVERSION_EXPECTED
|
||||
@@ -0,0 +1 @@
|
||||
// <caret>
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
println("String s = 1;")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
<selection>String s = 1;</selection>
|
||||
}
|
||||
}
|
||||
|
||||
// NO_CONVERSION_EXPECTED
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
println("<caret>")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package to
|
||||
|
||||
internal fun foo(p: Int)
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
public <selection>void foo(int p)</selection> {
|
||||
System.out.println("foo");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun main(args: Array<String>) {
|
||||
reference(arg)
|
||||
somethingElse()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// NO_CONVERSION_EXPECTED
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
qualifier.<selection>reference(arg)</selection>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun main(args: Array<String>) {
|
||||
<caret>
|
||||
somethingElse()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package to
|
||||
|
||||
fun foo(): String {
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
public class JavaClass {
|
||||
@Deprecated
|
||||
<selection> public String foo() {
|
||||
return "";
|
||||
}
|
||||
</selection>}
|
||||
@@ -0,0 +1,6 @@
|
||||
package to
|
||||
|
||||
@SomeAnnotation
|
||||
fun foo(): String {
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
public class JavaClass {
|
||||
@Deprecated
|
||||
<selection> @SomeAnnotation
|
||||
public String foo() {
|
||||
return "";
|
||||
}
|
||||
</selection>}
|
||||
@@ -0,0 +1 @@
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// NO_CONVERSION_EXPECTED
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
//sdasd
|
||||
}
|
||||
<selection>}</selection>
|
||||
@@ -0,0 +1 @@
|
||||
<caret>
|
||||
@@ -0,0 +1,4 @@
|
||||
fun main(args: Array<String>) {
|
||||
{
|
||||
val a = Any()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
public static void main(String[] args) <selection>{
|
||||
Object a = new Object();</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main(args: Array<String>) {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
fun main(args: Array<String>) {
|
||||
qualifier
|
||||
somethingElse()
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// NO_CONVERSION_EXPECTED
|
||||
class A {
|
||||
public static void main(String[] args) {
|
||||
<selection>qualifier</selection>.reference(arg);
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun main(args: Array<String>) {
|
||||
<caret>
|
||||
somethingElse()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class B : X<*>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
interface X<T> {
|
||||
|
||||
}
|
||||
|
||||
class A implements <selection>X</selection> {
|
||||
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
class B : <caret>
|
||||
@@ -0,0 +1,6 @@
|
||||
fun foo(o: Any) {
|
||||
if (o is String) {
|
||||
val l = o.length
|
||||
}
|
||||
somethingElse()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
void foo(Object o) {
|
||||
<selection> if (o instanceof String) {
|
||||
int l = ((String) o).length();
|
||||
}
|
||||
</selection> }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(o: Any) {
|
||||
<caret> somethingElse()
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(o: Any) {
|
||||
if (o !is String) return
|
||||
val l = o.length
|
||||
somethingElse(o as String/* we should not remove this cast because it's not in pasted range*/)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user