kotlinx / ast

Generic AST parsing library for kotlin multiplatform
Apache License 2.0
325 stars 23 forks source link

Constructor parameters and properties defined in constructor #1

Closed martinflorek closed 5 years ago

martinflorek commented 5 years ago

The parser now handles "escaped" characters inside annotations' values but I have found another missing node.

The AST does not contain constructor parameters and properties declared in constructor e.g.:

class TestClass(
    @Value("test value")
    private val propertyA: String
)
drieks commented 5 years ago

Hi @martinflorek, please try Version 4f20128eaf.

I removed KlassArgument and the constructor is now reported as KlassDeclaration(constructor), including all arguments (also of type KlassDeclaration)

You can find the new AST structure of your test case here: https://github.com/kotlinx/ast/blob/4f20128eaf4d5d59b6c68448bfa53c266c823eec/kotlin/src/commonTest/resources/testdata/ConstructorParametersAndProperties.summary.txt

martinflorek commented 5 years ago

Now all my tests are crashing on calling summary() i.e. KotlinAstParser.parseKotlinFile(source).summary() throws java.lang.UnsupportedOperationException: Empty collection can't be reduced..

Parsing anything leads to a new structure and summary() does not work anymore...

martinflorek commented 5 years ago

Sorry, this is not true. The constructor works OK and I have other special case that is causing the crash with summary(). I will try to isolate it into a small test case.

drieks commented 5 years ago

Hi @martinflorek, can you provide a stacktrace? Or a small kotlin file example causing this?

All unit tests included in kotlinx.ast are working fine, I think you have something in your kotlin files that is not included in the tests.

I will add a test that tries to parse https://github.com/arrow-kt/arrow to find the bug this evening (I'm living in Germany, currently GMT+2)

martinflorek commented 5 years ago

I have added a minimalistic example in #2 that leads to weird AST structure which crashes after calling summary() on it.

drieks commented 5 years ago

I think this issue is resolved now, like #2.