/
file_list.go
80 lines (71 loc) · 2.12 KB
/
file_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package java
import (
"bytes"
"log"
"v.io/x/ref/lib/vdl/compile"
)
const listTmpl = header + `
// Source: {{.SourceFile}}
package {{.Package}};
{{ .Doc }}
@io.v.v23.vdl.GeneratedFromVdl(name = "{{.VdlTypeName}}")
{{ .AccessModifier }} class {{.Name}} extends io.v.v23.vdl.VdlList<{{.ElemType}}> {
private static final long serialVersionUID = 1L;
/**
* Vdl type for {@link {{.Name}}}.
*/
public static final io.v.v23.vdl.VdlType VDL_TYPE =
io.v.v23.vdl.Types.getVdlTypeFromReflect({{.Name}}.class);
/**
* Creates a new instance of {@link {{.Name}}} with the given underlying value.
*
* @param impl underlying value
*/
public {{.Name}}(java.util.List<{{.ElemType}}> impl) {
super(VDL_TYPE, impl);
}
/**
* Creates a new empty instance of {@link {{.Name}}}.
*/
public {{.Name}}() {
this(new java.util.ArrayList<{{.ElemType}}>());
}
}
`
// genJavaListFile generates the Java class file for the provided named list type.
func genJavaListFile(tdef *compile.TypeDef, env *compile.Env) JavaFileInfo {
name, access := javaTypeName(tdef, env)
data := struct {
AccessModifier string
Doc string
ElemType string
FileDoc string
Name string
Package string
SourceFile string
VdlTypeName string
VdlTypeString string
}{
AccessModifier: access,
Doc: javaDoc(tdef.Doc, tdef.DocSuffix),
ElemType: javaType(tdef.Type.Elem(), true, env),
FileDoc: tdef.File.Package.FileDoc,
Name: name,
Package: javaPath(javaGenPkgPath(tdef.File.Package.GenPath)),
SourceFile: tdef.File.BaseName,
VdlTypeName: tdef.Type.Name(),
VdlTypeString: tdef.Type.String(),
}
var buf bytes.Buffer
err := parseTmpl("list", listTmpl).Execute(&buf, data)
if err != nil {
log.Fatalf("vdl: couldn't execute list template: %v", err)
}
return JavaFileInfo{
Name: name + ".java",
Data: buf.Bytes(),
}
}