-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.go
42 lines (33 loc) · 1.03 KB
/
processor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ellyn_ast
import (
"github.com/lvyahui8/ellyn/ellyn_common/log"
"github.com/lvyahui8/ellyn/ellyn_common/utils"
"io/fs"
"os"
"strings"
)
type Processor interface {
FilterPackage(progCtx *ProgramContext, pkg Package) bool
FilterFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo) bool
HandleFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo, content []byte)
}
type DefaultProcessor struct {
}
func (d DefaultProcessor) FilterPackage(progCtx *ProgramContext, pkg Package) bool {
return strings.HasPrefix(pkg.Path, progCtx.RootPkgPath())
}
func (d DefaultProcessor) FilterFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo) bool {
if file.IsDir() {
return false
}
if utils.Go.IsTestFile(file.Name()) {
return false
}
if utils.Go.IsAutoGenFile(pkg.Dir + string(os.PathSeparator) + file.Name()) {
return false
}
return true
}
func (d DefaultProcessor) HandleFile(progCtx *ProgramContext, pkg Package, file fs.FileInfo, content []byte) {
log.Infof("dir %s,file %s", pkg.Dir, file.Name())
}