Expand description
Java code syntax
Java syntax elements.
Note that no checking exists to make sure the elements are used correctly, i.e. the correct combination of structs. Instead, the library user is expected to have basic knowledge of how Java syntax is composed, and to combine the structs in this module likewise.
Structs§
- Array
- An array of another type. Renders as
Component[] - Assert
Stmt - An assertion. Renders as
assert Assert;with a new line at the end - Assign
Expr - An assignation, as an expression. Renders as
Variable = Expr. In Java, an assignation expression has the same type and value as the assigned value. - Assign
Stmt - An assignation. This statement includes the semicolon and a new line.
- Block
- An unlabeled block. This can be used in many contexts, including merely organizing the code.
- Class
Def - Declares a class.
- Constructor
Call - Calls a constructor with a name and arguments. Renders as
new Name(Arg1, Arg2, Arg3, ...) - Constructor
Def - Defines a constructor
- Declare
Param - A function parameter, constructor parameter, or record component parameter.
- Declare
VarStmt - Declares a new variable. Renders as
Type Expr;with a new line at the end The expression can be either the variable name or an AssignExpr. - Else
- Represents “else” syntactically. Renders as
Before else After. - Enhanced
For - An enhanced for loop in the style
for (VarName : Iter) { Body }. All fields of this struct must be writable. - Extends
- The “extends” keyword. Renders as
Expr extends Super. - Function
Call - Calls a function with a name and arguments. Renders as
Name(Arg1, Arg2, Arg3, ...) - Function
Def - Defines a function
- IfBlock
- An if block. The condition and body must both be writable.
- Implements
- The “implements” keyword. Renders as
Expr implements Iface1, Iface2, Iface3, .... The interfaces must be a sequence. If it is empty, then onlyExprwill be rendered. - Interface
Def - Declares an interface
- Member
Access - Accesses a field or calls a method by name. Renders as
Owner.Member. - Parameterized
- A type argument-parameterized declaration. Renders as
Name<TypeArgs>. - Return
Stmt - A return statement. Renders as
return Expr;with a new line at the end. - Stmt
- A standalone statement. Renders the expression and adds a semicolon and a new line.
- Traditional
For - A traditional for loop in the style
for (Init; Predicate; Update) { Body }. All the fields of this struct must be writable. For example: - With
Inference - Applies diamond inference to the construction of a type. Renders as
Name<>.
Enums§
- Modifier
- A single modifier keyword