Conversion on copy paste: Reformat code after conversion
This commit is contained in:
@@ -31,6 +31,8 @@ import org.jetbrains.jet.lang.psi.JetFile
|
|||||||
import org.jetbrains.jet.plugin.editor.JetEditorOptions
|
import org.jetbrains.jet.plugin.editor.JetEditorOptions
|
||||||
import java.awt.datatransfer.Transferable
|
import java.awt.datatransfer.Transferable
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||||
|
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||||
|
|
||||||
public class JavaCopyPastePostProcessor() : CopyPastePostProcessor<TextBlockTransferableData> {
|
public class JavaCopyPastePostProcessor() : CopyPastePostProcessor<TextBlockTransferableData> {
|
||||||
|
|
||||||
@@ -73,8 +75,11 @@ public class JavaCopyPastePostProcessor() : CopyPastePostProcessor<TextBlockTran
|
|||||||
val text = convertCopiedCodeToKotlin(value, file.getProject())
|
val text = convertCopiedCodeToKotlin(value, file.getProject())
|
||||||
if (text.isNotEmpty()) {
|
if (text.isNotEmpty()) {
|
||||||
ApplicationManager.getApplication()!!.runWriteAction {
|
ApplicationManager.getApplication()!!.runWriteAction {
|
||||||
editor.getDocument().replaceString(bounds!!.getStartOffset(), bounds.getEndOffset(), text)
|
val startOffset = bounds!!.getStartOffset()
|
||||||
editor.getCaretModel().moveToOffset(bounds.getStartOffset() + text.length())
|
editor.getDocument().replaceString(bounds.getStartOffset(), bounds.getEndOffset(), text)
|
||||||
|
val endOffsetAfterCopy = startOffset + text.length()
|
||||||
|
editor.getCaretModel().moveToOffset(endOffsetAfterCopy)
|
||||||
|
CodeStyleManager.getInstance(project)!!.reformatText(file, startOffset, endOffsetAfterCopy)
|
||||||
PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument())
|
PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
class A {
|
class A {
|
||||||
|
|
||||||
|
|
||||||
fun foo() {}
|
fun foo() {
|
||||||
|
}
|
||||||
fun bar() {}
|
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun f() {}
|
fun f() {}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun main(args: Array<String>) {
|
||||||
|
if (x > 0)
|
||||||
|
x = 2
|
||||||
|
else
|
||||||
|
x = 3
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
class A {
|
||||||
|
public static void main(String[]args){
|
||||||
|
<selection>if (x > 0)
|
||||||
|
x = 2;
|
||||||
|
else
|
||||||
|
x = 3;</selection>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun main(args: Array<String>) { <caret>
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
class A {
|
class A {
|
||||||
fun someOther() = false
|
fun someOther() = false
|
||||||
|
|
||||||
private fun formatElement(var element : PsiElement) : String {
|
private fun formatElement(var element: PsiElement): String {
|
||||||
element = JetPsiUtil.ascendIfPropertyAccessor(element)
|
element = JetPsiUtil.ascendIfPropertyAccessor(element)
|
||||||
if (element is JetNamedFunction || element is JetProperty)
|
if (element is JetNamedFunction || element is JetProperty)
|
||||||
{
|
{
|
||||||
@@ -18,15 +18,15 @@ class A {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(element is PsiMethod) {"Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found"}
|
assert(element is PsiMethod) { "Method accepts only kotlin functions/properties and java methods, but '" + element.getText() + "' was found" }
|
||||||
return JetRefactoringUtil.formatPsiMethod((element as PsiMethod), true, false)
|
return JetRefactoringUtil.formatPsiMethod((element as PsiMethod), true, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getDimensionServiceKey() : String {
|
protected fun getDimensionServiceKey(): String {
|
||||||
return "#org.jetbrains.jet.plugin.refactoring.safeDelete.KotlinOverridingDialog"
|
return "#org.jetbrains.jet.plugin.refactoring.safeDelete.KotlinOverridingDialog"
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun getSelected() : ArrayList<UsageInfo> {
|
public fun getSelected(): ArrayList<UsageInfo> {
|
||||||
val result = ArrayList<UsageInfo>()
|
val result = ArrayList<UsageInfo>()
|
||||||
for (i in 0..myChecked.length - 1) {
|
for (i in 0..myChecked.length - 1) {
|
||||||
if (myChecked[i])
|
if (myChecked[i])
|
||||||
|
|||||||
+5
@@ -66,6 +66,11 @@ public class JavaToKotlinCopyPasteConversionTestGenerated extends AbstractJavaTo
|
|||||||
doTest("idea/testData/copyPaste/conversion/Imports3.java");
|
doTest("idea/testData/copyPaste/conversion/Imports3.java");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Indentation.java")
|
||||||
|
public void testIndentation() throws Exception {
|
||||||
|
doTest("idea/testData/copyPaste/conversion/Indentation.java");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("MethodReferenceWithoutQualifier.java")
|
@TestMetadata("MethodReferenceWithoutQualifier.java")
|
||||||
public void testMethodReferenceWithoutQualifier() throws Exception {
|
public void testMethodReferenceWithoutQualifier() throws Exception {
|
||||||
doTest("idea/testData/copyPaste/conversion/MethodReferenceWithoutQualifier.java");
|
doTest("idea/testData/copyPaste/conversion/MethodReferenceWithoutQualifier.java");
|
||||||
|
|||||||
Reference in New Issue
Block a user