jmethod.go 1.6 KB
Newer Older
1
package jdomain
P
Phodal HUANG 已提交
2

P
Phodal Huang 已提交
3
import (
P
Phodal Huang 已提交
4
	"github.com/phodal/coca/pkg/domain/core_domain"
P
Phodal Huang 已提交
5
	"github.com/phodal/coca/pkg/infrastructure/string_helper"
P
Phodal Huang 已提交
6 7 8
	"strings"
)

P
Phodal HUANG 已提交
9 10
type JMethod struct {
	Name              string
P
Phodal HUANG 已提交
11
	Type              string
P
Phodal HUANG 已提交
12 13 14 15
	StartLine         int
	StartLinePosition int
	StopLine          int
	StopLinePosition  int
P
Phodal Huang 已提交
16
	Parameters        []core_domain.CodeProperty
17
	MethodCalls       []core_domain.CodeCall
18
	Override          bool
P
Phodal Huang 已提交
19
	Annotations       []core_domain.CodeAnnotation
20
	IsConstructor     bool
21
	IsReturnNull      bool
P
Phodal Huang 已提交
22
	Modifiers         []string
P
Phodal Huang 已提交
23
	Creators          []JClassNode
P
Phodal Huang 已提交
24 25
}

P
Phodal Huang 已提交
26
func NewJMethod() JMethod {
27
	return JMethod{}
P
Phodal HUANG 已提交
28
}
P
Phodal HUANG 已提交
29

30 31 32
type JMethodInfo struct {
	Name       string
	Type       string
P
Phodal Huang 已提交
33
	Parameters []core_domain.CodeProperty
34 35 36
	Length     string
}

37 38 39 40
func (m *JMethod) IsJavaLangReturnType() bool {
	return m.Type == "String" || m.Type == "int" || m.Type == "float" || m.Type == "void" || m.Type == "char" || m.Type == "double"
}

P
Phodal Huang 已提交
41
func (m *JMethod) IsStatic() bool {
P
Phodal Huang 已提交
42
	return string_helper.StringArrayContains(m.Modifiers, "static")
P
Phodal Huang 已提交
43 44 45 46 47 48
}

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

49
func (m *JMethod) BuildFullMethodName(node JClassNode) string {
50 51 52
	return node.Package + "." + node.Class + "." + m.Name
}

53 54 55 56
func (m *JMethod) GetAllCallString() []string {
	var calls []string
	for _, call := range m.MethodCalls {
		if call.Class != "" {
P
Phodal Huang 已提交
57
			calls = append(calls, call.BuildFullMethodName())
58 59 60
		}
	}
	return calls
P
Phodal HUANG 已提交
61
}
P
Phodal Huang 已提交
62 63 64 65 66 67 68 69 70 71

func (m *JMethod) IsJunitTest() bool {
	var isTest = false
	for _, annotation := range m.Annotations {
		if annotation.IsIgnoreOrTest() {
			isTest = true
		}
	}
	return isTest
}
72