Skip to content

Commit

Permalink
Update to 1.3.10 and support property expressions (fixes #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz committed Nov 26, 2018
1 parent 305a403 commit 7abbbd7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions ast-psi/src/main/kotlin/kastree/ast/psi/Converter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ open class Converter {
is KtCallExpression -> convertCall(v)
is KtArrayAccessExpression -> convertArrayAccess(v)
is KtNamedFunction -> convertAnonFunc(v)
// TODO: this can happen when a labeled expression uses a var decl as the expression
is KtProperty -> throw Unsupported("Property expressions not supported")
is KtProperty -> convertPropertyExpr(v)
is KtDestructuringDeclaration -> convertPropertyExpr(v)
// TODO: this is present in a recovery test where an interface decl is on rhs of a gt expr
is KtClass -> throw Unsupported("Class expressions not supported")
else -> error("Unrecognized expression type from $v")
Expand Down Expand Up @@ -450,6 +450,14 @@ open class Converter {
body = v.bodyExpression?.let(::convertFuncBody)
).map(v)

open fun convertPropertyExpr(v: KtDestructuringDeclaration) = Node.Expr.Property(
decl = convertProperty(v)
).map(v)

open fun convertPropertyExpr(v: KtProperty) = Node.Expr.Property(
decl = convertProperty(v)
).map(v)

open fun convertPropertyVar(v: KtDestructuringDeclarationEntry) =
if (v.name == "_") null else Node.Decl.Property.Var(
name = v.name ?: error("No property name on $v"),
Expand Down
3 changes: 3 additions & 0 deletions ast/ast-common/src/main/kotlin/kastree/ast/MutableVisitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ open class MutableVisitor {
is Node.Expr.AnonFunc -> copy(
func = visitChildren(func, newCh)
)
is Node.Expr.Property -> copy(
decl = visitChildren(decl, newCh)
)
is Node.Block -> copy(
stmts = visitChildren(stmts, newCh)
)
Expand Down
4 changes: 4 additions & 0 deletions ast/ast-common/src/main/kotlin/kastree/ast/Node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ sealed class Node {
data class AnonFunc(
val func: Decl.Func
) : Expr()
// This is only present for when expressions and labeled expressions
data class Property(
val decl: Decl.Property
) : Expr()
}

data class Block(val stmts: List<Stmt>) : Node()
Expand Down
3 changes: 3 additions & 0 deletions ast/ast-common/src/main/kotlin/kastree/ast/Visitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ open class Visitor {
is Node.Expr.AnonFunc -> {
visitChildren(func)
}
is Node.Expr.Property -> {
visitChildren(decl)
}
is Node.Block -> {
visitChildren(stmts)
}
Expand Down
2 changes: 2 additions & 0 deletions ast/ast-common/src/main/kotlin/kastree/ast/Writer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ open class Writer(
}
is Node.Expr.AnonFunc ->
children(func)
is Node.Expr.Property ->
children(decl)
is Node.Block -> {
// Special case, no braces if the parent is a brace
if (parent is Node.Expr.Brace) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.0'
ext.kotlin_version = '1.3.10'

repositories {
mavenCentral()
Expand Down

0 comments on commit 7abbbd7

Please sign in to comment.