diff --git a/pkg/internal/lang/go/dump_source.go b/pkg/internal/lang/go/dump_source.go index b17f81b..aea22d0 100644 --- a/pkg/internal/lang/go/dump_source.go +++ b/pkg/internal/lang/go/dump_source.go @@ -2,7 +2,7 @@ package ddlctlgo import ( "bytes" - goast "go/ast" + "go/ast" "go/token" "io" @@ -16,19 +16,19 @@ func dumpDDLSource(fset *token.FileSet, ddlSrc []*ddlSource) { logs.Trace.Print("-- CommentGroup --------------------------------------------------------------------------------------------------------------------------------") { commentGroupAST := bytes.NewBuffer(nil) - goast.Fprint(commentGroupAST, fset, r.CommentGroup, goast.NotNilFilter) + ast.Fprint(commentGroupAST, fset, r.CommentGroup, ast.NotNilFilter) _, _ = logs.Trace.LineWriter("").Write(commentGroupAST.Bytes()) } logs.Trace.Print("-- TypeSpec --------------------------------------------------------------------------------------------------------------------------------") { typeSpecAST := bytes.NewBuffer(nil) - goast.Fprint(typeSpecAST, fset, r.TypeSpec, goast.NotNilFilter) + ast.Fprint(typeSpecAST, fset, r.TypeSpec, ast.NotNilFilter) _, _ = logs.Trace.LineWriter("").Write(typeSpecAST.Bytes()) } logs.Trace.Print("-- StructType --------------------------------------------------------------------------------------------------------------------------------") { structTypeAST := bytes.NewBuffer(nil) - goast.Fprint(structTypeAST, fset, r.StructType, goast.NotNilFilter) + ast.Fprint(structTypeAST, fset, r.StructType, ast.NotNilFilter) _, _ = logs.Trace.LineWriter("").Write(structTypeAST.Bytes()) } } diff --git a/pkg/internal/lang/go/extract_source.go b/pkg/internal/lang/go/extract_source.go index 9582262..92af228 100644 --- a/pkg/internal/lang/go/extract_source.go +++ b/pkg/internal/lang/go/extract_source.go @@ -3,7 +3,7 @@ package ddlctlgo import ( "context" "fmt" - goast "go/ast" + "go/ast" "go/token" "regexp" "sync" @@ -18,10 +18,10 @@ import ( type ddlSource struct { Position token.Position // TypeSpec is used to guess the table name if the CREATE TABLE annotation is not found. - TypeSpec *goast.TypeSpec + TypeSpec *ast.TypeSpec // StructType is used to determine the column name. If the tag specified by --go-column-tag is not found, the field name is used. - StructType *goast.StructType - CommentGroup *goast.CommentGroup + StructType *ast.StructType + CommentGroup *ast.CommentGroup } //nolint:gochecknoglobals @@ -47,10 +47,10 @@ func DDLTagGoCommentLineRegex() *regexp.Regexp { // //nolint:cyclop -func extractDDLSourceFromDDLTagGo(_ context.Context, fset *token.FileSet, f *goast.File) ([]*ddlSource, error) { +func extractDDLSourceFromDDLTagGo(_ context.Context, fset *token.FileSet, f *ast.File) ([]*ddlSource, error) { ddlSrc := make([]*ddlSource, 0) - for commentedNode, commentGroups := range goast.NewCommentMap(fset, f, f.Comments) { + for commentedNode, commentGroups := range ast.NewCommentMap(fset, f, f.Comments) { for _, commentGroup := range commentGroups { CommentGroupLoop: for _, commentLine := range commentGroup.List { @@ -61,12 +61,12 @@ func extractDDLSourceFromDDLTagGo(_ context.Context, fset *token.FileSet, f *goa Position: fset.Position(commentLine.Pos()), CommentGroup: commentGroup, } - goast.Inspect(commentedNode, func(node goast.Node) bool { + ast.Inspect(commentedNode, func(node ast.Node) bool { switch n := node.(type) { - case *goast.TypeSpec: + case *ast.TypeSpec: s.TypeSpec = n switch t := n.Type.(type) { - case *goast.StructType: + case *ast.StructType: s.StructType = t return false default: // noop diff --git a/pkg/internal/lang/go/parse.go b/pkg/internal/lang/go/parse.go index 316fd7f..71ff2a9 100644 --- a/pkg/internal/lang/go/parse.go +++ b/pkg/internal/lang/go/parse.go @@ -19,7 +19,7 @@ import ( apperr "github.com/kunitsucom/ddlctl/pkg/apperr" "github.com/kunitsucom/ddlctl/pkg/internal/config" - ddlast "github.com/kunitsucom/ddlctl/pkg/internal/generator" + "github.com/kunitsucom/ddlctl/pkg/internal/generator" langutil "github.com/kunitsucom/ddlctl/pkg/internal/lang/util" "github.com/kunitsucom/ddlctl/pkg/internal/util" "github.com/kunitsucom/ddlctl/pkg/logs" @@ -31,7 +31,7 @@ const ( ) //nolint:cyclop -func Parse(ctx context.Context, src string) (*ddlast.DDL, error) { +func Parse(ctx context.Context, src string) (*generator.DDL, error) { // MEMO: get absolute path for parser.ParseFile() sourceAbs := util.Abs(src) @@ -40,7 +40,7 @@ func Parse(ctx context.Context, src string) (*ddlast.DDL, error) { return nil, apperr.Errorf("os.Stat: %w", err) } - ddl := ddlast.NewDDL(ctx) + ddl := generator.NewDDL(ctx) if info.IsDir() { if err := filepath.WalkDir(sourceAbs, walkDirFn(ctx, ddl)); err != nil { @@ -62,7 +62,7 @@ func Parse(ctx context.Context, src string) (*ddlast.DDL, error) { //nolint:gochecknoglobals var fileSuffix = ".go" -func walkDirFn(ctx context.Context, ddl *ddlast.DDL) func(path string, d os.DirEntry, err error) error { +func walkDirFn(ctx context.Context, ddl *generator.DDL) func(path string, d os.DirEntry, err error) error { return func(path string, d os.DirEntry, err error) error { if err != nil { return err //nolint:wrapcheck @@ -88,7 +88,7 @@ func walkDirFn(ctx context.Context, ddl *ddlast.DDL) func(path string, d os.DirE } //nolint:cyclop,funlen,gocognit -func parseFile(ctx context.Context, filename string) ([]ddlast.Stmt, error) { +func parseFile(ctx context.Context, filename string) ([]generator.Stmt, error) { fset := token.NewFileSet() f, err := parser.ParseFile(fset, filename, nil, parser.ParseComments) if err != nil { @@ -102,9 +102,9 @@ func parseFile(ctx context.Context, filename string) ([]ddlast.Stmt, error) { dumpDDLSource(fset, ddlSrc) - stmts := make([]ddlast.Stmt, 0) + stmts := make([]generator.Stmt, 0) for _, r := range ddlSrc { - createTableStmt := &ddlast.CreateTableStmt{} + createTableStmt := &generator.CreateTableStmt{} // source createTableStmt.SourceFile = r.Position.Filename @@ -121,7 +121,7 @@ func parseFile(ctx context.Context, filename string) ([]ddlast.Stmt, error) { if /* CREATE INDEX */ matches := langutil.StmtRegexCreateIndex.Regex.FindStringSubmatch(comment); len(matches) > langutil.StmtRegexCreateIndex.Index { commentMatchedCreateIndex := comment source := fset.Position(extractContainingCommentFromCommentGroup(r.CommentGroup, commentMatchedCreateIndex).Pos()) - createIndexStmt := &ddlast.CreateIndexStmt{ + createIndexStmt := &generator.CreateIndexStmt{ Comments: []string{commentMatchedCreateIndex}, SourceFile: source.Filename, SourceLine: source.Line, @@ -134,11 +134,11 @@ func parseFile(ctx context.Context, filename string) ([]ddlast.Stmt, error) { if /* CREATE TABLE */ matches := langutil.StmtRegexCreateTable.Regex.FindStringSubmatch(comment); len(matches) > langutil.StmtRegexCreateTable.Index { createTableStmt.SetCreateTable(matches[langutil.StmtRegexCreateTable.Index]) } else if /* CONSTRAINT */ matches := langutil.StmtRegexCreateTableConstraint.Regex.FindStringSubmatch(comment); len(matches) > langutil.StmtRegexCreateTableConstraint.Index { - createTableStmt.Constraints = append(createTableStmt.Constraints, &ddlast.CreateTableConstraint{ + createTableStmt.Constraints = append(createTableStmt.Constraints, &generator.CreateTableConstraint{ Constraint: matches[langutil.StmtRegexCreateTableConstraint.Index], }) } else if /* OPTIONS */ matches := langutil.StmtRegexCreateTableOptions.Regex.FindStringSubmatch(comment); len(matches) > langutil.StmtRegexCreateTableOptions.Index { - createTableStmt.Options = append(createTableStmt.Options, &ddlast.CreateTableOption{ + createTableStmt.Options = append(createTableStmt.Options, &generator.CreateTableOption{ Option: matches[langutil.StmtRegexCreateTableOptions.Index], }) } @@ -157,7 +157,7 @@ func parseFile(ctx context.Context, filename string) ([]ddlast.Stmt, error) { // columns if r.StructType != nil { for _, field := range r.StructType.Fields.List { - column := &ddlast.CreateTableColumn{} + column := &generator.CreateTableColumn{} tag := reflect.StructTag(strings.Trim(field.Tag.Value, "`")) diff --git a/pkg/internal/lang/go/parse_test.go b/pkg/internal/lang/go/parse_test.go index 077997c..821fba8 100644 --- a/pkg/internal/lang/go/parse_test.go +++ b/pkg/internal/lang/go/parse_test.go @@ -15,7 +15,7 @@ import ( "github.com/kunitsucom/ddlctl/pkg/apperr" "github.com/kunitsucom/ddlctl/pkg/internal/config" "github.com/kunitsucom/ddlctl/pkg/internal/fixture" - ddlast "github.com/kunitsucom/ddlctl/pkg/internal/generator" + "github.com/kunitsucom/ddlctl/pkg/internal/generator" ) //nolint:paralleltest @@ -226,7 +226,7 @@ func Test_walkDirFn(t *testing.T) { require.NoError(t, err) } - ddl := ddlast.NewDDL(ctx) + ddl := generator.NewDDL(ctx) fn := walkDirFn(ctx, ddl) { err := fn("", nil, os.ErrPermission)