Fix ConvertTextJavaCopyPasteProcessor after 4725dd3

In cases like 'fun foo() = \n fun dummy(){}'
declaration on the next line is parsed as top-level declaration.

But ConvertTextJavaCopyPasteProcessor expects that 'fun dummy(){}'
would be a part of an expression body, so we replace "\n" with " "
to turn off recovery in the case

See TextJavaToKotlinCopyPasteConversionTestGenerated.testAsExpressionBody
This commit is contained in:
Denis Zharkov
2016-07-16 09:10:00 +03:00
parent 2f2b1a7f80
commit 3b0131fd04
@@ -125,7 +125,7 @@ class ConvertTextJavaCopyPasteProcessor : CopyPastePostProcessor<TextBlockTransf
val fileText = file.text
val dummyDeclarationText = "fun dummy(){}"
val newFileText = fileText.substring(0, startOffset) + "\n" + dummyDeclarationText + "\n" + fileText.substring(endOffset)
val newFileText = fileText.substring(0, startOffset) + " " + dummyDeclarationText + "\n" + fileText.substring(endOffset)
val newFile = parseAsFile(newFileText, KotlinFileType.INSTANCE, file.project)
val declaration = PsiTreeUtil.findElementOfClassAtRange(newFile, startOffset + 1, startOffset + 1 + dummyDeclarationText.length, KtFunction::class.java) ?: return null