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

Unified Diff: mojom/generators/go/translator/types.go

Issue 2091493002: Switch to the new go generator in the mojo tree. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Update names as suggested. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/generators/go/translator/translator.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/generators/go/translator/types.go
diff --git a/mojom/generators/go/translator/types.go b/mojom/generators/go/translator/types.go
index 2b8390d9bb74d79e2cb644c557c34c44fcd216b8..72bdce826d81cea8cc899935da6257859ad2337b 100644
--- a/mojom/generators/go/translator/types.go
+++ b/mojom/generators/go/translator/types.go
@@ -6,6 +6,7 @@ package translator
import (
"fmt"
+ "path/filepath"
"mojom/generated/mojom_types"
)
@@ -121,9 +122,9 @@ func (t *translator) translateMapType(mojomType mojom_types.MapType) (goType str
}
func (t *translator) translateTypeReference(typeRef mojom_types.TypeReference) (goType string) {
- // TOOD(azani): Handle imported types.
typeKey := *typeRef.TypeKey
userDefinedType := t.fileGraph.ResolvedTypes[typeKey]
+
typeName := t.goTypeName(*typeRef.TypeKey)
if _, ok := userDefinedType.(*mojom_types.UserDefinedTypeInterfaceType); ok {
@@ -134,5 +135,17 @@ func (t *translator) translateTypeReference(typeRef mojom_types.TypeReference) (
}
}
+ srcFileInfo := userDefinedTypeDeclData(userDefinedType).SourceFileInfo
+ if srcFileInfo != nil && srcFileInfo.FileName == t.currentFileName {
+ pkgName := fileNameToPackageName(srcFileInfo.FileName)
+ pkgPath, err := filepath.Rel(t.Config.SrcRootPath(), srcFileInfo.FileName)
+ if err != nil {
+ panic(err.Error())
+ }
+ pkgPath = pkgPath[:len(pkgPath)-len(filepath.Ext(pkgPath))-1]
+ t.imports[pkgName] = pkgPath
+ typeName = fmt.Sprintf("%s.%s", pkgName, typeName)
+ }
+
return typeName
}
« no previous file with comments | « mojom/generators/go/translator/translator.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698