Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 25, 2022
1 parent 6ac7fbd commit 1b511ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
10 changes: 5 additions & 5 deletions chapi-ast-java/src/main/kotlin/chapi/ast/javaast/JavaAnalyser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions chapi-domain/src/main/kotlin/chapi/parser/Analyser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package chapi.parser

import chapi.domain.core.CodeContainer

enum class AnalysisMode {
enum class ParseMode {
Basic, Full
}

Expand All @@ -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
}

0 comments on commit 1b511ee

Please sign in to comment.