From feac3204304f32c2bcfd6540faa73c3983c4d08f Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 17 Apr 2022 17:37:23 +0800 Subject: [PATCH] fix(typescript): fix key issues for scan --- .../kotlinast/KotlinBasicIdentListenerTest.kt | 19 +++++++++++++++++++ .../TypeScriptFullIdentListener.kt | 2 +- .../TypeScriptFullIdentListenerTest.kt | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/chapi-ast-kotlin/src/test/kotlin/chapi/ast/kotlinast/KotlinBasicIdentListenerTest.kt b/chapi-ast-kotlin/src/test/kotlin/chapi/ast/kotlinast/KotlinBasicIdentListenerTest.kt index be1c0108..744a05f7 100644 --- a/chapi-ast-kotlin/src/test/kotlin/chapi/ast/kotlinast/KotlinBasicIdentListenerTest.kt +++ b/chapi-ast-kotlin/src/test/kotlin/chapi/ast/kotlinast/KotlinBasicIdentListenerTest.kt @@ -345,5 +345,24 @@ class Person(val name: String) : Human { } } } + + @Test + fun `should correct field bug`() { + val codeContainer = analyse(""" +@Repository +class RedundancyRepositoryImpl(val jdbi: Jdbi) : RedundancyRepository { + private val table = "select sum(1) sum, m.clzname as name, m.module as module " + + "from code_method m, code_class c, method_access ma, code_class_access ca " + + "where ca.class_id=c.id and ca.is_interface = false and ca.is_abstract = false " + + "and ma.method_id = m.id and m.name not like '%${'$'}%'" + + "and m.name != '' and m.name != 'main' and m.name != ''" + + "and m.name != 'toString' and m.name != 'equals' and m.name != 'hashCode' and m.name != 'clone'" + + "and m.clzname = c.name and c.module=m.module and c.is_thirdparty = false and c.is_test != true " + + "and m.system_id=:system_id and c.system_id=:system_id and ma.system_id=:system_id " + + "group by m.clzname, m.module having sum = 1" +} + """.trimIndent()) + assertEquals(2, codeContainer.DataStructures[0].Fields.size) + } } } diff --git a/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt b/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt index c7122394..fd286efd 100644 --- a/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt +++ b/chapi-ast-typescript/src/main/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListener.kt @@ -209,7 +209,7 @@ class TypeScriptFullIdentListener(node: TSIdentify) : TypeScriptAstListener() { } "PropertyDeclarationExpressionContext" -> { val ctx = childCtx as TypeScriptParser.PropertyDeclarationExpressionContext - val codeField = CodeField(TypeValue = ctx.propertyName().text) + val codeField = CodeField(TypeKey = ctx.propertyName().text) val modifier = ctx.propertyMemberBase().text if (modifier != "") { diff --git a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt index 43f57ff1..500a8851 100644 --- a/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt +++ b/chapi-ast-typescript/src/test/kotlin/chapi/ast/typescriptast/TypeScriptFullIdentListenerTest.kt @@ -349,7 +349,7 @@ import BadSmellThresholdTable from "./components/BadSmellThresholdTable"; val codeFile = TypeScriptAnalyser().analysis(personClassCode, "") assertEquals(codeFile.DataStructures[0].Fields.size, 5) assertEquals(codeFile.DataStructures[0].Fields[0].Modifiers[0], "public") - assertEquals(codeFile.DataStructures[0].Fields[0].TypeValue, "publicString") + assertEquals(codeFile.DataStructures[0].Fields[0].TypeKey, "publicString") assertEquals(codeFile.DataStructures[0].Fields[0].TypeType, "string") assertEquals(codeFile.DataStructures[0].Fields[1].TypeType, "string") assertEquals(codeFile.DataStructures[0].Fields[4].Modifiers.size, 0)