From ebeb90365350ce9aa6021b2105f6d615bd70e7a7 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 1 Jan 2024 15:34:04 +0800 Subject: [PATCH] Revert "refactor(rust): simplify logic" This reverts commit 1486098038c55607dbbc3bbd0db14033b8f38067. --- .../main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt b/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt index 85d519a7..45206969 100644 --- a/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt +++ b/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt @@ -4,6 +4,7 @@ import chapi.ast.antlr.RustParser import chapi.ast.antlr.RustParser.ItemContext import chapi.ast.antlr.RustParser.SimplePathContext import chapi.ast.antlr.RustParser.TypePathSegmentContext +import chapi.ast.antlr.RustParser.Type_Context import chapi.ast.antlr.RustParserBaseListener import chapi.domain.core.* import org.antlr.v4.runtime.ParserRuleContext @@ -161,13 +162,18 @@ open class RustAstBaseListener(private val fileName: String) : RustParserBaseLis private fun buildFields(structFields: RustParser.StructFieldsContext?): List { return structFields?.structField()?.map { CodeField( - TypeType = lookupByType(it.type_()?.text), + TypeType = lookupType(it.type_()), Annotations = buildAttribute(it.outerAttribute()), TypeValue = it.identifier()?.text ?: "", ) } ?: emptyList() } + private fun lookupType(type_: Type_Context?): String { + val typeText = type_?.text + return lookupByType(typeText) + } + open fun lookupByType(typeText: String?): String { if (typeText == null) return "" val text = if (typeText.contains("::")) {