diff --git a/pkg/domain/trial/code_call.go b/pkg/domain/core_domain/code_call.go similarity index 88% rename from pkg/domain/trial/code_call.go rename to pkg/domain/core_domain/code_call.go index 1b1047d3d86589afac74df439f028837dd3c64a9..2abf4baedbb066cce8678cd8f2e1b595ca06d39c 100644 --- a/pkg/domain/trial/code_call.go +++ b/pkg/domain/core_domain/code_call.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeCall struct { Package string diff --git a/pkg/domain/trial/code_data_struct.go b/pkg/domain/core_domain/code_data_struct.go similarity index 97% rename from pkg/domain/trial/code_data_struct.go rename to pkg/domain/core_domain/code_data_struct.go index e2d590176367031c587727d63f6dc05c16c61101..6c20a1b821958f43aa091d5ba7dde4be8f0e60cf 100644 --- a/pkg/domain/trial/code_data_struct.go +++ b/pkg/domain/core_domain/code_data_struct.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeDataStruct struct { Name string diff --git a/pkg/domain/trial/code_file.go b/pkg/domain/core_domain/code_file.go similarity index 94% rename from pkg/domain/trial/code_file.go rename to pkg/domain/core_domain/code_file.go index d24eb3304c2a434c67556f2b3962e8c459fbc099..4c63166f82a5aa178ec5ca5ec23b2a2bde525479 100644 --- a/pkg/domain/trial/code_file.go +++ b/pkg/domain/core_domain/code_file.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeFile struct { FullName string diff --git a/pkg/domain/trial/code_function.go b/pkg/domain/core_domain/code_function.go similarity index 96% rename from pkg/domain/trial/code_function.go rename to pkg/domain/core_domain/code_function.go index cb15c8a9f464feca3301683865fbf7bb17da1e90..5ebeef3e667581a550cff1a850c9a6c179edf08f 100644 --- a/pkg/domain/trial/code_function.go +++ b/pkg/domain/core_domain/code_function.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeFunction struct { Name string diff --git a/pkg/domain/trial/code_member.go b/pkg/domain/core_domain/code_member.go similarity index 93% rename from pkg/domain/trial/code_member.go rename to pkg/domain/core_domain/code_member.go index fd2dda8cb7f7b5459ceaccdaa13ef748965b2c06..7f1fbcd4e54a48b34814f7e8b77efb3e30155845 100644 --- a/pkg/domain/trial/code_member.go +++ b/pkg/domain/core_domain/code_member.go @@ -1,4 +1,4 @@ -package trial +package core_domain import "github.com/phodal/coca/pkg/domain" diff --git a/pkg/domain/trial/code_module.go b/pkg/domain/core_domain/code_module.go similarity index 72% rename from pkg/domain/trial/code_module.go rename to pkg/domain/core_domain/code_module.go index 514028cdbe8fea19015c6c2e260cfc2a809df11e..c2a27ba6103432d9f3be82a6f0cfc9a73370424e 100644 --- a/pkg/domain/trial/code_module.go +++ b/pkg/domain/core_domain/code_module.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeModule struct { Packages []CodePackage diff --git a/pkg/domain/trial/code_package.go b/pkg/domain/core_domain/code_package.go similarity index 81% rename from pkg/domain/trial/code_package.go rename to pkg/domain/core_domain/code_package.go index b69b3db5f60053c57483f0bd034c7d57b1f16139..c5db4d2419ae04ef8e9a4d60cf3e7fe92ca66278 100644 --- a/pkg/domain/trial/code_package.go +++ b/pkg/domain/core_domain/code_package.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodePackage struct { Name string diff --git a/pkg/domain/trial/code_position.go b/pkg/domain/core_domain/code_position.go similarity index 86% rename from pkg/domain/trial/code_position.go rename to pkg/domain/core_domain/code_position.go index 178c012867870f07b8ddbbd27ed2b6afac9709ac..0dc1cd734a9e533e11bc1326e655b86101f4721f 100644 --- a/pkg/domain/trial/code_position.go +++ b/pkg/domain/core_domain/code_position.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodePosition struct { StartLine int diff --git a/pkg/domain/trial/code_project.go b/pkg/domain/core_domain/code_project.go similarity index 71% rename from pkg/domain/trial/code_project.go rename to pkg/domain/core_domain/code_project.go index 4ca48c6a8d576353a4cfbfa597ece597f1a0656e..7a295e191527cc98c89ca4c3f1cd9e172a4efb72 100644 --- a/pkg/domain/trial/code_project.go +++ b/pkg/domain/core_domain/code_project.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeProject struct { Modules []CodeModule diff --git a/pkg/domain/trial/code_property.go b/pkg/domain/core_domain/code_property.go similarity index 89% rename from pkg/domain/trial/code_property.go rename to pkg/domain/core_domain/code_property.go index d5069f0ee80a38a1d04851e109af48b4c754959c..2fbcff467589bf5b5fe30c3b9dbd696f52915e61 100644 --- a/pkg/domain/trial/code_property.go +++ b/pkg/domain/core_domain/code_property.go @@ -1,4 +1,4 @@ -package trial +package core_domain type CodeProperty struct { Modifiers []string diff --git a/trial/cocago/cocago_builder.go b/trial/cocago/cocago_builder.go index 054bcc42a2d4e2f3789fdb0e1976611d3b0b7579..7eb73073952bc741d0d0956b224afabe27ee5bb4 100644 --- a/trial/cocago/cocago_builder.go +++ b/trial/cocago/cocago_builder.go @@ -2,16 +2,16 @@ package cocago import ( "fmt" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "go/ast" "reflect" ) -func BuildPropertyField(name string, field *ast.Field) *trial.CodeProperty { +func BuildPropertyField(name string, field *ast.Field) *core_domain.CodeProperty { var typeName string var typeType string - var params []trial.CodeProperty - var results []trial.CodeProperty + var params []core_domain.CodeProperty + var results []core_domain.CodeProperty switch x := field.Type.(type) { case *ast.Ident: typeType = "Identify" @@ -44,7 +44,7 @@ func BuildPropertyField(name string, field *ast.Field) *trial.CodeProperty { fmt.Fprintf(output, "BuildPropertyField %s\n", reflect.TypeOf(x)) } - property := &trial.CodeProperty{ + property := &core_domain.CodeProperty{ Modifiers: nil, Name: name, TypeType: typeType, @@ -71,8 +71,8 @@ func getStarExprName(starExpr ast.StarExpr) string { } } -func BuildFunction(x *ast.FuncDecl) *trial.CodeFunction { - codeFunc := &trial.CodeFunction{ +func BuildFunction(x *ast.FuncDecl) *core_domain.CodeFunction { + codeFunc := &core_domain.CodeFunction{ Name: x.Name.String(), } @@ -90,8 +90,8 @@ func BuildFunction(x *ast.FuncDecl) *trial.CodeFunction { return codeFunc } -func BuildFieldToProperty(fieldList []*ast.Field) []trial.CodeProperty { - var properties []trial.CodeProperty +func BuildFieldToProperty(fieldList []*ast.Field) []core_domain.CodeProperty { + var properties []core_domain.CodeProperty for _, field := range fieldList { property := BuildPropertyField(getFieldName(field), field) properties = append(properties, *property) diff --git a/trial/cocago/cocago_parser.go b/trial/cocago/cocago_parser.go index 3a7f1f9d53d6431660088533e750e23703f06002..76cac7186c077893eb592fd6717ca974e774a37c 100644 --- a/trial/cocago/cocago_parser.go +++ b/trial/cocago/cocago_parser.go @@ -3,7 +3,7 @@ package cocago import ( "bytes" "fmt" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "go/ast" "go/parser" "go/token" @@ -14,7 +14,7 @@ import ( "reflect" ) -var currentPackage *trial.CodePackage +var currentPackage *core_domain.CodePackage type CocagoParser struct { } @@ -23,7 +23,7 @@ var debug = false var output io.Writer func NewCocagoParser() *CocagoParser { - currentPackage = &trial.CodePackage{} + currentPackage = &core_domain.CodePackage{} output = os.Stdout return &CocagoParser{} } @@ -35,7 +35,7 @@ func (n *CocagoParser) SetOutput(isDebug bool) io.Writer { return output } -func (n *CocagoParser) ProcessFile(fileName string) trial.CodeFile { +func (n *CocagoParser) ProcessFile(fileName string) core_domain.CodeFile { absPath, _ := filepath.Abs(fileName) content, _ := ioutil.ReadFile(absPath) @@ -52,10 +52,10 @@ func (n *CocagoParser) ProcessFile(fileName string) trial.CodeFile { return *codeFile } -func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string) *trial.CodeFile { - var currentStruct trial.CodeDataStruct - var currentFile trial.CodeFile - var currentFunc *trial.CodeFunction +func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string) *core_domain.CodeFile { + var currentStruct core_domain.CodeDataStruct + var currentFile core_domain.CodeFile + var currentFunc *core_domain.CodeFunction currentFile.FullName = fileName var funcType = "" @@ -71,7 +71,7 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string imp := BuildImport(x) currentFile.Imports = append(currentFile.Imports, *imp) case *ast.TypeSpec: - currentStruct = trial.CodeDataStruct{} + currentStruct = core_domain.CodeDataStruct{} currentStruct.Name = x.Name.String() case *ast.StructType: AddStructType(currentStruct, x, ¤tFile) @@ -97,14 +97,14 @@ func (n *CocagoParser) Visitor(f *ast.File, fset *token.FileSet, fileName string return ¤tFile } -func BuildImport(x *ast.ImportSpec) *trial.CodeImport { +func BuildImport(x *ast.ImportSpec) *core_domain.CodeImport { path := x.Path.Value cleanPath := path[1 : len(path)-1] asName := "" if x.Name != nil { asName = x.Name.String() } - imp := &trial.CodeImport{ + imp := &core_domain.CodeImport{ Source: cleanPath, AsName: asName, ImportName: "", @@ -114,17 +114,17 @@ func BuildImport(x *ast.ImportSpec) *trial.CodeImport { return imp } -func AddInterface(x *ast.InterfaceType, ident string, codeFile *trial.CodeFile) { +func AddInterface(x *ast.InterfaceType, ident string, codeFile *core_domain.CodeFile) { properties := BuildFieldToProperty(x.Methods.List) - dataStruct := trial.CodeDataStruct{ + dataStruct := core_domain.CodeDataStruct{ Name: ident, ID: "", MemberIds: nil, InOutProperties: properties, } - member := trial.CodeMember{ + member := core_domain.CodeMember{ DataStructID: dataStruct.Name, Type: "interface", } @@ -133,11 +133,11 @@ func AddInterface(x *ast.InterfaceType, ident string, codeFile *trial.CodeFile) codeFile.DataStructures = append(codeFile.DataStructures, dataStruct) } -func AddNestedFunction(currentFunc *trial.CodeFunction, x *ast.FuncType) { +func AddNestedFunction(currentFunc *core_domain.CodeFunction, x *ast.FuncType) { } -func AddFunctionDecl(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, currentFile *trial.CodeFile) *trial.CodeFunction { +func AddFunctionDecl(currentStruct core_domain.CodeDataStruct, x *ast.FuncDecl, currentFile *core_domain.CodeFile) *core_domain.CodeFunction { recv := "" if x.Recv != nil { recv = BuildReceiver(x, recv) @@ -155,7 +155,7 @@ func AddFunctionDecl(currentStruct trial.CodeDataStruct, x *ast.FuncDecl, curren } else { member := GetMemberFromFile(*currentFile, "default") if member == nil { - member = &trial.CodeMember{ + member = &core_domain.CodeMember{ DataStructID: "default", Type: "method", } @@ -182,7 +182,7 @@ func BuildReceiver(x *ast.FuncDecl, recv string) string { return recv } -func BuildMethodCall(codeFunc *trial.CodeFunction, item ast.Stmt) { +func BuildMethodCall(codeFunc *core_domain.CodeFunction, item ast.Stmt) { switch it := item.(type) { case *ast.ExprStmt: BuildMethodCallExprStmt(it, codeFunc) @@ -191,11 +191,11 @@ func BuildMethodCall(codeFunc *trial.CodeFunction, item ast.Stmt) { } } -func BuildMethodCallExprStmt(it *ast.ExprStmt, codeFunc *trial.CodeFunction) { +func BuildMethodCallExprStmt(it *ast.ExprStmt, codeFunc *core_domain.CodeFunction) { switch expr := it.X.(type) { case *ast.CallExpr: selector, selName := BuildExpr(expr.Fun.(ast.Expr)) - call := trial.CodeCall{ + call := core_domain.CodeCall{ Package: "", Type: "", Class: selector, @@ -204,7 +204,7 @@ func BuildMethodCallExprStmt(it *ast.ExprStmt, codeFunc *trial.CodeFunction) { for _, arg := range expr.Args { value, kind := BuildExpr(arg.(ast.Expr)) - property := &trial.CodeProperty{ + property := &core_domain.CodeProperty{ TypeName: value, TypeType: kind, } @@ -241,12 +241,12 @@ func BuildExpr(expr ast.Expr) (string, string) { return "", "" } -func createMember(codeDataStruct trial.CodeDataStruct) { +func createMember(codeDataStruct core_domain.CodeDataStruct) { } -func GetMemberFromFile(file trial.CodeFile, recv string) *trial.CodeMember { - var identMember *trial.CodeMember +func GetMemberFromFile(file core_domain.CodeFile, recv string) *core_domain.CodeMember { + var identMember *core_domain.CodeMember for _, member := range file.Members { if member.DataStructID == recv { identMember = member @@ -262,8 +262,8 @@ func getFieldName(field *ast.Field) string { return field.Names[0].Name } -func AddStructType(currentStruct trial.CodeDataStruct, x *ast.StructType, currentFile *trial.CodeFile) { - member := trial.CodeMember{ +func AddStructType(currentStruct core_domain.CodeDataStruct, x *ast.StructType, currentFile *core_domain.CodeFile) { + member := core_domain.CodeMember{ DataStructID: currentStruct.Name, Type: "struct", } diff --git a/trial/pkg/application/processor/process.go b/trial/pkg/application/processor/process.go index 504ae527d655171c7db2d59e5e1095632f699604..61649599bb5779e960311d18113892e535ba965f 100644 --- a/trial/pkg/application/processor/process.go +++ b/trial/pkg/application/processor/process.go @@ -2,18 +2,18 @@ package processor import ( "github.com/phodal/coca/pkg/adapter/cocafile" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/cocago" "strings" ) -func ProcessPackage(path string, debug bool) []*trial.CodeFile { +func ProcessPackage(path string, debug bool) []*core_domain.CodeFile { var GoFileFilter = func(path string) bool { return strings.HasSuffix(path, ".go") } files := cocafile.GetFilesWithFilter(path, GoFileFilter) - filesData := make([]*trial.CodeFile, len(files)) + filesData := make([]*core_domain.CodeFile, len(files)) parser := cocago.NewCocagoParser() if debug { parser.SetOutput(true) diff --git a/trial/pkg/application/pyapp/py_ident_app.go b/trial/pkg/application/pyapp/py_ident_app.go index 9bd8b8f0639b82b06b2b8183b3fe815ad5145fa7..de92c5d27c19be8c8afd9453f40762b1dd9804a3 100644 --- a/trial/pkg/application/pyapp/py_ident_app.go +++ b/trial/pkg/application/pyapp/py_ident_app.go @@ -3,7 +3,7 @@ package pyapp import ( "github.com/antlr/antlr4/runtime/Go/antlr" parser "github.com/phodal/coca/languages/python" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/pkg/ast/pyast" ) @@ -21,7 +21,7 @@ func ProcessTsString(code string) *parser.PythonParser { type PythonApiApp struct { } -func (j *PythonApiApp) Analysis(code string, fileName string) *trial.CodeFile { +func (j *PythonApiApp) Analysis(code string, fileName string) *core_domain.CodeFile { scriptParser := ProcessTsString(code) context := scriptParser.Root() diff --git a/trial/pkg/application/pyapp/py_ident_app_test.go b/trial/pkg/application/pyapp/py_ident_app_test.go index c67cf66d920afc771d64244950bb28e29f8282a0..c87ae6c7f5831d779f7e548244177169063edd7e 100644 --- a/trial/pkg/application/pyapp/py_ident_app_test.go +++ b/trial/pkg/application/pyapp/py_ident_app_test.go @@ -4,7 +4,7 @@ import ( . "github.com/onsi/gomega" "github.com/phodal/coca/cocatest" "github.com/phodal/coca/pkg/adapter/cocafile" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "io/ioutil" "strings" "testing" @@ -84,10 +84,10 @@ func Test_PythonClassWithDecorator(t *testing.T) { codeFile := app.Analysis(string(file), "testdata/grammar/class_or_func_def_stmt.py") g.Expect(len(codeFile.DataStructures)).To(Equal(1)) - g.Expect(len(codeFile.DataStructures[0].Annotations.([]trial.PythonAnnotation))).To(Equal(1)) + g.Expect(len(codeFile.DataStructures[0].Annotations.([]core_domain.PythonAnnotation))).To(Equal(1)) g.Expect(codeFile.Members[0].FunctionNodes[0].Name).To(Equal("bar")) - g.Expect(len(codeFile.Members[0].FunctionNodes[0].Annotations.([]trial.PythonAnnotation))).To(Equal(2)) + g.Expect(len(codeFile.Members[0].FunctionNodes[0].Annotations.([]core_domain.PythonAnnotation))).To(Equal(2)) } func Test_PythonImport(t *testing.T) { diff --git a/trial/pkg/application/ts/ts_ident_app.go b/trial/pkg/application/ts/ts_ident_app.go index 33753aaf4a9b3cd839a5ee89e7ec730555983557..78c0256fc4c93e18cd7062893fd5788761eaa09d 100644 --- a/trial/pkg/application/ts/ts_ident_app.go +++ b/trial/pkg/application/ts/ts_ident_app.go @@ -3,7 +3,7 @@ package ts import ( "github.com/antlr/antlr4/runtime/Go/antlr" parser "github.com/phodal/coca/languages/ts" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/pkg/ast/ts" ) @@ -21,7 +21,7 @@ func ProcessTsString(code string) *parser.TypeScriptParser { type TypeScriptApiApp struct { } -func (j *TypeScriptApiApp) Analysis(code string, fileName string) trial.CodeFile { +func (j *TypeScriptApiApp) Analysis(code string, fileName string) core_domain.CodeFile { scriptParser := ProcessTsString(code) context := scriptParser.Program() diff --git a/trial/pkg/ast/ast_util/position.go b/trial/pkg/ast/ast_util/position.go index 4c581bffc6ce7b526981089728b77777e7ece9d1..8c3f054d47898682aecbdf2174c1c951e389a06f 100644 --- a/trial/pkg/ast/ast_util/position.go +++ b/trial/pkg/ast/ast_util/position.go @@ -3,7 +3,7 @@ package ast_util import ( "github.com/antlr/antlr4/runtime/Go/antlr" "github.com/phodal/coca/pkg/domain" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" ) func AddPosition(m *domain.JMethod, ctx *antlr.BaseParserRuleContext) { @@ -14,7 +14,7 @@ func AddPosition(m *domain.JMethod, ctx *antlr.BaseParserRuleContext) { } -func AddFunctionPosition(m *trial.CodeFunction, ctx *antlr.BaseParserRuleContext) { +func AddFunctionPosition(m *core_domain.CodeFunction, ctx *antlr.BaseParserRuleContext) { m.Position.StartLine = ctx.GetStart().GetLine() m.Position.StartLinePosition = ctx.GetStart().GetColumn() m.Position.StopLine = ctx.GetStop().GetLine() diff --git a/trial/pkg/ast/pyast/python_ident_listener.go b/trial/pkg/ast/pyast/python_ident_listener.go index 596c4a00c29b194ac4968b84ccf713e2338b9efe..c887b659b512b18a43721863c43fc2732765f266 100644 --- a/trial/pkg/ast/pyast/python_ident_listener.go +++ b/trial/pkg/ast/pyast/python_ident_listener.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/antlr/antlr4/runtime/Go/antlr" parser "github.com/phodal/coca/languages/python" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/pkg/ast/ast_util" "io" "os" @@ -15,14 +15,14 @@ type PythonIdentListener struct { parser.BasePythonParserListener } -var currentCodeFile *trial.CodeFile -var currentDataStruct *trial.CodeDataStruct +var currentCodeFile *core_domain.CodeFile +var currentDataStruct *core_domain.CodeDataStruct var debug = false var output io.Writer var hasEnterMember = false func NewPythonIdentListener(fileName string) *PythonIdentListener { - currentCodeFile = &trial.CodeFile{} + currentCodeFile = &core_domain.CodeFile{} currentCodeFile.FullName = fileName output = os.Stdout @@ -39,7 +39,7 @@ func (s *PythonIdentListener) SetDebugOutput(isDebug bool) io.Writer { func (s *PythonIdentListener) EnterImport_stmt(ctx *parser.Import_stmtContext) { dotNames := ctx.Dotted_as_names().(*parser.Dotted_as_namesContext).AllDotted_as_name() - codeImport := &trial.CodeImport{} + codeImport := &core_domain.CodeImport{} context := dotNames[0].(*parser.Dotted_as_nameContext) codeImport.Source = context.Dotted_name().GetText() if context.Name() != nil { @@ -55,7 +55,7 @@ func (s *PythonIdentListener) EnterImport_stmt(ctx *parser.Import_stmtContext) { } func (s *PythonIdentListener) EnterFrom_stmt(ctx *parser.From_stmtContext) { - codeImport := &trial.CodeImport{} + codeImport := &core_domain.CodeImport{} codeImport.Source = ctx.From_stmt_source().GetText() usageName := ctx.From_stmt_as_names().GetText() @@ -75,7 +75,7 @@ func (s *PythonIdentListener) EnterFrom_stmt(ctx *parser.From_stmtContext) { func (s *PythonIdentListener) EnterClassdef(ctx *parser.ClassdefContext) { hasEnterMember = true - dataStruct := &trial.CodeDataStruct{ + dataStruct := &core_domain.CodeDataStruct{ Name: ctx.Name().GetText(), ID: "", MemberIds: nil, @@ -99,7 +99,7 @@ func (s *PythonIdentListener) ExitClassdef(ctx *parser.ClassdefContext) { func (s *PythonIdentListener) EnterFuncdef(ctx *parser.FuncdefContext) { hasEnterMember = true - function := trial.CodeFunction{ + function := core_domain.CodeFunction{ Name: ctx.Name().GetText(), } @@ -109,7 +109,7 @@ func (s *PythonIdentListener) EnterFuncdef(ctx *parser.FuncdefContext) { function.Annotations = decorators } - member := &trial.CodeMember{ + member := &core_domain.CodeMember{ Name: ctx.Name().GetText(), } @@ -125,14 +125,14 @@ func (s *PythonIdentListener) ExitFuncdef(ctx *parser.FuncdefContext) { hasEnterMember = false } -func BuildDecoratorsByIndex(node antlr.ParseTree, index int) []trial.PythonAnnotation { +func BuildDecoratorsByIndex(node antlr.ParseTree, index int) []core_domain.PythonAnnotation { var nodes []parser.DecoratorContext for i := 0; i < index; i++ { context := node.GetParent().GetChild(i).(*parser.DecoratorContext) nodes = append(nodes, *context) } - var annotations []trial.PythonAnnotation + var annotations []core_domain.PythonAnnotation for _, node := range nodes { decorator := BuildDecorator(&node) annotations = append(annotations, *decorator) @@ -141,10 +141,10 @@ func BuildDecoratorsByIndex(node antlr.ParseTree, index int) []trial.PythonAnnot return annotations } -func BuildDecorator(x *parser.DecoratorContext) *trial.PythonAnnotation { +func BuildDecorator(x *parser.DecoratorContext) *core_domain.PythonAnnotation { text := x.Dotted_name().GetText() - annotation := &trial.PythonAnnotation{ + annotation := &core_domain.PythonAnnotation{ Name: text, } @@ -155,11 +155,11 @@ func BuildDecorator(x *parser.DecoratorContext) *trial.PythonAnnotation { return annotation } -func BuildArgList(context *parser.ArglistContext) []trial.CodeProperty { - var arguments []trial.CodeProperty +func BuildArgList(context *parser.ArglistContext) []core_domain.CodeProperty { + var arguments []core_domain.CodeProperty for _, arg := range context.AllArgument() { argContext := arg.(*parser.ArgumentContext) - argument := &trial.CodeProperty{ + argument := &core_domain.CodeProperty{ Name: "", TypeName: argContext.GetText(), } @@ -169,6 +169,6 @@ func BuildArgList(context *parser.ArglistContext) []trial.CodeProperty { return arguments } -func (s *PythonIdentListener) GetCodeFileInfo() *trial.CodeFile { +func (s *PythonIdentListener) GetCodeFileInfo() *core_domain.CodeFile { return currentCodeFile } diff --git a/trial/pkg/ast/ts/typescript_ident_converter.go b/trial/pkg/ast/ts/typescript_ident_converter.go index 8e3bcc2c2db5a16a210b3b7895cf9e44dc7eaf27..b4d1a219886f5ba190bc2981e382edfc14dcbc19 100644 --- a/trial/pkg/ast/ts/typescript_ident_converter.go +++ b/trial/pkg/ast/ts/typescript_ident_converter.go @@ -3,12 +3,12 @@ package ts import ( "github.com/antlr/antlr4/runtime/Go/antlr" "github.com/phodal/coca/languages/ts" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/pkg/ast/ast_util" ) -func BuildConstructorMethod(ctx *parser.ConstructorDeclarationContext) *trial.CodeFunction { - function := &trial.CodeFunction{ +func BuildConstructorMethod(ctx *parser.ConstructorDeclarationContext) *core_domain.CodeFunction { + function := &core_domain.CodeFunction{ Name: "constructor", } @@ -23,8 +23,8 @@ func BuildConstructorMethod(ctx *parser.ConstructorDeclarationContext) *trial.Co return function } -func BuildMemberMethod(ctx *parser.PropertyMemberDeclarationContext) *trial.CodeFunction { - function := &trial.CodeFunction{ +func BuildMemberMethod(ctx *parser.PropertyMemberDeclarationContext) *core_domain.CodeFunction { + function := &core_domain.CodeFunction{ Name: ctx.PropertyName().GetText(), } function.Position.StartLine = ctx.GetStart().GetLine() @@ -47,9 +47,9 @@ func BuildImplements(typeList parser.IClassOrInterfaceTypeListContext) []string return implements } -func BuildMethodParameter(context *parser.ParameterListContext) ([]trial.CodeProperty) { +func BuildMethodParameter(context *parser.ParameterListContext) ([]core_domain.CodeProperty) { childNode := context.GetChild(0) - var parameters []trial.CodeProperty = nil + var parameters []core_domain.CodeProperty = nil switch x := childNode.(type) { case *parser.RequiredParameterListContext: @@ -66,7 +66,7 @@ func BuildMethodParameter(context *parser.ParameterListContext) ([]trial.CodePro } case *parser.PredefinedTypeContext: predefinedTypeContext := x - parameter := trial.CodeProperty{ + parameter := core_domain.CodeProperty{ TypeName: "any", TypeType: predefinedTypeContext.GetText(), } @@ -76,13 +76,13 @@ func BuildMethodParameter(context *parser.ParameterListContext) ([]trial.CodePro return parameters } -func buildRestParameters(ctx *parser.RestParameterContext) trial.CodeProperty { +func buildRestParameters(ctx *parser.RestParameterContext) core_domain.CodeProperty { context := ctx.GetChild(1).(*parser.RequiredParameterContext) return buildRequiredParameter(context) } -func buildRequireParameterList(listContext *parser.RequiredParameterListContext) []trial.CodeProperty { - var requireCodeParams []trial.CodeProperty = nil +func buildRequireParameterList(listContext *parser.RequiredParameterListContext) []core_domain.CodeProperty { + var requireCodeParams []core_domain.CodeProperty = nil for _, requiredParameter := range listContext.AllRequiredParameter() { paramCtx := requiredParameter.(*parser.RequiredParameterContext) @@ -93,13 +93,13 @@ func buildRequireParameterList(listContext *parser.RequiredParameterListContext) return requireCodeParams } -func buildRequiredParameter(paramCtx *parser.RequiredParameterContext) trial.CodeProperty { +func buildRequiredParameter(paramCtx *parser.RequiredParameterContext) core_domain.CodeProperty { paramType := "" if paramCtx.TypeAnnotation() != nil { annotationContext := paramCtx.TypeAnnotation().(*parser.TypeAnnotationContext) paramType = BuildTypeAnnotation(annotationContext) } - parameter := trial.CodeProperty{ + parameter := core_domain.CodeProperty{ TypeName: paramCtx.IdentifierOrPattern().GetText(), TypeType: paramType, } diff --git a/trial/pkg/ast/ts/typescript_ident_listener.go b/trial/pkg/ast/ts/typescript_ident_listener.go index fac734d5e79f873cb5b351fb42467b01802c4f59..2fd8a828005dd447b1d11fb7fc169b89ccfcd7aa 100644 --- a/trial/pkg/ast/ts/typescript_ident_listener.go +++ b/trial/pkg/ast/ts/typescript_ident_listener.go @@ -4,7 +4,7 @@ import ( "github.com/antlr/antlr4/runtime/Go/antlr" parser "github.com/phodal/coca/languages/ts" "github.com/phodal/coca/pkg/domain" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/pkg/ast/ast_util" "strings" ) @@ -12,11 +12,11 @@ import ( var defaultClass = "default" type TypeScriptIdentListener struct { - currentDataStruct *trial.CodeDataStruct - dataStructures []trial.CodeDataStruct - dataStructQueue []trial.CodeDataStruct + currentDataStruct *core_domain.CodeDataStruct + dataStructures []core_domain.CodeDataStruct + dataStructQueue []core_domain.CodeDataStruct filePath string - codeFile trial.CodeFile + codeFile core_domain.CodeFile parser.BaseTypeScriptParserListener } @@ -27,11 +27,11 @@ func NewTypeScriptIdentListener(fileName string) *TypeScriptIdentListener { return listener } -func (s *TypeScriptIdentListener) GetNodeInfo() trial.CodeFile { +func (s *TypeScriptIdentListener) GetNodeInfo() core_domain.CodeFile { isScriptCalls := s.currentDataStruct != nil && s.currentDataStruct.IsNotEmpty() if isScriptCalls { if len(s.currentDataStruct.Functions) < 1 { - function := &trial.CodeFunction{} + function := &core_domain.CodeFunction{} function.Name = "default" function.MethodCalls = append(function.MethodCalls, s.currentDataStruct.FunctionCalls...) @@ -47,7 +47,7 @@ func (s *TypeScriptIdentListener) GetNodeInfo() trial.CodeFile { func (s *TypeScriptIdentListener) EnterImportFromBlock(ctx *parser.ImportFromBlockContext) { replaceSingleQuote := UpdateImportStr(ctx.StringLiteral().GetText()) - imp := &trial.CodeImport{Source: replaceSingleQuote} + imp := &core_domain.CodeImport{Source: replaceSingleQuote} importName := ctx.GetChild(0).(antlr.ParseTree).GetText() imp.ImportName = importName s.codeFile.Imports = append(s.codeFile.Imports, *imp) @@ -61,18 +61,18 @@ func UpdateImportStr(importText string) string { func (s *TypeScriptIdentListener) EnterImportAliasDeclaration(ctx *parser.ImportAliasDeclarationContext) { replaceSingleQuote := UpdateImportStr(ctx.StringLiteral().GetText()) - imp := &trial.CodeImport{Source: replaceSingleQuote} + imp := &core_domain.CodeImport{Source: replaceSingleQuote} s.codeFile.Imports = append(s.codeFile.Imports, *imp) } func (s *TypeScriptIdentListener) EnterImportAll(ctx *parser.ImportAllContext) { replaceSingleQuote := UpdateImportStr(ctx.StringLiteral().GetText()) - imp := &trial.CodeImport{Source: replaceSingleQuote} + imp := &core_domain.CodeImport{Source: replaceSingleQuote} s.codeFile.Imports = append(s.codeFile.Imports, *imp) } func (s *TypeScriptIdentListener) EnterInterfaceDeclaration(ctx *parser.InterfaceDeclarationContext) { - s.currentDataStruct = &trial.CodeDataStruct{ + s.currentDataStruct = &core_domain.CodeDataStruct{ Type: "Interface", Name: ctx.Identifier().GetText(), } @@ -93,7 +93,7 @@ func (s *TypeScriptIdentListener) EnterInterfaceDeclaration(ctx *parser.Interfac } } -func BuildInterfaceTypeBody(ctx *parser.TypeMemberListContext, dataStruct *trial.CodeDataStruct) { +func BuildInterfaceTypeBody(ctx *parser.TypeMemberListContext, dataStruct *core_domain.CodeDataStruct) { for _, typeMember := range ctx.AllTypeMember() { typeMemberCtx := typeMember.(*parser.TypeMemberContext) memberChild := typeMemberCtx.GetChild(0) @@ -104,7 +104,7 @@ func BuildInterfaceTypeBody(ctx *parser.TypeMemberListContext, dataStruct *trial method := domain.NewJMethod() method.Name = x.PropertyName().GetText() - function := trial.CodeFunction{ + function := core_domain.CodeFunction{ Name: x.PropertyName().GetText(), } @@ -115,21 +115,21 @@ func BuildInterfaceTypeBody(ctx *parser.TypeMemberListContext, dataStruct *trial } } -func BuildInterfacePropertySignature(signatureCtx *parser.PropertySignatureContext, dataStruct *trial.CodeDataStruct) { +func BuildInterfacePropertySignature(signatureCtx *parser.PropertySignatureContext, dataStruct *core_domain.CodeDataStruct) { typeType := BuildTypeAnnotation(signatureCtx.TypeAnnotation().(*parser.TypeAnnotationContext)) typeValue := signatureCtx.PropertyName().(*parser.PropertyNameContext).GetText() isArrowFunc := signatureCtx.Type_() != nil if isArrowFunc { - function := &trial.CodeFunction{ + function := &core_domain.CodeFunction{ Name: typeValue, } - param := trial.CodeProperty{ + param := core_domain.CodeProperty{ TypeName: "any", TypeType: typeType, } - returnType := trial.CodeProperty{ + returnType := core_domain.CodeProperty{ TypeType: signatureCtx.Type_().GetText(), } function.Parameters = append(function.Parameters, param) @@ -137,7 +137,7 @@ func BuildInterfacePropertySignature(signatureCtx *parser.PropertySignatureConte dataStruct.Functions = append(dataStruct.Functions, *function) } else { - codeField := &trial.CodeField{} + codeField := &core_domain.CodeField{} codeField.TypeType = typeType codeField.TypeValue = typeValue @@ -150,7 +150,7 @@ func (s *TypeScriptIdentListener) ExitInterfaceDeclaration(ctx *parser.Interface } func (s *TypeScriptIdentListener) EnterClassDeclaration(ctx *parser.ClassDeclarationContext) { - s.currentDataStruct = &trial.CodeDataStruct{ + s.currentDataStruct = &core_domain.CodeDataStruct{ Type: "Class", Name: ctx.Identifier().GetText(), } @@ -189,11 +189,11 @@ func (s *TypeScriptIdentListener) handleClassBodyElements(classTailContext *pars } } -func (s *TypeScriptIdentListener) HandlePropertyMember(propertyMemberCtx *parser.PropertyMemberDeclarationContext, dataStruct *trial.CodeDataStruct) { +func (s *TypeScriptIdentListener) HandlePropertyMember(propertyMemberCtx *parser.PropertyMemberDeclarationContext, dataStruct *core_domain.CodeDataStruct) { callSignatureSizePos := 3 if propertyMemberCtx.PropertyName() != nil { modifier := propertyMemberCtx.PropertyMemberBase().GetText() - codeField := trial.CodeField{ + codeField := core_domain.CodeField{ TypeValue: propertyMemberCtx.PropertyName().GetText(), } codeField.Modifiers = append(codeField.Modifiers, modifier) @@ -224,12 +224,12 @@ func (s *TypeScriptIdentListener) exitClass() { s.dataStructQueue = s.dataStructQueue[0 : len(s.dataStructQueue)-1] s.currentDataStruct = &s.dataStructQueue[len(s.dataStructQueue)-1] } else { - s.currentDataStruct = trial.NewDataStruct() + s.currentDataStruct = core_domain.NewDataStruct() } } func (s *TypeScriptIdentListener) EnterFunctionDeclaration(ctx *parser.FunctionDeclarationContext) { - function := &trial.CodeFunction{ + function := &core_domain.CodeFunction{ Name: ctx.Identifier().GetText(), } @@ -239,12 +239,12 @@ func (s *TypeScriptIdentListener) EnterFunctionDeclaration(ctx *parser.FunctionD ast_util.AddFunctionPosition(function, ctx.GetChild(0).GetParent().(*antlr.BaseParserRuleContext)) if s.currentDataStruct == nil { - s.currentDataStruct = &trial.CodeDataStruct{} + s.currentDataStruct = &core_domain.CodeDataStruct{} } s.currentDataStruct.Functions = append(s.currentDataStruct.Functions, *function) } -func FillMethodFromCallSignature(callSignatureContext *parser.CallSignatureContext, function *trial.CodeFunction) { +func FillMethodFromCallSignature(callSignatureContext *parser.CallSignatureContext, function *core_domain.CodeFunction) { if callSignatureContext.ParameterList() != nil { parameterListContext := callSignatureContext.ParameterList().(*parser.ParameterListContext) functionParameters := BuildMethodParameter(parameterListContext) diff --git a/trial/tcmd/analysis_go.go b/trial/tcmd/analysis_go.go index 7c8e7c9abc1ab677c427bada352f594e00ef483a..555eb54578c54ba008da6cdb53ca39c0cb0feba7 100644 --- a/trial/tcmd/analysis_go.go +++ b/trial/tcmd/analysis_go.go @@ -4,7 +4,7 @@ import ( "encoding/json" "github.com/phodal/coca/cmd/cmd_util" "github.com/phodal/coca/pkg/adapter/cocafile" - "github.com/phodal/coca/pkg/domain/trial" + "github.com/phodal/coca/pkg/domain/core_domain" "github.com/phodal/coca/trial/cocago" "github.com/spf13/cobra" ) @@ -24,7 +24,7 @@ var analysisGoCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { importPath := analysisGoCmdConfig.Path - var results []trial.CodeFile + var results []core_domain.CodeFile files := cocafile.GetFilesWithFilter(importPath, cocafile.GoFileFilter) for _, file := range files { parser := cocago.NewCocagoParser()