Skip to content

Commit 51eaa28

Browse files
authored
fix: <java> #20,incorrect TypeValue and TypeKey (#21)
1 parent 9766ba0 commit 51eaa28

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaFullIdentListener.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,12 @@ open class JavaFullIdentListener(fileName: String, val classes: Array<String>) :
531531
}
532532

533533
val typeTypeText = typeCtx.identifier(0).text
534-
val typeValue = declCtx.variableDeclaratorId().identifier().text
535-
fieldsMap[typeValue] = typeTypeText
534+
val typeKey = declCtx.variableDeclaratorId().identifier().text
535+
val typeValue = declCtx.variableInitializer()?.text ?: ""
536+
537+
fieldsMap[typeKey] = typeTypeText
536538

537-
val field = CodeField(typeTypeText, typeValue, Modifiers = arrayOf(), Annotations = this.currentAnnotations)
539+
val field = CodeField(typeTypeText, typeValue, typeKey, Modifiers = arrayOf(), Annotations = this.currentAnnotations)
538540
fields += field
539541

540542
buildFieldCall(typeTypeText, ctx)

chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaFullIdentListenerTest.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ package hello;
113113
114114
public class JavaCallApp {
115115
private JavaDaoParser daoParser;
116+
private String name = "abc";
116117
117118
public daoCall() {
118119
daoParser.Call();
@@ -123,9 +124,13 @@ public class JavaCallApp {
123124
val codeFile = JavaAnalyser().identFullInfo(code, "")
124125
println(codeFile.DataStructures[0].Fields.size)
125126

126-
assertEquals(codeFile.DataStructures[0].Fields.size, 1)
127+
assertEquals(codeFile.DataStructures[0].Fields.size, 2)
127128
assertEquals(codeFile.DataStructures[0].Fields[0].TypeType, "JavaDaoParser")
128-
assertEquals(codeFile.DataStructures[0].Fields[0].TypeValue, "daoParser")
129+
assertEquals(codeFile.DataStructures[0].Fields[0].TypeKey, "daoParser")
130+
131+
assertEquals(codeFile.DataStructures[0].Fields[1].TypeType, "String")
132+
assertEquals(codeFile.DataStructures[0].Fields[1].TypeKey, "name")
133+
assertEquals(codeFile.DataStructures[0].Fields[1].TypeValue, "\"abc\"")
129134
}
130135

131136
@Test

0 commit comments

Comments
 (0)