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

Side by Side Diff: mojom/generators/go/translator/names.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
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 translator 5 package translator
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "path/filepath" 9 "path/filepath"
10 "strings" 10 "strings"
(...skipping 24 matching lines...) Expand all
35 t.goTypeCache[typeKey] = goType 35 t.goTypeCache[typeKey] = goType
36 return goType 36 return goType
37 } 37 }
38 38
39 func fileNameToPackageName(fileName string) string { 39 func fileNameToPackageName(fileName string) string {
40 base := filepath.Base(fileName) 40 base := filepath.Base(fileName)
41 ext := filepath.Ext(base) 41 ext := filepath.Ext(base)
42 return base[:len(base)-len(ext)] 42 return base[:len(base)-len(ext)]
43 } 43 }
44 44
45 func userDefinedTypeDeclData(userDefinedType mojom_types.UserDefinedType) *mojom _types.DeclarationData {
46 switch u := userDefinedType.(type) {
47 case *mojom_types.UserDefinedTypeEnumType:
48 return u.Value.DeclData
49 case *mojom_types.UserDefinedTypeStructType:
50 return u.Value.DeclData
51 case *mojom_types.UserDefinedTypeUnionType:
52 return u.Value.DeclData
53 case *mojom_types.UserDefinedTypeInterfaceType:
54 return u.Value.DeclData
55 }
56 panic("Non-handled mojom UserDefinedType. This should never happen.")
57 }
58
45 // userDefinedTypeShortName extracts the ShortName from a user-defined type. 59 // userDefinedTypeShortName extracts the ShortName from a user-defined type.
46 func userDefinedTypeShortName(userDefinedType mojom_types.UserDefinedType) strin g { 60 func userDefinedTypeShortName(userDefinedType mojom_types.UserDefinedType) strin g {
47 » switch u := userDefinedType.(type) { 61 » return *userDefinedTypeDeclData(userDefinedType).ShortName
48 » case *mojom_types.UserDefinedTypeEnumType:
49 » » return *u.Value.DeclData.ShortName
50 » case *mojom_types.UserDefinedTypeStructType:
51 » » return *u.Value.DeclData.ShortName
52 » case *mojom_types.UserDefinedTypeUnionType:
53 » » return *u.Value.DeclData.ShortName
54 » case *mojom_types.UserDefinedTypeInterfaceType:
55 » » return *u.Value.DeclData.ShortName
56 » }
57 » panic("Non-handled mojom UserDefinedType. This should never happen.")
58 } 62 }
59 63
60 // privateName accepts a string and returns that same string with the first rune 64 // privateName accepts a string and returns that same string with the first rune
61 // set to lowercase. 65 // set to lowercase.
62 func privateName(name string) string { 66 func privateName(name string) string {
63 _, size := utf8.DecodeRuneInString(name) 67 _, size := utf8.DecodeRuneInString(name)
64 return strings.ToLower(name[:size]) + name[size:] 68 return strings.ToLower(name[:size]) + name[size:]
65 } 69 }
66 70
67 // formatName formats a name to match go style. 71 // formatName formats a name to match go style.
(...skipping 25 matching lines...) Expand all
93 } 97 }
94 98
95 for i := range parts { 99 for i := range parts {
96 part := strings.Title(strings.ToLower(parts[i])) 100 part := strings.Title(strings.ToLower(parts[i]))
97 _, size := utf8.DecodeRuneInString(part) 101 _, size := utf8.DecodeRuneInString(part)
98 parts[i] = strings.ToUpper(part[:size]) + part[size:] 102 parts[i] = strings.ToUpper(part[:size]) + part[size:]
99 } 103 }
100 104
101 return strings.Join(parts, "") 105 return strings.Join(parts, "")
102 } 106 }
OLDNEW
« no previous file with comments | « mojom/generators/go/translator/mojom_file.go ('k') | mojom/generators/go/translator/translator.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698