Extraction Engine: Support lazy properties and properties with initializer
This commit is contained in:
@@ -535,7 +535,7 @@ public class JetPsiFactory(private val project: Project) {
|
||||
state = State.RECEIVER
|
||||
}
|
||||
|
||||
private fun blockPrefix() = when (target) {
|
||||
private fun bodyPrefix() = when (target) {
|
||||
Target.FUNCTION -> ""
|
||||
Target.READ_ONLY_PROPERTY -> "\nget()"
|
||||
}
|
||||
@@ -621,19 +621,28 @@ public class JetPsiFactory(private val project: Project) {
|
||||
return this
|
||||
}
|
||||
|
||||
public fun simpleBody(body: String): CallableBuilder {
|
||||
public fun blockBody(body: String): CallableBuilder {
|
||||
assert(state == State.BODY || state == State.TYPE_CONSTRAINTS)
|
||||
|
||||
sb.append(blockPrefix()).append(" = ").append(body)
|
||||
sb.append(bodyPrefix()).append(" {\n").append(body).append("\n}")
|
||||
state = State.DONE
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public fun blockBody(body: String): CallableBuilder {
|
||||
assert(state == State.BODY || state == State.TYPE_CONSTRAINTS)
|
||||
public fun initializer(body: String): CallableBuilder {
|
||||
assert(target == Target.READ_ONLY_PROPERTY && (state == State.BODY || state == State.TYPE_CONSTRAINTS))
|
||||
|
||||
sb.append(blockPrefix()).append(" {\n").append(body).append("\n}")
|
||||
sb.append(" = ").append(body)
|
||||
state = State.DONE
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public fun lazyBody(body: String): CallableBuilder {
|
||||
assert(target == Target.READ_ONLY_PROPERTY && (state == State.BODY || state == State.TYPE_CONSTRAINTS))
|
||||
|
||||
sb.append(" by kotlin.properties.Delegates.lazy {\n").append(body).append("\n}")
|
||||
state = State.DONE
|
||||
|
||||
return this
|
||||
|
||||
@@ -130,11 +130,17 @@ public fun JetElement.outermostLastBlockElement(predicate: (JetElement) -> Boole
|
||||
return JetPsiUtil.getOutermostLastBlockElement(this) { e -> e != null && predicate(e) }
|
||||
}
|
||||
|
||||
public fun JetBlockExpression.appendElement(element: JetElement): JetElement =
|
||||
addAfter(element, getRBrace()!!.getPrevSibling()!!)!! as JetElement
|
||||
|
||||
public fun JetBlockExpression.prependElement(element: JetElement): JetElement =
|
||||
addBefore(element, getLBrace()!!.getNextSibling()!!)!! as JetElement
|
||||
public fun JetBlockExpression.appendElement(element: JetElement): JetElement {
|
||||
val rBrace = getRBrace()
|
||||
val anchor = if (rBrace == null) {
|
||||
val lastChild = getLastChild()
|
||||
if (lastChild !is PsiWhiteSpace) addAfter(JetPsiFactory(this).createNewLine(), lastChild)!! else lastChild
|
||||
}
|
||||
else {
|
||||
rBrace.getPrevSibling()!!
|
||||
}
|
||||
return addAfter(element, anchor)!! as JetElement
|
||||
}
|
||||
|
||||
public fun JetElement.wrapInBlock(): JetBlockExpression {
|
||||
val block = JetPsiFactory(this).createEmptyBody()
|
||||
|
||||
Reference in New Issue
Block a user