Skip to content

Commit

Permalink
refactor(goast): improve type resolution in GoFullIdentListener.kt
Browse files Browse the repository at this point in the history
Remove unnecessary checks and ensure correct type retrieval for struct references. This enhances the accuracy of the type declaration extraction by checking the existence of children before accessing them.
  • Loading branch information
phodal committed Nov 12, 2024
1 parent ec368f8 commit c825273
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,12 @@ class GoFullIdentListener(var fileName: String) : GoAstListener() {
else -> {
if (firstChild.text == "&") {
val second = it.getChild(1)
/// new struct, like &http.Request{}
if (second is ExpressionContext) {
val expression = second.getChild(0)
if (expression is PrimaryExprContext) {
val typeDecl = expression.children.first().getChild(0)?.getChild(0)?.getChild(0)
if (typeDecl is GoParser.LiteralTypeContext) {
return typeDecl.getChild(0).text
if (typeDecl is GoParser.LiteralTypeContext && typeDecl.childCount > 0) {
return typeDecl.getChild(0)!!.text
}
}
}
Expand Down

0 comments on commit c825273

Please sign in to comment.