Object
Object
is a generic object type. These objects can be used as parameters for the Context/next
function, like {{next .}}
.
.Typeof
.Typeof
returns the type name of the object. The type name is a string that represents the type of the object. Except for objects under Common, the type names of other objects are lowercase names separated by dots. For example, the type name of a EnumMember
object is enum.member
, and the type name of a Enum
object is enum
. These objects can be customized for code generation by defining templates.
Example:
package demo;
enum Color {
Red = 1;
Green = 2;
Blue = 3;
}
{{- define "go/enum.member" -}}
const {{render "enum.member:name" .Name}} = {{next .Value}}
{{- end}}
{{- define "go/enum.member:name" -}}
{{.Decl.Name}}_{{.}}
{{- end}}
Output:
package demo
type Color int
const Color_Red = 1
const Color_Green = 2
const Color_Blue = 3
These two definitions will override the built-in template functions next/go/enum.member
and next/go/enum.member:name
.
ArrayType
ArrayType
represents an fixed-size array Type.
.ElemType
.ElemType
represents the element Type of the array.
.N
.N
represents the number of elements in the array.
Comment
Comment
represents a line comment or a comment group in Next source code. Use this in templates to access and format comments.
.String
.String
returns the full original comment text, including delimiters.
Example:
const x = 1; // This is a comment.
{{.Comment.String}}
Output:
// This is a comment.
.Text
.Text
returns the content of the comment without comment delimiters.
Example:
const x = 1; // This is a comment.
{{.Comment.Text}}
Output:
This is a comment.
Common
Common
contains some general types, including a generic type. Unless specifically stated, these objects cannot be directly called using the Context/next
function. The Value object represents a value, which can be either a constant value or an enum member's value. The object type for the former is const.value
, and for the latter is enum.member.value
.
Annotation
Annotation
represents an annotation by name
=> value.
Annotation is a map that stores the parameters of a single annotation. It allows for flexible parameter types, including strings, numbers, booleans and Types.
Example:
Next code:
@json(omitempty)
@event(name="Login")
@message(name="Login", type=100)
struct Login {}
@next(type=int8)
enum Color {
Red = 1;
Green = 2;
Blue = 3;
}
Will be represented as:
{{- define "go/struct" -}}
{{.Annotations.json.omitempty}}
{{.Annotations.event.name}}
{{.Annotations.message.name}}
{{.Annotations.message.type}}
{{- end}}
{{- define "go/enum" -}}
{{.Annotations.next.type}}
{{- end}}
Output:
true
Login
Login
100
int8
The next
annotation is used to pass information to the next compiler. It's a reserved annotation and should not be used for other purposes. The next
annotation can be annotated to package
statements, const
declarations, enum
declarations, struct
declarations, field
declarations, interface
declarations, method
declarations, and parameter
declarations.
Annotation name MUST NOT be "Has", it's a reserved method for checking whether the annotation contains the given parameter. Parameter name MUST NOT be start with "_" and uppercase letter (A-Z).
@message(type=100) // OK
@message(_type=100)
// invalid parameter name "_type": must not start with an underscore (_)
@next(Pos=100)
// invalid parameter name "Pos": must not start with an uppercase letter (A-Z)
.Has
.Has
reports whether the annotation contains the given parameter.
Example:
@json(omitempty)
struct User {/*...*/}
{{if .Annotations.json.Has "omitempty"}}
{{/* do something */}}
{{end}}
If you want to check whether the annotation has a non-empty value, you can use the parameter name directly.
{{if .Annotations.json.omitempty}}
{{/* do something */}}
{{end}}
.Len
.Len
returns the number of parameters in the annotation.
.NamePos
.NamePos
returns the position of the annotation name in the source code. It's useful to provide a better error message when needed.
Example:
package demo;
@message(type=100)
struct Login {/*...*/}
{{error "%s: Something went wrong" (.Annotations.message.NamePos "type")}}
Output:
example.next:3:10: Something went wrong
.Node
.Node
returns the node that the annotation is linked to.
.Pos
.Pos
returns the position of the annotation in the source code. It's useful to provide a better error message when needed.
Example:
package demo;
@message(type=100)
struct Login {/*...*/}
{{error "%s: Something went wrong" .Annotations.message.Pos}}
Output:
example.next:3:1: Something went wrong
.ValuePos
.ValuePos
returns the position of the annotation value in the source code. It's useful to provide a better error message when needed.
Example:
package demo;
@message(type=100)
struct Login {/*...*/}
{{error "%s: Something went wrong" (.Annotations.message.ValuePos "type")}}
Output:
example.next:3:15: Something went wrong
decl
.available
The @next(available="expression")
annotation for file
, const
, enum
, struct
, field
, interface
, method
availability of the declaration. The expression
is a boolean expression that can be used to control the availability of the declaration in the target language. Supported operators are &
, |
, !
, (
, )
, and true
, false
.
Example:
@next(available="c|cpp|java|go|csharp")
struct Point {
int x;
int y;
@next(available="c | cpp | go")
int z;
@next(available="!java & !c")
int w;
}
enum
The next
annotation for enum
declarations used to control the enum behavior.
.type
.type
specifies the underlying type of the enum.
Example:
@next(type=int8)
enum Color {
Red = 1;
Green = 2;
Blue = 3;
}
Output in Go:
type Color int8
const (
ColorRed Color = 1
ColorGreen Color = 2
ColorBlue Color = 3
)
Output in C++:
enum class Color : int8_t {
Red = 1,
Green = 2,
Blue = 3,
};
interface
The next
annotation for interface
declarations used to control the interface behavior. L_alias
is a alias for the interface name in language L
. It's used to reference an external type in the target language.
Example:
@next(
available="go|java",
go_alias="net/http.Handler",
java_alias="java.util.function.Function<com.sun.net.httpserver.HttpExchange, String>",
)
interface HTTPHandler {}
@next(available="go|java")
interface HTTPServer {
@next(error)
Handle(string path, HTTPHandler handler);
}
method
The next
annotation for method
declarations used to control the method behavior.
.error
The @next(error)
annotation used to indicate that the method returns an error or throws an exception.
Example:
interface Parser {
@next(error)
parse(string s) int;
}
Output in Go:
type Parser interface {
Parse(s string) (int, error)
}
Output in C++:
class Parser {
public:
int parse(const std::string& s) const;
};
Output in Java:
interface Parser {
int parse(String s) throws Exception;
}
.mut
The @next(mut)
annotation used to indicate that the method is a mutable method, which means it can modify the object's state.
Example:
interface Writer {
@next(error, mut)
write(string data);
}
Output in Go:
type Writer interface {
Write(data string) error
}
Output in C++:
class Writer {
public:
void write(const std::string& data);
};
package
The next
annotation for package
statements used to control the package behavior for specific languages. The next
annotation can be used to set the package name, package path, and some other package-related information.
For any language L
, the next
annotation for package
statements is defined as @next(L_package="package_info")
.
Example:
@next(
c_package="DEMO_",
cpp_package="demo",
java_package="com.exmaple.demo",
go_package="github.com/next/demo",
csharp_package="demo",
)
{{.Package.Annotations.next.c_package}}
{{.Package.Annotations.next.cpp_package}}
{{.Package.Annotations.next.java_package}}
{{.Package.Annotations.next.go_package}}
{{.Package.Annotations.next.csharp_package}}
There are some reserved keys for the next
annotation for package
statements.
.go_imports
.go_imports
represents a list of import paths for Go packages, separated by commas: @next(go_imports="fmt.Printf,*io.Reader")
.
*
is required to import types.
Example:
@next(go_imports="fmt.Printf,*io.Reader")
package demo;
param
The next
annotation for parameter
declarations used to control the parameter behavior.
.mut
The @next(mut)
annotation used to indicate that the parameter is mutable.
Example:
interface Reader {
@next(error);
read(@next(mut) string data);
}
Output in Go:
type Reader interface {
Read(data string) error
}
Output in C++:
class Reader {
public:
void read(std::string& data);
};
struct
The next
annotation for struct
declarations used to control the struct behavior. L_alias
is a alias for the struct name in language L
. It's used to reference an external type in the target language.
Example:
@next(rust_alias="u128")
struct uint128 {
int64 low;
int64 high;
}
@next(go_alias="complex128")
struct Complex {
float64 real;
float64 imag;
}
struct Contract {
uint128 address;
Complex complex;
}
This will don't generate the uint128
struct in the rust
language, but use u128
instead. And in the go
language, it will use complex128
instead of Complex
.
Annotations
Annotations
represents a group of annotations by name
=> Annotation.
Annotations is a map that stores multiple annotations for a given entity. The key is the annotation name (string), and the value is the corresponding Annotation object.
.Has
.Has
reports whether the annotations contain the given annotation.
Example:
@json(omitempty)
struct User {/*...*/}
{{if .Annotations.Has "json"}}
{{/* do something */}}
{{end}}
Decl
Decl
represents a top-level declaration Node in a file.
Currently, the following declarations are supported:
.UsedKinds
.UsedKinds
returns the used kinds in the declaration. Returns 0 if the declaration does not use any kinds. Otherwise, returns the OR of all used kinds.
Example:
struct User {
int64 id;
string name;
vector<string> emails;
map<int, bool> flags;
}
The used kinds in the User
struct are: (1<<KindInt64) | (1<<KindString) | (1<<KindVector) | (1<<KindMap) | (1<<KindInt) | (1<<KindBool)
.
Fields
Fields<D, F>
represents a list of fields of a declaration where D
is the declaration Node and F
is the field object Node.
.Decl
.Decl
is the declaration Node that contains the fields.
Currently, it is one of following types:
.List
.List
is the slice of fields: [Object].
Currently, the field object is one of following types:
.Lookup
.Lookup
looks up a field by name and returns the field object.
List
List<T>
represents a slice of objects: [T: Object].
.List
.List
represents the slice of Objects. It is used to provide a uniform way to access.
LocatedObject
LocatedObject
represents an Object with a location in a file.
.File
.File
represents the file containing the object.
.Package
.Package
represents the package containing the object.
.Pos
.Pos
represents the Position of the object.
Example:
package demo;
const Name = "hei hei";
{{- define "meta/this" -}}const{{- end -}}
{{this.Pos}}
{{this.Value.Pos}}
Output:
demo.next:2:1
demo.next:2:14
Node
Node
represents a LocatedObject that is a node in a file.
Currently, the following nodes are supported:
.Annotations
.Annotations
represents the Annotations for the node.
Example:
package demo;
@next(type=int8)
@custom
enum Color {
Red = 1;
Green = 2;
Blue = 3;
}
{{.Annotations.next.type}}
{{.Annotations.next.Pos}}
{{.Annotations.Has "custom"}}
Output:
int8
demo.next:2:1
true
.Doc
.Doc
represents the documentation comment for the node. The documentation comment is a comment that appears before the node declaration.
Example:
// This is a documentation comment for the node.
// It can be multiple lines.
const x = 1;
{{.Doc.Text}}
Output:
This is a documentation comment for the node.
It can be multiple lines.
.Name
.Name
represents the name of the node.
Example:
const x = 1;
{{.Name}}
Output:
x
.NamePos
.NamePos
represents the position of the node name.
Example:
package demo;
const x = 1;
{{.NamePos}}
Output:
demo.next:2:7
Position
Position
returns the string representation of the position, e.g., demo.next:10:2
.
.Column
.Column
represents the column number of the position starting from 1.
.Filename
.Filename
represents the filename of the position.
.IsValid
.IsValid
reports whether the position is valid.
.Line
.Line
represents the line number of the position starting from 1.
Symbol
Symbol
represents a Next symbol. There are two types of symbols:
- Value symbol: such as a constant or an enum member.
- Type symbol: such as an enum, a struct, or an interface.
Type
Type
represents a Next type Object.
Currently, the following types are supported:
.Actual
.Actual
represents the actual type. You need to use the Actual
method to get the actual type to access the specific fields of the type.
For example, if you have a type ArrayType
:
{{.Type.Actual.ElemType}} {{/* Good */}}
{{.Type.Actual.N}} {{/* Good */}}
{{.Type.ElemType}} {{/* Error */}}
{{.Type.N}} {{/* Error */}}
Example:
package demo;
struct User {
int64 id;
string name;
array<int, 3> codes;
}
{{- define "c/struct.field" -}}
{{- if .Type.Kind.IsArray -}}
{{next .Type.Actual.ElemType}} {{.Name}}[{{.Type.Actual.N}}];
{{- else -}}
{{next .Type}} {{.Name}};
{{- end}}
{{- end}}
Output:
typedef struct User {
int64_t id;
char* name;
int codes[3];
} User;
In the example above, the codes
field is an single-dimensional array of integers with a length of 3. If we want to process the multi-dimensional array, we need to fix the template to recursively process the array type.
Example:
package demo;
struct User {
int64 id;
string name;
array<array<int, 3>, 2> codes;
}
{{- define "c/struct.field" -}}
{{next .Doc}}{{render "dict:struct.field.decl" (dict "type" .Type "name" (render "struct.field:name" .))}};{{next .Comment}}
{{- end}}
{{- define "c/dict:struct.field.decl" -}}
{{- $type := .type -}}
{{- $name := .name -}}
{{- if $type.Kind.IsArray -}}
{{render "dict:struct.field.decl" (dict "type" $type.Actual.ElemType "name" (printf "%s[%d]" $name $type.Actual.N))}}
{{- else -}}
{{next $type}} {{$name}}
{{- end}}
{{- end}}
Output:
typedef struct User {
int64_t id;
char* name;
int codes[2][3];
} User;
.Decl
.Decl
represents the Decl of the type. If the type is a built-in type, it returns a special declaration. Otherwise, it returns the declaration of the type: Enum, Struct, or Interface.
.Kind
.Kind
returns the Kind of the type.
Example:
package demo;
enum Color {
Red = 1;
Green = 2;
Blue = 3;
}
{{- define "cpp/enum" -}}
{{.Type.Kind}}
{{.MemberType.Kind}}
{{end}}
Output:
Enum
Int32
.String
.String
represents the string representation of the type.
.UsedKinds
.UsedKinds
returns the used kinds in the type.
Example:
package demo;
struct User {
int64 id;
string name;
vector<string> emails;
map<int, bool> flags;
}
The used kinds in the User
struct are: (1<<KindStruct) | (1<<KindInt64) | (1<<KindString) | (1<<KindVector) | (1<<KindMap) | (1<<KindInt) | (1<<KindBool)
.
{{.UsedKinds.Has "struct"}}
{{.UsedKinds.Has "int64"}}
{{.UsedKinds.Has "string"}}
{{.UsedKinds.Has "vector"}}
{{.UsedKinds.Has "map"}}
{{.UsedKinds.Has "int"}}
{{.UsedKinds.Has "bool"}}
{{.UsedKinds.Has "float32"}}
Output:
true
true
true
true
true
true
true
false
Kind
Kind
represents the type kind. Currently, the following kinds are supported:
- bool: true or false
- int: integer
- int8: 8-bit integer
- int16: 16-bit integer
- int32: 32-bit integer
- int64: 64-bit integer
- float32: 32-bit floating point
- float64: 64-bit floating point
- byte: byte
- bytes: byte slice
- string: string
- time: time
- duration: duration
- any: any object
- map: dictionary
- vector: vector of elements
- array: array of elements
- enum: enumeration
- struct: structure
- interface: interface
.Bits
.Bits
returns the number of bits for the type. If the type has unknown bits, it returns 0 (for example, any
, string
, bytes
).
.Compatible
.Compatible
returns the compatible type kind between two kinds. If the kinds are not compatible, it returns KindInvalid
. If the kinds are the same, it returns the kind. If the kinds are both numeric, it returns the kind with the most bits.
.IsAny
.IsAny
reports whether the type is any.
.IsArray
.IsArray
reports whether the type is an array.
.IsBool
.IsBool
reports whether the type is a boolean.
.IsByte
.IsByte
reports whether the type is a byte.
.IsBytes
.IsBytes
reports whether the type is a byte slice.
.IsDuration
.IsDuration
reports whether the type is a duration.
.IsEnum
.IsEnum
reports whether the type is an enumeration.
.IsFloat
.IsFloat
reports whether the type is a floating point. It includes float32
and float64
.
.IsInteger
.IsInteger
reports whether the type is an integer. It includes int
, int8
, int16
, int32
, int64
, and byte
.
.IsInterface
.IsInterface
reports whether the type is an interface.
.IsMap
.IsMap
reports whether the type is a map.
.IsNumeric
.IsNumeric
reports whether the type is a numeric type. It includes integer and floating point types.
.IsPrimitive
.IsPrimitive
reports whether the type is a PrimitiveType.
.IsString
.IsString
reports whether the type is a string.
.IsStruct
.IsStruct
reports whether the type is a structure.
.IsTime
.IsTime
reports whether the type is a time.
.IsVector
.IsVector
reports whether the type is a vector.
.String
.String
returns the string representation of the kind.
.Valid
.Valid
reports whether the type is valid.
Kinds
Kinds
represents the type kind set.
.Has
.Has
reports whether the type contains specific kind. The kind can be a Kind
(or any integer) or a string representation of the Kind. If the kind is invalid, it returns an error.
Const
Const
(extends Decl) represents a const declaration.
.Comment
.Comment
is the line Comment of the constant declaration.
Example:
const x = 1; // This is a line comment for the constant.
{{.Comment.Text}}
Output:
This is a line comment for the constant.
.Type
.Type
represents the type of the constant.
.Value
.Value
represents the Value object of the constant.
Consts
Consts
represents a List of Const declarations.
Decls
Decls
holds all top-level declarations in a file.
.Consts
.Enums
.Interfaces
.List
.List
returns the all top-level declarations.
.Structs
Doc
Doc
represents a documentation comment for a declaration in Next source code. Use this in templates to access and format documentation comments.
.Format
.Format
formats the documentation comment for various output styles.
Parameters: (indent string[, begin string[, end string]])
Example:
// This is a documentation comment.
// It can be multiple lines.
const x = 1;
{{.Doc.Format "/// "}}
{{.Doc.Format " * " "/**\n" " */"}}
Output:
/// This is a documentation comment.
/// It can be multiple lines.
/**
* This is a documentation comment.
* It can be multiple lines.
*/
.String
.String
returns the full original documentation comment, including delimiters.
Example:
// This is a documentation comment.
// It can be multiple lines.
const x = 1;
{{.Doc.String}}
Output:
// This is a documentation comment.
// It can be multiple lines.
.Text
.Text
returns the content of the documentation comment without comment delimiters.
Example:
// This is a documentation comment.
// It can be multiple lines.
const x = 1;
{{.Doc.Text}}
Output:
This is a documentation comment.
It can be multiple lines.
Enum
Enum
(extends Decl) represents an enum declaration.
.MemberType
.MemberType
represents the PrimitiveType of the enum members.
.Members
.Members
is the Fields of EnumMember.
.Type
.Type
is the EnumType of the enum.
EnumMember
EnumMember
(extends Decl) represents an enum member object in an Enum declaration.
.Comment
.Comment
represents the line Comment of the enum member declaration.
.Decl
.Decl
represents the Enum that contains the member.
.Index
.Index
represents the index of the enum member in the enum type.
.Value
.Value
represents the Value object of the enum member.
EnumMembers
EnumMembers
represents the Fields of EnumEember in an Enum declaration.
EnumType
EnumType
represents the Type of an Enum declaration.
Enums
Enums
represents a List of Enum declarations.
File
File
(extends Decl) represents a Next source file.
.Decls
.Decls
returns the file's all top-level declarations.
.Imports
.Imports
represents the file's import declarations.
.LookupLocalType
.LookupLocalType
looks up a type by name in the file's symbol table. If the type is not found, it returns an error. If the symbol is found but it is not a type, it returns an error.
.LookupLocalValue
.LookupLocalValue
looks up a value by name in the file's symbol table. If the value is not found, it returns an error. If the symbol is found but it is not a value, it returns an error.
.Name
.Name
represents the file name without the ".next" extension.
.Path
.Path
represents the file full path.
Import
Import
represents a import declaration in a File.
.Comment
.Comment
represents the line Comment of the import declaration.
Example:
// This is a documenation comment for the import.
// It can be multiline.
import "path/to/file.next"; // This is a line comment for the import.
{{.Comment.Text}}
Output:
This is a line comment for the import.
.Doc
.Doc
represents the Doc comment of the import.
Example:
// This is a documenation comment for the import.
// It can be multiline.
import "path/to/file.next"; // This is a line comment for the import declaration.
{{.Doc.Text}}
Output:
This is a documenation comment for the import.
It can be multiline.
.File
.File
represents the File object that contains the import declaration.
Example:
package a;
import "file2.next";
import "file3.next";
{{range .Imports.List}}
{{.File.Path}}
{{end}}
Output:
file1.next
file1.next
.FullPath
.FullPath
represents the full path of the import.
Example:
import "path/to/file.next";
{{.FullPath}}
Output:
/full/path/to/file.next
.Path
.Path
represents the import path.
Example:
import "path/to/file.next";
{{.Path}}
Output:
path/to/file.next
.Target
.Target
represents the imported File object.
Example:
package a;
import "file2.next";
import "file3.next";
{{range .Imports.List}}
{{.Target.Path}}
{{end}}
Output:
file2.next
file3.next
Imports
Imports
holds a slice of Import declarations and the declaration that contains the imports.
.Decl
.Decl
represents the declaration Node that contains the imports. Currently, it is one of following types:
Example:
package a;
import "path/to/file2.next";
package a;
- file.npl
- package.npl
{{- define "meta/this" -}}file{{- end -}}
{{range this.Imports.List}}
{{.Decl.Name}}
{{end}}
Output (for file1.next):
file1
{{- define "meta/this" -}}package{{- end -}}
{{range this.Imports.List}}
{{.Decl.Name}}
{{end}}
Output:
a
.List
.List
represents a slice of Import declarations: [Import].
Example: see Object/Imports.Decl.
.TrimmedList
.TrimmedList
represents a slice of unique imports sorted by package name.
Example:
package c;
import "path/to/file1.next"; // package: a
import "path/to/file2.next"; // package: a
import "path/to/file3.next"; // package: b
{{range .Imports.TrimmedList}}
{{.Target.Package.Name}}
{{end}}
Output:
a
b
Interface
Interface
(extends Decl) represents an interface declaration.
.Methods
.Methods
represents the list of interface methods.
.Type
.Type
represents InterfaceType of the interface.
InterfaceMethod
InterfaceMethod
(extends Node) represents an interface method declaration.
.Comment
.Comment
represents the line Comment of the interface method declaration.
.Decl
.Decl
represents the interface that contains the method.
.Index
.Index
represents the index of the interface method in the interface.
Example:
interface Shape {
draw(); // Index is 0 for draw
area() float64; // Index is 1 for area
}
.IsFirst
.IsFirst
reports whether the method is the first method in the interface.
Example:
interface Shape {
draw(); // IsFirst is true for draw
area() float64;
}
.IsLast
.IsLast
reports whether the method is the last method in the interface type.
Example:
interface Shape {
draw();
area() float64; // IsLast is true for area
}
.Params
.Params
represents the Fields of InterfaceMethodParameter.
.Result
.Result
represents the InterfaceMethodResult of the method.
InterfaceMethodParameter
InterfaceMethodParameter
(extends Node) represents an interface method parameter declaration.
.Index
.Index
represents the index of the interface method parameter in the method.
Example:
interface Shape {
draw(int x, int y); // Index is 0 for x, 1 for y
}
.IsFirst
.IsFirst
reports whether the parameter is the first parameter in the method.
Example:
interface Shape {
draw(int x, int y); // IsFirst is true for x
}
.IsLast
.IsLast
reports whether the parameter is the last parameter in the method. Example:
interface Shape {
draw(int x, int y); // IsLast is true for y
}
.Method
.Method
represents the InterfaceMethod that contains the parameter.
.Type
.Type
represents the Type of the parameter.
InterfaceMethodParams
InterfaceMethodParams
represents the Fields of InterfaceMethodParameter in an InterfaceMethod declaration.
InterfaceMethodResult
InterfaceMethodResult
represents an interface method result.
.Method
.Method
represents the InterfaceMethod that contains the result.
.Type
.Type
represents the underlying Type of the result.
InterfaceMethods
InterfaceMethods
represents the Fields of InterfaceMethod in an Interface declaration.
InterfaceType
InterfaceType
represents the Type of an Interface declaration.
Interfaces
Interfaces
represents a List of Interface declarations.
MapType
MapType
represents a map Type.
.ElemType
.ElemType
represents the element Type of the map.
.KeyType
.KeyType
represents the key Type of the map.
Package
Package
(extends Decl) represents a Next package.
.Decls
.Decls
represents the top-level declarations in the package.
.Files
.Files
represents the all declared file objects in the package.
.Has
.Has
reports whether the package contains the given Type or Symbol. If the current package is nil, it always returns true.
Example:
{{- define "next/go/used.type" -}}
{{if not (.File.Package.Has .Type) -}}
{{.Type.Decl.File.Package.Name -}}.
{{- end -}}
{{next .Type}}
{{- end}}
.Imports
.Imports
represents the package's import declarations.
.LookupLocalType
.LookupLocalType
looks up a type by name in the package's symbol table.
.LookupLocalValue
.LookupLocalValue
looks up a value by name in the package's symbol table.
.Name
.Name
represents the package name string.
.Types
.Types
represents the all declared types in the package.
Packages
Packages
represents a list of Next packages.
PrimitiveType
PrimitiveType
represents a primitive type.
Currently, the following primitive types are supported:
- int
- int8
- int16
- int32
- int64
- float32
- float64
- bool
- string
- byte
- bytes
- any
Struct
Struct
(extends Decl) represents a struct declaration.
.Fields
.Fields
represents the Fields of StructField.
Example:
struct Point {
int x;
int y;
}
{{range .Fields.List}}
{{.Name}} {{.Type}}
{{end}}
Output:
x int
y int
.Type
.Type
represents StructType of the struct.
StructField
StructField
(extends Node) represents a struct field declaration.
.Comment
.Comment
represents the line Comment of the struct field declaration.
.Decl
.Decl
represents the Struct that contains the field.
.Index
.Index
represents the index of the struct field in the struct type.
Example:
struct Point {
int x; // Index is 0 for x
int y; // Index is 1 for y
}
.IsFirst
.IsFirst
reports whether the field is the first field in the struct type.
Example:
struct Point {
int x; // IsFirst is true for x
int y;
}
.IsLast
.IsLast
reports whether the field is the last field in the struct type.
Example:
struct Point {
int x;
int y; // IsLast is true for y
}
.Type
.Type
represents the Type of the struct field.
StructFields
StructFields
represents the Fields of StructField in a Struct declaration.
StructType
StructType
represents the Type of a Struct declaration.
Structs
Structs
represents a List of Struct declarations.
UsedType
UsedType
represents a used Type in a file.
.File
.File
represents the File where the type is used.
.Node
.Node
represents the node where the type is used.
The node may be:
- StructField: for a struct field type
- InterfaceMethod: for a method result type
- InterfaceMethodParameter: for a method parameter type
.Type
.Type
represents the underlying Type.
Example:
package demo;
struct User {/*...*/}
struct Group {
User user;
}
The type of the user
field is a UsedType
with the underlying type StructType
of the User
struct.
Value
Value
represents a value for a const declaration or an enum member.
.Actual
.Actual
represents the underlying value of the constant. It returns one of the following types:
- int32
- int64
- float32
- float64
- bool
- string
- nil
.Enum
.Enum
represents the enum object that contains the value if it is an enum member. Otherwise, it returns nil.
.IsFirst
.IsFirst
reports whether the value is the first member of the enum type.
Example:
enum Color {
Red = 1; // IsFirst is true for Red
Green = 2;
Blue = 3;
}
.IsLast
.IsLast
reports whether the value is the last member of the enum type.
Example:
enum Color {
Red = 1;
Green = 2;
Blue = 3; // IsLast is true for Blue
}
.String
.String
represents the string representation of the value.
.Type
.Type
represents the PrimitiveType of the value.
VectorType
VectorType
represents a vector Type.
.ElemType
.ElemType
represents the element Type of the vector.