Convert to block body: adjust line indent
#KT-22368 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
1bc72f0b32
commit
30366148bf
@@ -23,7 +23,10 @@ import org.jetbrains.kotlin.idea.KotlinBundle
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
import org.jetbrains.kotlin.idea.core.setType
|
import org.jetbrains.kotlin.idea.core.setType
|
||||||
|
import org.jetbrains.kotlin.idea.formatter.adjustLineIndent
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.isError
|
import org.jetbrains.kotlin.types.isError
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||||
@@ -93,7 +96,8 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention<KtDeclarationWithBody
|
|||||||
}
|
}
|
||||||
|
|
||||||
declaration.equalsToken!!.delete()
|
declaration.equalsToken!!.delete()
|
||||||
body.replace(newBody)
|
val replaced = body.replace(newBody)
|
||||||
|
declaration.containingKtFile.adjustLineIndent(replaced.startOffset, replaced.endOffset)
|
||||||
return declaration
|
return declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun foo(x: Int,
|
||||||
|
y: Int) = <caret>x + y
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo(x: Int,
|
||||||
|
y: Int): Int {
|
||||||
|
return x + y
|
||||||
|
}
|
||||||
@@ -6595,6 +6595,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
runTest("idea/testData/intentions/convertToBlockBody/addSpace.kt");
|
runTest("idea/testData/intentions/convertToBlockBody/addSpace.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("adjustLineIndent.kt")
|
||||||
|
public void testAdjustLineIndent() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/convertToBlockBody/adjustLineIndent.kt");
|
||||||
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInConvertToBlockBody() throws Exception {
|
public void testAllFilesPresentInConvertToBlockBody() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/convertToBlockBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/convertToBlockBody"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user