Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: mojom/generators/go/templates/interfaces.go

Issue 2077113002: Handle interfaces with a ServiceName in the go bindings generator. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix names issue. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojom/generators/go/templates/interfaces_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package templates 5 package templates
6 6
7 import ( 7 import (
8 "text/template" 8 "text/template"
9 ) 9 )
10 10
11 const interfaceTmplText = ` 11 const interfaceTmplText = `
12 {{- define "Interface" -}} 12 {{- define "Interface" -}}
13 {{$interface := . -}} 13 {{$interface := . -}}
14 {{ template "InterfaceDecl" $interface }} 14 {{ template "InterfaceDecl" $interface }}
15
16 {{- range $method := $interface.Methods -}}
17 {{ template "Method" $method }}
18 {{- end -}}
19
20 {{- if $interface.ServiceName -}}
21 {{ template "ServiceDecl" $interface }}
22 {{- end -}}
15 {{- end -}} 23 {{- end -}}
16 ` 24 `
17 25
18 const interfaceDeclTmplText = ` 26 const interfaceDeclTmplText = `
19 {{- define "InterfaceDecl" -}} 27 {{- define "InterfaceDecl" -}}
20 {{- $interface := . -}} 28 {{- $interface := . -}}
21 {{ template "InterfaceInterfaceDecl" $interface }} 29 {{ template "InterfaceInterfaceDecl" $interface }}
22 30
23 {{ template "InterfaceOtherDecl" $interface }} 31 {{ template "InterfaceOtherDecl" $interface }}
24 32
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 bindings.NewCounter(), 88 bindings.NewCounter(),
81 } 89 }
82 } 90 }
83 91
84 func (p *{{$interface.Name}}_Proxy) Close_Proxy() { 92 func (p *{{$interface.Name}}_Proxy) Close_Proxy() {
85 p.router.Close() 93 p.router.Close()
86 } 94 }
87 {{- end -}} 95 {{- end -}}
88 ` 96 `
89 97
98 const methodTmplText = `
99 {{- define "Method" -}}
100 {{- $method := . -}}
101
102 {{ template "MethodParams" $method }}
103
104 {{ template "MethodSignature" $method }}
105
106 {{ template "MethodFunction" $method }}
107 {{- end -}}
108 `
109
90 const methodOrdinalsTmplText = ` 110 const methodOrdinalsTmplText = `
91 {{- define "MethodOrdinals" -}} 111 {{- define "MethodOrdinals" -}}
92 {{- $interface := . -}} 112 {{- $interface := . -}}
93 {{- range $method := $interface.Methods -}} 113 {{- range $method := $interface.Methods -}}
94 const {{$method.FullName}}_Ordinal uint32 = {{$method.Ordinal}} 114 const {{$method.FullName}}_Ordinal uint32 = {{$method.Ordinal}}
95 {{end -}} 115 {{end -}}
96 {{- end -}} 116 {{- end -}}
97 ` 117 `
98 118
99 const methodParamsTmplText = ` 119 const methodParamsTmplText = `
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if err = p.router.Accept(message); err != nil { 197 if err = p.router.Accept(message); err != nil {
178 p.Close_Proxy() 198 p.Close_Proxy()
179 return 199 return
180 } 200 }
181 {{end -}} 201 {{end -}}
182 return 202 return
183 } 203 }
184 {{- end -}} 204 {{- end -}}
185 ` 205 `
186 206
207 const serviceDeclTmplText = `
208 {{- define "ServiceDecl" -}}
209 {{- $interface := . -}}
210 const {{$interface.PrivateName}}_Name string = "{{$interface.ServiceName}}"
211
212 func (r *{{$interface.Name}}_Request) Name() string {
213 return {{$interface.PrivateName}}_Name
214 }
215
216 func (p *{{$interface.Name}}_Pointer) Name() string {
217 return {{$interface.PrivateName}}_Name
218 }
219
220 func (f *{{$interface.Name}}_ServiceFactory) Name() string {
221 return {{$interface.PrivateName}}_Name
222 }
223 {{- end -}}
224 `
225
187 func initInterfaceTemplates() { 226 func initInterfaceTemplates() {
227 template.Must(goFileTmpl.Parse(interfaceTmplText))
188 template.Must(goFileTmpl.Parse(interfaceDeclTmplText)) 228 template.Must(goFileTmpl.Parse(interfaceDeclTmplText))
189 template.Must(goFileTmpl.Parse(interfaceInterfaceDeclTmplText)) 229 template.Must(goFileTmpl.Parse(interfaceInterfaceDeclTmplText))
190 template.Must(goFileTmpl.Parse(interfaceOtherDeclTmplText)) 230 template.Must(goFileTmpl.Parse(interfaceOtherDeclTmplText))
231 template.Must(goFileTmpl.Parse(serviceDeclTmplText))
191 template.Must(goFileTmpl.Parse(methodOrdinalsTmplText)) 232 template.Must(goFileTmpl.Parse(methodOrdinalsTmplText))
192 template.Must(goFileTmpl.Parse(methodParamsTmplText)) 233 template.Must(goFileTmpl.Parse(methodParamsTmplText))
193 template.Must(goFileTmpl.Parse(methodSignatureTmplText)) 234 template.Must(goFileTmpl.Parse(methodSignatureTmplText))
194 template.Must(goFileTmpl.Parse(methodFuncTmplText)) 235 template.Must(goFileTmpl.Parse(methodFuncTmplText))
236 template.Must(goFileTmpl.Parse(methodTmplText))
195 } 237 }
OLDNEW
« no previous file with comments | « no previous file | mojom/generators/go/templates/interfaces_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698