Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parser #39

Merged
merged 2 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ast-psi/src/main/kotlin/ktast/ast/psi/Converter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.allChildren
import org.jetbrains.kotlin.psi.psiUtil.children
import org.jetbrains.kotlin.psi.psiUtil.siblings

open class Converter {
Expand Down Expand Up @@ -950,19 +949,20 @@ open class Converter {
args = v.valueArgumentList?.let(::convertValueArgs),
)

open fun convertModifiers(v: KtModifierList) = Node.Modifiers(
elements = v.node.children().mapNotNull { node ->
// We go over the node children because we want to preserve order
node.psi.let { psi ->
open fun convertModifiers(v: KtModifierList): Node.Modifiers {
val nonExtraChildren = v.allChildren.filterNot { it is PsiComment || it is PsiWhiteSpace }.toList()
return Node.Modifiers(
elements = nonExtraChildren.mapNotNull { psi ->
// We go over the node children because we want to preserve order
when (psi) {
is KtAnnotationEntry -> convertAnnotationSet(psi)
is KtAnnotation -> convertAnnotationSet(psi)
is PsiWhiteSpace -> null
else -> convertKeywordModifier(psi)
}
}
}.toList(),
).map(v)
}.toList(),
).map(v)
}

open fun convertKeywordModifier(v: PsiElement) = Node.Modifier.Keyword.of(v.text)
.map(v)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package localTestData

class Test {

@Nested
// This is a nested test case
inner class TestCase {
}
}
5 changes: 5 additions & 0 deletions ast-psi/src/test/resources/localTestData/valueClass.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package localTestData

// For JVM backends
@JvmInline
value class Password(private val s: String)
2 changes: 1 addition & 1 deletion ast/src/commonMain/kotlin/ktast/ast/Node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ sealed class Node {
}

enum class Token : HasSimpleStringRepresentation {
ABSTRACT, FINAL, OPEN, ANNOTATION, SEALED, DATA, OVERRIDE, LATEINIT, INNER, ENUM, COMPANION,
ABSTRACT, FINAL, OPEN, ANNOTATION, SEALED, DATA, OVERRIDE, LATEINIT, INNER, ENUM, COMPANION, VALUE,
PRIVATE, PROTECTED, PUBLIC, INTERNAL,
IN, OUT, NOINLINE, CROSSINLINE, VARARG, REIFIED,
TAILREC, OPERATOR, INFIX, INLINE, EXTERNAL, SUSPEND, CONST, FUN,
Expand Down