bs_node.go 1.7 KB
Newer Older
P
Phodal Huang 已提交
1 2 3
package bs_domain

import (
P
Phodal Huang 已提交
4
	"github.com/phodal/coca/pkg/domain/core_domain"
P
Phodal Huang 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
	"strings"
)

type BsJClass struct {
	Package     string
	Class       string
	Type        string
	Path        string
	Extends     string
	Implements  []string
	Methods     []BsJMethod
	MethodCalls []BsJMethodCall
	ClassBS     ClassBadSmellInfo
}

type BsJMethodCall struct {
P
Phodal Huang 已提交
21 22 23 24 25
	Package    string
	Type       string
	Class      string
	MethodName string
	Position   core_domain.CodePosition
P
Phodal Huang 已提交
26 27 28
}

type BsJMethod struct {
P
Phodal Huang 已提交
29 30 31 32
	Name       string
	Type       string
	MethodBody string
	Modifier   string
33
	Parameters []core_domain.CodeProperty
P
Phodal Huang 已提交
34 35
	MethodBs   MethodBadSmellInfo
	Position   core_domain.CodePosition
P
Phodal Huang 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
}

type MethodBadSmellInfo struct {
	IfSize     int
	SwitchSize int
	IfInfo     []IfParInfo
}

type IfParInfo struct {
	StartLine int
	EndLine   int
}

func NewIfPairInfo() IfParInfo {
	return IfParInfo{
		StartLine: 0,
		EndLine:   0,
	}
}

func NewMethodBadSmellInfo() MethodBadSmellInfo {
	return MethodBadSmellInfo{
		IfSize:     0,
		SwitchSize: 0,
		IfInfo:     nil,
	}
}

type ClassBadSmellInfo struct {
	OverrideSize  int
	PublicVarSize int
}

func NewJFullClassNode() BsJClass {
	info := &ClassBadSmellInfo{0, 0}
	return BsJClass{
		"",
		"",
		"",
		"",
		"",
		nil,
		nil,
		nil,
		*info}
}

func (b *BsJMethod) IsGetterSetter() bool {
	return strings.HasPrefix(b.Name, "set") || strings.HasPrefix(b.Name, "get")
}

func (b *BsJClass) HaveCallParent() bool {
	hasCallParentMethod := false
	for _, methodCall := range b.MethodCalls {
		if methodCall.Class == b.Extends {
			hasCallParentMethod = true
		}
	}
	return hasCallParentMethod
}

func (b *BsJClass) ClassFullName() string {
	return b.Package + "." + b.Class
}

func (c *BsJMethodCall) ClassFullName() string {
	return c.Package + "." + c.Class
}