From 457f577801d6f5b1368648edc389506dbe9c00ed Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 12 Jan 2020 23:30:55 +0800 Subject: [PATCH] refactor: refactor switch type to make clean code --- pkg/infrastructure/ast/full/java_full_listener.go | 13 ++++++++----- trial/pkg/ast/ts/typescript_ident_listener.go | 4 ---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/infrastructure/ast/full/java_full_listener.go b/pkg/infrastructure/ast/full/java_full_listener.go index 77d10df..a8125f1 100644 --- a/pkg/infrastructure/ast/full/java_full_listener.go +++ b/pkg/infrastructure/ast/full/java_full_listener.go @@ -2,9 +2,9 @@ package full import ( "github.com/antlr/antlr4/runtime/Go/antlr" + "github.com/phodal/coca/languages/java" "github.com/phodal/coca/pkg/domain" common_listener2 "github.com/phodal/coca/pkg/infrastructure/ast/common_listener" - "github.com/phodal/coca/languages/java" "reflect" "strconv" "strings" @@ -613,10 +613,13 @@ func buildMethodNameForBuilder(ctx *parser.MethodCallContext, targetType string) func getTargetFromVarDecl(varParent antlr.Tree, targetType string) string { varDeclParent := varParent.(*parser.VariableDeclaratorContext).GetParent() - if reflect.TypeOf(varDeclParent).String() == "*parser.VariableDeclaratorsContext" { - parent := varDeclParent.(*parser.VariableDeclaratorsContext).GetParent() - if reflect.TypeOf(parent).String() == "*parser.LocalVariableDeclarationContext" { - targetType = parent.(*parser.LocalVariableDeclarationContext).TypeType().GetText() + switch x := varDeclParent.(type) { + case *parser.VariableDeclaratorsContext: + switch parentType := x.GetParent().(type) { + case *parser.LocalVariableDeclarationContext: + { + targetType = parentType.TypeType().GetText() + } } } return targetType diff --git a/trial/pkg/ast/ts/typescript_ident_listener.go b/trial/pkg/ast/ts/typescript_ident_listener.go index 05202dc..9b90702 100644 --- a/trial/pkg/ast/ts/typescript_ident_listener.go +++ b/trial/pkg/ast/ts/typescript_ident_listener.go @@ -221,10 +221,6 @@ func (s *TypeScriptIdentListener) EnterMemberDotExpression(ctx *parser.MemberDot } -func (s *TypeScriptIdentListener) EnterFunctionExpressionDeclaration(ctx *parser.FunctionExpressionDeclarationContext) { - -} - func (s *TypeScriptIdentListener) EnterFunctionDeclaration(ctx *parser.FunctionDeclarationContext) { method := domain.NewJMethod() -- GitLab