Conversion to Kotlin on paste: supported for annotation
This commit is contained in:
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.psi.psiUtil.allChildren
|
||||
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
@@ -217,11 +218,16 @@ data class DataForConversion private(
|
||||
}
|
||||
else {
|
||||
add(fileText.substring(range.start, elements.first().range.start))
|
||||
addAll(elements)
|
||||
elements.flatMapTo(this) {
|
||||
if (shouldExpandToChildren(it)) it.allChildren.toList() else listOf(it)
|
||||
}
|
||||
add(fileText.substring(elements.last().range.end, range.end))
|
||||
}
|
||||
}
|
||||
|
||||
// converting of PsiModifierList is not supported by converter, but converting of single annotations inside it is supported
|
||||
private fun shouldExpandToChildren(element: PsiElement) = element is PsiModifierList
|
||||
|
||||
private fun buildImportsAndPackage(sourceFile: PsiJavaFile): String {
|
||||
return StringBuilder {
|
||||
val packageName = sourceFile.getPackageName()
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Ann(String::class)
|
||||
class X
|
||||
@@ -0,0 +1,7 @@
|
||||
@interface Ann {
|
||||
Class value();
|
||||
}
|
||||
|
||||
<selection>@Ann(String.class)
|
||||
</selection>class C {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<caret>class X
|
||||
+6
@@ -95,6 +95,12 @@ public class JavaToKotlinCopyPasteConversionTestGenerated extends AbstractJavaTo
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("CopyAnnotation.java")
|
||||
public void testCopyAnnotation() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/copyPaste/conversion/CopyAnnotation.java");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FieldWithNoEndComment.java")
|
||||
public void testFieldWithNoEndComment() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/copyPaste/conversion/FieldWithNoEndComment.java");
|
||||
|
||||
Reference in New Issue
Block a user