@@ -27,87 +27,68 @@ type Function struct {
2727 identifier string
2828}
2929
30- func (f * Function ) Init () {
31- }
32-
33- func (f * Function ) WriteGoCode (cw * CodeWriter ) {
34- panic ("implement me" )
35- }
36-
37- // Copy for copy fetcher cache value
38- func (f * Function ) Copy () CodeGen {
39- if f == nil {
40- return nil
41- }
42- return & Function {
43- Type : f .Type ,
44- Name : f .Name ,
45- GoName : f .GoName ,
46- Params : f .Params ,
47- ReturnType : f .ReturnType ,
48- Deprecated : f .Deprecated ,
49- Suffix : f .Suffix ,
50- Description : f .Description ,
51- DocURL : f .DocURL ,
52- goFuncName : f .goFuncName ,
53- identifier : f .identifier ,
30+ // GoArgs return go function args
31+ func (f * Function ) GoArgs () string {
32+ var args []string
33+ for _ , p := range f .Params {
34+ args = append (args , p .GoName ())
5435 }
36+ return strings .Join (args , ", " )
5537}
5638
57- func ( m * Function ) needRelease () bool {
58- switch m . ReturnType .( type ) {
59- case * typing. PrimitiveType , * typing. StringType :
60- return false
39+ // GoReturn return go function return
40+ func ( f * Function ) GoReturn () string {
41+ if f . ReturnType == nil {
42+ return ""
6143 }
62- return strings .HasPrefix (m .Name , "new" ) || ! strings .HasPrefix (m .Name , "init" ) && strings .HasPrefix (m .Name , "Initial" ) ||
63- strings .HasPrefix (m .Name , "copy" ) || strings .HasPrefix (m .Name , "mutableCopy" )
44+ return f .ReturnType .GoName (nil , true )
6445}
6546
6647// Selector return full Objc function name
67- func (m * Function ) Selector () string {
68- if m .identifier == "" {
48+ func (f * Function ) Selector () string {
49+ if f .identifier == "" {
6950 var sb strings.Builder
70- sb .WriteString (m .Name )
71- for idx , p := range m .Params {
51+ sb .WriteString (f .Name )
52+ for idx , p := range f .Params {
7253 if idx > 0 {
7354 sb .WriteString (p .FieldName )
7455 }
7556 sb .WriteString (":" )
7657 }
77- m .identifier = sb .String ()
58+ f .identifier = sb .String ()
7859 }
79- return m .identifier
60+ return f .identifier
8061}
8162
82- func (m * Function ) String () string {
83- return m .Selector ()
63+ func (f * Function ) String () string {
64+ return f .Selector ()
8465}
8566
8667// NormalizeInstanceTypeFunction return new init function.
87- func (m * Function ) NormalizeInstanceTypeFunction (returnType * typing.ClassType ) * Function {
68+ func (f * Function ) NormalizeInstanceTypeFunction (returnType * typing.ClassType ) * Function {
8869 nm := & Function {
89- Name : m .Name ,
90- GoName : m .GoName ,
91- Params : m .Params ,
70+ Name : f .Name ,
71+ GoName : f .GoName ,
72+ Params : f .Params ,
9273 ReturnType : returnType ,
93- goFuncName : m .goFuncName ,
94- Suffix : m .Suffix ,
74+ goFuncName : f .goFuncName ,
75+ Suffix : f .Suffix ,
9576 }
9677 return nm
9778}
9879
9980// WriteGoCallCode generate go function code to call c wrapper code
100- func (m * Function ) WriteGoCallCode (currentModule * modules.Module , typeName string , cw * CodeWriter ) {
101- funcDeclare := m .GoFuncDeclare (currentModule , typeName )
81+ func (f * Function ) WriteGoCallCode (currentModule * modules.Module , typeName string , cw * CodeWriter ) {
82+ funcDeclare := f .GoFuncDeclare (currentModule , typeName )
10283
103- if m .Deprecated {
84+ if f .Deprecated {
10485 return
10586 cw .WriteLine ("// deprecated" )
10687 }
10788
108- if m .DocURL != "" {
109- cw .WriteLine (fmt .Sprintf ("// %s [Full Topic]" , m .Description ))
110- cw .WriteLine (fmt .Sprintf ("//\n // [Full Topic]: %s" , m .DocURL ))
89+ if f .DocURL != "" {
90+ cw .WriteLine (fmt .Sprintf ("// %s [Full Topic]" , f .Description ))
91+ cw .WriteLine (fmt .Sprintf ("//\n // [Full Topic]: %s" , f .DocURL ))
11192 }
11293
11394 var receiver string
@@ -117,16 +98,16 @@ func (m *Function) WriteGoCallCode(currentModule *modules.Module, typeName strin
11798 cw .Indent ()
11899
119100 var returnTypeStr string
120- rt := typing .UnwrapAlias (m .ReturnType )
101+ rt := typing .UnwrapAlias (f .ReturnType )
121102 switch rt .(type ) {
122103 case * typing.VoidType :
123104 returnTypeStr = "objc.Void"
124105 default :
125- returnTypeStr = m .ReturnType .GoName (currentModule , true )
106+ returnTypeStr = f .ReturnType .GoName (currentModule , true )
126107 }
127- callCode := fmt .Sprintf ("objc.Call[%s](%s, objc.Sel(\" %s\" )" , returnTypeStr , receiver , m .Selector ())
108+ callCode := fmt .Sprintf ("objc.Call[%s](%s, objc.Sel(\" %s\" )" , returnTypeStr , receiver , f .Selector ())
128109 var sb strings.Builder
129- for idx , p := range m .Params {
110+ for idx , p := range f .Params {
130111 sb .WriteString (", " )
131112 switch tt := p .Type .(type ) {
132113 case * typing.ClassType :
@@ -154,9 +135,6 @@ func (m *Function) WriteGoCallCode(currentModule *modules.Module, typeName strin
154135 default :
155136 var resultName = "rv"
156137 cw .WriteLine (resultName + " := " + callCode )
157- if m .needRelease () {
158- cw .WriteLine (resultName + ".Autorelease()" )
159- }
160138 cw .WriteLine ("return " + resultName )
161139 }
162140 cw .UnIndent ()
0 commit comments