Fixed bug with bad conversion on paste when top-level java class copied

This commit is contained in:
Valentin Kipyatkov
2015-04-10 12:43:50 +03:00
parent aff17a9fa1
commit 965f3da2b1
9 changed files with 38 additions and 7 deletions
@@ -588,7 +588,7 @@ fun main(args: Array<String>) {
}
testClass(javaClass<AbstractJavaToKotlinCopyPasteConversionTest>()) {
model("copyPaste/conversion", extension = "java")
model("copyPaste/conversion", pattern = """^([^\.]+)\.java$""")
}
testClass(javaClass<AbstractInsertImportOnPasteTest>()) {
@@ -144,8 +144,7 @@ data class DataForConversion private(
// element's text can be removed from file's text keeping parsing the same
private fun canDropElementFromText(element: PsiElement): Boolean {
return when (element) {
is PsiWhiteSpace, is PsiComment, is PsiModifierList,
is PsiAnnotation, is PsiPackageStatement, is PsiImportList, is PsiImportStatementBase -> true
is PsiWhiteSpace, is PsiComment, is PsiModifierList, is PsiAnnotation -> true
is PsiJavaToken -> {
when (element.getTokenType()) {
@@ -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
public class C : I {
override fun foo(): String {
return ""
}
}
@@ -0,0 +1,11 @@
package javaPack
import org.jetbrains.annotations.NotNull;
<selection>public class C implements I {
@NotNull
@Override
public String foo() {
return "";
}
}</selection>
@@ -5,5 +5,3 @@ public object JavaClass {
println("Hello, world!")
}
}
fun main(args: Array<String>) = JavaClass.main(args)
@@ -1,4 +1,3 @@
// this test should cause the whole file to be converted at once (with non-selected text stripped) and the main function to be generated
package helloWorld;
// sample class
@@ -58,6 +58,7 @@ public abstract class AbstractJavaToKotlinCopyPasteConversionTest : AbstractCopy
myFixture.performEditorAction(IdeActions.ACTION_COPY)
configureByDependencyIfExists(testName + ".dependency.kt")
configureByDependencyIfExists(testName + ".dependency.java")
configureTargetFile(testName + ".to.kt")
@@ -62,7 +62,7 @@ public class JavaToKotlinCopyPasteConversionTestGenerated extends AbstractJavaTo
}
public void testAllFilesPresentInConversion() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/copyPaste/conversion"), Pattern.compile("^(.+)\\.java$"), true);
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/copyPaste/conversion"), Pattern.compile("^([^\\.]+)\\.java$"), true);
}
@TestMetadata("Arithmetic.java")
@@ -77,6 +77,12 @@ public class JavaToKotlinCopyPasteConversionTestGenerated extends AbstractJavaTo
doTest(fileName);
}
@TestMetadata("ClassWithOverrides.java")
public void testClassWithOverrides() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/copyPaste/conversion/ClassWithOverrides.java");
doTest(fileName);
}
@TestMetadata("Constructor.java")
public void testConstructor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/copyPaste/conversion/Constructor.java");