File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
main/kotlin/chapi/ast/kotlinast
test/kotlin/chapi/ast/kotlinast Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -163,6 +163,17 @@ open class KotlinBasicIdentListener(private val fileName: String) : KotlinAstLis
163
163
isEnteredClass.decrementAndGet()
164
164
}
165
165
166
+ override fun enterCompanionObject (ctx : KotlinParser .CompanionObjectContext ? ) {
167
+ val classBody = ctx?.classBody() ? : return
168
+ classBody.classMemberDeclarations().classMemberDeclaration().forEach {
169
+ val propertyDeclaration = it.declaration()?.propertyDeclaration()
170
+ val functionDeclaration = it.declaration()?.functionDeclaration()
171
+
172
+ if (propertyDeclaration != null ) currentNode.Fields + = buildField(propertyDeclaration)
173
+ if (functionDeclaration != null ) currentNode.Functions + = buildFunction(functionDeclaration)
174
+ }
175
+ }
176
+
166
177
override fun enterPrimaryConstructor (ctx : KotlinParser .PrimaryConstructorContext ) {
167
178
val parameters = ctx.classParameters().classParameter().map(::buildProperty)
168
179
val fields = ctx.classParameters().classParameter().mapNotNull(::buildField)
Original file line number Diff line number Diff line change @@ -41,6 +41,26 @@ class KotlinFunctionCallTest {
41
41
assert (codeFunction.Name == " foo" )
42
42
}
43
43
44
+ @Test
45
+ fun should_support_for_companion_object () {
46
+ val code = """
47
+ class A {
48
+ companion object {
49
+ fun foo() {
50
+ println("Hello, world!")
51
+ }
52
+ }
53
+ }
54
+ """ .trimIndent()
55
+
56
+ val codeContainer = KotlinAnalyser ().analysis(code, " Test.kt" , ParseMode .Full )
57
+ val dataStructures = codeContainer.DataStructures .filter { it.NodeName == " A" }
58
+ val codeFunction = dataStructures[0 ].Functions [0 ]
59
+
60
+ assert (codeFunction.Name == " foo" )
61
+ }
62
+
63
+
44
64
@Test
45
65
fun should_success_parse_test_usecase () {
46
66
val code = """
You can’t perform that action at this time.
0 commit comments