From 1b511ee58fed5d18dc67d91a14919fcb41b85dce Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 25 Nov 2022 14:39:56 +0800 Subject: [PATCH] fix: fix tests --- .../kotlin/chapi/ast/javaast/JavaAnalyser.kt | 10 ++++---- .../chapi/ast/kotlinast/KotlinAnalyser.kt | 23 +++++++++++++++---- .../src/main/kotlin/chapi/parser/Analyser.kt | 6 ++--- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaAnalyser.kt b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaAnalyser.kt index 9f85bb10..772fece1 100644 --- a/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaAnalyser.kt +++ b/chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaAnalyser.kt @@ -4,17 +4,17 @@ import chapi.ast.antlr.JavaLexer import chapi.ast.antlr.JavaParser import chapi.domain.core.CodeDataStruct import chapi.domain.core.CodeContainer -import chapi.parser.AnalysisMode +import chapi.parser.ParseMode import chapi.parser.TwoStepAnalyser import org.antlr.v4.runtime.CharStreams import org.antlr.v4.runtime.CommonTokenStream import org.antlr.v4.runtime.tree.ParseTreeWalker open class JavaAnalyser : TwoStepAnalyser() { - override fun analysis(code: String, filePath: String, mode: AnalysisMode): CodeContainer { - return when (mode) { - AnalysisMode.Basic -> identFullInfo(code, filePath) - AnalysisMode.Full -> identBasicInfo(code, filePath) + override fun analysis(code: String, filePath: String, parseMode: ParseMode): CodeContainer { + return when (parseMode) { + ParseMode.Basic -> identFullInfo(code, filePath) + ParseMode.Full -> identBasicInfo(code, filePath) } } diff --git a/chapi-ast-kotlin/src/main/kotlin/chapi/ast/kotlinast/KotlinAnalyser.kt b/chapi-ast-kotlin/src/main/kotlin/chapi/ast/kotlinast/KotlinAnalyser.kt index 29e8c1e2..f3f3af1e 100644 --- a/chapi-ast-kotlin/src/main/kotlin/chapi/ast/kotlinast/KotlinAnalyser.kt +++ b/chapi-ast-kotlin/src/main/kotlin/chapi/ast/kotlinast/KotlinAnalyser.kt @@ -3,17 +3,30 @@ package chapi.ast.kotlinast import chapi.ast.antlr.KotlinLexer import chapi.ast.antlr.KotlinParser import chapi.domain.core.CodeContainer -import chapi.parser.AnalysisMode +import chapi.parser.ParseMode import chapi.parser.TwoStepAnalyser import org.antlr.v4.runtime.CharStreams import org.antlr.v4.runtime.CommonTokenStream import org.antlr.v4.runtime.tree.ParseTreeWalker +enum class AnalysisMode { + Basic, Full +} + +// a compatible api for Analyser +@Deprecated("use AnalysisMode move to Global instead", ReplaceWith("ParseMode")) +fun KotlinAnalyser.analysis(code: String, filePath: String, mode: AnalysisMode): CodeContainer { + return when (mode) { + AnalysisMode.Basic -> analysis(code, filePath, ParseMode.Basic) + AnalysisMode.Full -> analysis(code, filePath, ParseMode.Full) + } +} + class KotlinAnalyser: TwoStepAnalyser() { - override fun analysis(code: String, filePath: String, mode: AnalysisMode): CodeContainer { - val listener = when (mode) { - AnalysisMode.Basic -> KotlinBasicIdentListener(filePath) - AnalysisMode.Full -> KotlinFullIdentListener(filePath) + override fun analysis(code: String, filePath: String, parseMode: ParseMode): CodeContainer { + val listener = when (parseMode) { + ParseMode.Basic -> KotlinBasicIdentListener(filePath) + ParseMode.Full -> KotlinFullIdentListener(filePath) } val context = when (isKotlinScript(filePath)) { true -> this.parse(code).script() diff --git a/chapi-domain/src/main/kotlin/chapi/parser/Analyser.kt b/chapi-domain/src/main/kotlin/chapi/parser/Analyser.kt index 6bb229b7..e9c5de98 100644 --- a/chapi-domain/src/main/kotlin/chapi/parser/Analyser.kt +++ b/chapi-domain/src/main/kotlin/chapi/parser/Analyser.kt @@ -2,7 +2,7 @@ package chapi.parser import chapi.domain.core.CodeContainer -enum class AnalysisMode { +enum class ParseMode { Basic, Full } @@ -13,8 +13,8 @@ interface Analyser { abstract class TwoStepAnalyser : Analyser { override fun analysis(code: String, filePath: String): CodeContainer { - return this.analysis(code, filePath, AnalysisMode.Basic) + return this.analysis(code, filePath, ParseMode.Basic) } - abstract fun analysis(code: String, filePath: String, mode: AnalysisMode = AnalysisMode.Basic): CodeContainer + abstract fun analysis(code: String, filePath: String, parseMode: ParseMode = ParseMode.Basic): CodeContainer }