handle semicolons in "introduce backing property"

#KT-9417 Fixed
This commit is contained in:
Dmitry Jemerov
2015-10-01 20:49:37 +02:00
parent 3ed04aea8a
commit 2884a1c6ea
4 changed files with 24 additions and 2 deletions
@@ -89,13 +89,18 @@ class IntroduceBackingPropertyIntention(): JetSelfTargetingIntention<JetProperty
private fun createGetter(element: JetProperty) {
val body = "get() = _${element.name}"
val newGetter = JetPsiFactory(element).createProperty("val x $body").getter!!
element.add(newGetter)
element.addAccessor(newGetter)
}
private fun createSetter(element: JetProperty) {
val body = "set(value) { _${element.name} = value }"
val newSetter = JetPsiFactory(element).createProperty("val x $body").setter!!
element.add(newSetter)
element.addAccessor(newSetter)
}
private fun JetProperty.addAccessor(newAccessor: JetPropertyAccessor) {
val semicolon = getNode().findChildByType(JetTokens.SEMICOLON)
addBefore(newAccessor, semicolon?.psi)
}
private fun createBackingProperty(property: JetProperty) {
@@ -0,0 +1,3 @@
class City(val name: String) {
var ti<caret>meZone : Int = -3;
}
@@ -0,0 +1,8 @@
class City(val name: String) {
private var _timeZone: Int = -3
var timeZone : Int
get() = _timeZone
set(value) {
_timeZone = value
};
}
@@ -5268,6 +5268,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("semicolon.kt")
public void testSemicolon() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/introduceBackingProperty/semicolon.kt");
doTest(fileName);
}
@TestMetadata("simpleVal.kt")
public void testSimpleVal() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/introduceBackingProperty/simpleVal.kt");