From f4ba9e7e8f8e61a571d1eb6d6ca533dea9f289a0 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 4 Feb 2020 13:06:18 +0800 Subject: [PATCH] feat: add implment api supportt --- .../chapi/ast/javaast/JavaIdentListener.kt | 11 +++++++---- .../kotlin/chapi/ast/javaast/JavaIdentAppTest.kt | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt index bfbcb62f..4fab5bbc 100644 --- a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt +++ b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaIdentListener.kt @@ -62,8 +62,7 @@ class JavaIdentListener(fileName: String) : JavaParserBaseListener() { if (ctx.IMPLEMENTS() != null) { for (_type in ctx.typeList().typeType()) { - val typeText = _type.text - this.buildImplement(typeText) + this.buildImplement(_type.text) } } @@ -153,8 +152,12 @@ class JavaIdentListener(fileName: String) : JavaParserBaseListener() { return codeFile.PackageName + "." + currentClz + "." + name + ":" + function.Position.StartLine.toString() } - private fun buildImplement(typeText: String?) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + private fun buildImplement(typeText: String) { + var target = this.warpTargetFullType(typeText) + if (target == "") { + target = typeText + } + currentNode.Implements += target } private fun buildExtend(extendName: String) { diff --git a/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentAppTest.kt b/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentAppTest.kt index 9ff6f15e..4fb828ba 100644 --- a/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentAppTest.kt +++ b/chapi-ast-java/src/test/kotlin/chapi/ast/javaast/JavaIdentAppTest.kt @@ -95,6 +95,22 @@ public class HelloWorld { assertEquals(codeFile.DataStructures[0].Extend, "HasStatic") } + @Test + internal fun shouldGetImplementName() { + val code = """ +class Pig implements Animal { + public void animalSound() { + System.out.println("The pig says: wee wee"); + } + public void sleep() { + System.out.println("Zzz"); + } +} +""" + val codeFile = JavaIdentApp().analysis(code, "") + assertEquals(codeFile.DataStructures[0].Implements[0], "Animal") + } + @Test internal fun shouldGetInnerStructureName() { val code = """