==================================
standalone assignment expression
==================================

x = 3;

---

(program
  (expression_statement (assignment_expression
    (identifier)
    (decimal_integer_literal))))

==================================
standalone binary expression
==================================

a > b;
a < b;
a == b;
a >= b;
a <= b;
a != b;
a && b;
a || b;
a & b;
a | b;
a ^ b;
a % b;
a << b;
a >> b;
a >>> b;
3 + 2;
3 - 2;
3 * 2;
9 / 3;

---

(program
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (identifier) (identifier)))
  (expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal)))
  (expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal)))
  (expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal)))
  (expression_statement (binary_expression (decimal_integer_literal) (decimal_integer_literal))))

==================================
instanceof expressions
==================================

a instanceof C.D;
a instanceof List<B>;
c instanceof C[];

---

(program
  (expression_statement (instanceof_expression
    (identifier)
    (scoped_type_identifier (type_identifier) (type_identifier))))
  (expression_statement (instanceof_expression
    (identifier)
    (generic_type (type_identifier) (type_arguments (type_identifier)))))
  (expression_statement (instanceof_expression
    (identifier)
    (array_type (type_identifier) (dimensions)))))

===========================================================
if statements
===========================================================

if (x)
  y;

---

(program
  (if_statement
    condition: (parenthesized_expression (identifier))
    consequence: (expression_statement (identifier))))

===========================================================
if statements with braces
===========================================================

if (x) {
  y;
}

---

(program
  (if_statement
    condition: (parenthesized_expression (identifier))
    consequence: (block (expression_statement (identifier)))))

===========================================================
if statements with assignment without braces
===========================================================

if (x = 3)
  y = 2;

---

(program
  (if_statement
    condition: (parenthesized_expression
      (assignment_expression
        left: (identifier)
        right: (decimal_integer_literal)))
    consequence: (expression_statement
      (assignment_expression
        left: (identifier)
        right: (decimal_integer_literal)))))

==================================
if then else statement
==================================

if (x = 3) {
  y = 9;
} else {
  y = 0;
}

---

(program
  (if_statement
    condition: (parenthesized_expression
      (assignment_expression
        left: (identifier)
        right: (decimal_integer_literal)))
    consequence: (block
      (expression_statement (assignment_expression
        left: (identifier)
        right: (decimal_integer_literal))))
    alternative: (block
      (expression_statement (assignment_expression
        left: (identifier)
        right: (decimal_integer_literal))))))

==================================
nested if then else statements
==================================

if (a)
  if (b)
    c();
  else
    d();

---

(program
  (if_statement
    (parenthesized_expression (identifier))
    (if_statement
      (parenthesized_expression (identifier))
      (expression_statement (method_invocation (identifier) (argument_list)))
      (expression_statement (method_invocation (identifier) (argument_list))))))

==================================
ternary expressions
==================================

max = (a > b) ? a : b;

---

(program
  (expression_statement (assignment_expression
    left: (identifier)
    right: (ternary_expression
      condition: (parenthesized_expression (binary_expression
        left: (identifier)
        right: (identifier)))
      consequence: (identifier)
      alternative: (identifier)))))

==================================
for statement
==================================

for(int i = 1; i < 11; i++) {
  System.out.println("Count is: " + i);
}

for (j.init(i); j.check(); j.update()) {
  System.out.println(j);
}

---

(program
  (for_statement
    init: (local_variable_declaration
      type: (integral_type)
      declarator: (variable_declarator
        name: (identifier)
        value: (decimal_integer_literal)))
    condition: (binary_expression
      left: (identifier)
      right: (decimal_integer_literal))
    update: (update_expression (identifier))
    body: (block
      (expression_statement (method_invocation
        object: (field_access
          object: (identifier)
          field: (identifier))
        name: (identifier)
        arguments: (argument_list (binary_expression
          left: (string_literal)
          right: (identifier)))))))
  (for_statement
    init: (method_invocation
      object: (identifier)
      name: (identifier)
      arguments: (argument_list (identifier)))
    condition: (method_invocation
      object: (identifier)
      name: (identifier)
      arguments: (argument_list))
    update: (method_invocation
      object: (identifier)
      name: (identifier)
      arguments: (argument_list))
    body: (block
      (expression_statement (method_invocation
        object: (field_access
          object: (identifier)
          field: (identifier))
        name: (identifier)
        arguments: (argument_list (identifier)))))))

================================
Enhanced for statements
================================

for (A b : c) {
  d(b);
}

---

(program
  (enhanced_for_statement
    (type_identifier)
    (identifier)
    (identifier)
    (block
      (expression_statement (method_invocation
        (identifier)
        (argument_list (identifier)))))))

==================================
while statement
==================================

class WhileDemo {
    public static void main(String[] args){
        int count = 1;
        while (count < 11) {
            System.out.println("Count is: " + count);
            count++;
        }
    }
}

---

 (program
  (class_declaration
    name: (identifier)
    body: (class_body
      (method_declaration
        (modifiers)
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters
          (formal_parameter
            type: (array_type
              element: (type_identifier)
              dimensions: (dimensions))
            name: (identifier)))
        body: (block
          (local_variable_declaration
            type: (integral_type)
            declarator: (variable_declarator
              name: (identifier)
              value: (decimal_integer_literal)))
          (while_statement
            condition: (parenthesized_expression
              (binary_expression
                left: (identifier)
                right: (decimal_integer_literal)))
            body: (block
              (expression_statement (method_invocation
                object: (field_access
                  object: (identifier)
                  field: (identifier))
                name: (identifier)
                arguments: (argument_list
                  (binary_expression left: (string_literal) right: (identifier)))))
              (expression_statement (update_expression (identifier))))))))))

==================================
try-with-resources statements
==================================

try (FileInputStream input = new FileInputStream("file.txt")) {
  int data = input.read();
}

---

(program
  (try_with_resources_statement
    resources: (resource_specification
      (resource
        type: (type_identifier)
        name: (identifier)
        value: (object_creation_expression
          type: (type_identifier)
          arguments: (argument_list (string_literal)))))
    body: (block
      (local_variable_declaration
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)
          value: (method_invocation
            object: (identifier)
            name: (identifier)
            arguments: (argument_list)))))))

==================================
return statement
==================================

return x;
return x * y;
return x + 2;
return fire(x);

---

(program
  (return_statement (identifier))
  (return_statement (binary_expression (identifier) (identifier)))
  (return_statement (binary_expression (identifier) (decimal_integer_literal)))
  (return_statement (method_invocation (identifier) (argument_list (identifier)))))

==================================
annotation
==================================

@SuppressWarnings(value = "unchecked")
@GwtCompatible(emulated = true)
class Duck {

}

---

(program
  (class_declaration
    (modifiers
      (annotation
        (identifier)
        (annotation_argument_list
          (element_value_pair
            (identifier)
            (string_literal))))
      (annotation
        (identifier)
        (annotation_argument_list
          (element_value_pair
            (identifier)
            (true)))))
    (identifier)
    (class_body)))

==================================
marker annotation
==================================

@Override
class Quack {
  @bar
  public void foo() {

  }
}

---

(program
  (class_declaration
    (modifiers (marker_annotation (identifier)))
    (identifier)
    (class_body
      (method_declaration
        (modifiers (marker_annotation (identifier)))
        (void_type)
        (identifier)
        (formal_parameters)
        (block)))))

==================================
single element annotation
==================================

@Duck(waddle.swim)
@SuppressWarnings("unchecked")
class Quack {

}

---

(program
  (class_declaration
    (modifiers
      (annotation (identifier) (annotation_argument_list (field_access (identifier) (identifier))))
      (annotation (identifier) (annotation_argument_list (string_literal))))
    (identifier)
    (class_body)))

==================================
lambda expression
==================================

class LambdaTest {
  void singleton() {
    version -> create;
    (a, b) -> a + b;
  }
}

---

(program
  (class_declaration
    (identifier)
    (class_body
      (method_declaration
        (void_type)
        (identifier)
        (formal_parameters)
        (block
          (expression_statement (lambda_expression
            (identifier)
            (identifier)))
          (expression_statement (lambda_expression
            (inferred_parameters (identifier) (identifier))
            (binary_expression (identifier) (identifier)))))))))

==================================
traditional switch statement
==================================

public class SwitchDemo {
  public static void main(String[] args) {
    int destinysChild = 2;
    String destinysChildString;
    switch (destinysChild) {
        case 1:  destinysChildString = "Beyonce";
                 break;
        case 2:  destinysChildString = "Kelly";
                 break;
        case 3:  destinysChildString = "Michelle";
                 break;
        default: destinysChildString = "Invalid";
                 break;
    }
    System.out.println(destinysChildString);
  }
}

---

(program
  (class_declaration
    (modifiers)
    name: (identifier)
    body: (class_body
      (method_declaration
        (modifiers)
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters
          (formal_parameter
            type: (array_type
              element: (type_identifier)
              dimensions: (dimensions))
            name: (identifier)))
        body: (block
          (local_variable_declaration
            type: (integral_type)
            declarator: (variable_declarator
              name: (identifier)
              value: (decimal_integer_literal)))
          (local_variable_declaration
            type: (type_identifier)
            declarator: (variable_declarator
              name: (identifier)))
          (switch_expression
            condition: (parenthesized_expression
              (identifier))
            body: (switch_block
              (switch_block_statement_group
                (switch_label
                  (decimal_integer_literal))
                (expression_statement
                  (assignment_expression
                    left: (identifier)
                    right: (string_literal)))
                (break_statement))
              (switch_block_statement_group
                (switch_label
                  (decimal_integer_literal))
                (expression_statement
                  (assignment_expression
                    left: (identifier)
                    right: (string_literal)))
                (break_statement))
              (switch_block_statement_group
                (switch_label
                  (decimal_integer_literal))
                (expression_statement
                  (assignment_expression
                    left: (identifier)
                    right: (string_literal)))
                (break_statement))
              (switch_block_statement_group
                (switch_label)
                (expression_statement
                  (assignment_expression
                    left: (identifier)
                    right: (string_literal)))
                (break_statement))))
          (expression_statement
            (method_invocation
              object: (field_access
                object: (identifier)
                field: (identifier))
              name: (identifier)
              arguments: (argument_list
                (identifier)))))))))

==================================
functional switch statement
==================================

class Test {
    int i;
    int f(int i) {
        return 0;
    }

    void main() {
        switch (f(i)) {
            case 0, 1 -> System.out.println(6);
            case 2 -> System.out.println(7);
        }
    }
}

---

(program
  (class_declaration
    name: (identifier)
    body: (class_body
      (field_declaration
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)))
      (method_declaration
        type: (integral_type)
        name: (identifier)
        parameters: (formal_parameters
          (formal_parameter
            type: (integral_type)
            name: (identifier)))
        body: (block
          (return_statement
            (decimal_integer_literal))))
      (method_declaration
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters)
        body: (block
          (switch_expression
            condition: (parenthesized_expression
              (method_invocation
                name: (identifier)
                arguments: (argument_list
                  (identifier))))
            body: (switch_block
              (switch_rule
                (switch_label
                  (decimal_integer_literal)
                  (decimal_integer_literal))
                (expression_statement
                  (method_invocation
                    object: (field_access
                      object: (identifier)
                      field: (identifier))
                    name: (identifier)
                    arguments: (argument_list
                      (decimal_integer_literal)))))
              (switch_rule
                (switch_label
                  (decimal_integer_literal))
                (expression_statement
                  (method_invocation
                    object: (field_access
                      object: (identifier)
                      field: (identifier))
                    name: (identifier)
                    arguments: (argument_list
                      (decimal_integer_literal))))))))))))

===========================================================
traditional-style switch expression
===========================================================

class Test {
    int d = 3;
    static final int NUM = 2;
    void main() {
        int result = switch (d) {
            case 5 + 6:
                yield 1;
            case NUM:
                yield 2;
            default:
                System.out.println("hmmm...");
                yield 0;
        };
    }
}

---

(program
  (class_declaration
    name: (identifier)
    body: (class_body
      (field_declaration
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)
          value: (decimal_integer_literal)))
      (field_declaration
        (modifiers)
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)
          value: (decimal_integer_literal)))
      (method_declaration
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters)
        body: (block
          (local_variable_declaration
            type: (integral_type)
            declarator: (variable_declarator
              name: (identifier)
              value: (switch_expression
                condition: (parenthesized_expression
                  (identifier))
                body: (switch_block
                  (switch_block_statement_group
                    (switch_label
                      (binary_expression
                        left: (decimal_integer_literal)
                        right: (decimal_integer_literal)))
                    (yield_statement
                      (decimal_integer_literal)))
                  (switch_block_statement_group
                    (switch_label
                      (identifier))
                    (yield_statement
                      (decimal_integer_literal)))
                  (switch_block_statement_group
                    (switch_label)
                    (expression_statement
                      (method_invocation
                        object: (field_access
                          object: (identifier)
                          field: (identifier))
                        name: (identifier)
                        arguments: (argument_list
                          (string_literal))))
                    (yield_statement
                      (decimal_integer_literal))))))))))))

==================================
functional switch expression
==================================

class Test {
    int i;
    static final int ZERO = 0;
    void main() {
        int a = switch (i) {
            case ZERO, 1 -> 6;
            case (int)(2.0) -> 7;
            default -> 8;
        };
    }
}

---

(program
  (class_declaration
    name: (identifier)
    body: (class_body
      (field_declaration
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)))
      (field_declaration
        (modifiers)
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)
          value: (decimal_integer_literal)))
      (method_declaration
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters)
        body: (block
          (local_variable_declaration
            type: (integral_type)
            declarator: (variable_declarator
              name: (identifier)
              value: (switch_expression
                condition: (parenthesized_expression
                  (identifier))
                body: (switch_block
                  (switch_rule
                    (switch_label
                      (identifier)
                      (decimal_integer_literal))
                    (expression_statement
                      (decimal_integer_literal)))
                  (switch_rule
                    (switch_label
                      (cast_expression
                        type: (integral_type)
                        value: (parenthesized_expression
                          (decimal_floating_point_literal))))
                    (expression_statement
                      (decimal_integer_literal)))
                  (switch_rule
                    (switch_label)
                    (expression_statement
                      (decimal_integer_literal))))))))))))

==================================
switch expression with block
==================================

class Test {
    int i;
    void main() {
        int a = switch (i) {
            case 0, 1 -> 6;
            case 2 -> 7;
            default -> {
                int result = 8;
                yield result;
            }
        };
    }
}

---

(program
  (class_declaration
    name: (identifier)
    body: (class_body
      (field_declaration
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)))
      (method_declaration
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters)
        body: (block
          (local_variable_declaration
            type: (integral_type)
            declarator: (variable_declarator
              name: (identifier)
              value: (switch_expression
                condition: (parenthesized_expression
                  (identifier))
                body: (switch_block
                  (switch_rule
                    (switch_label
                      (decimal_integer_literal)
                      (decimal_integer_literal))
                    (expression_statement
                      (decimal_integer_literal)))
                  (switch_rule
                    (switch_label
                      (decimal_integer_literal))
                    (expression_statement
                      (decimal_integer_literal)))
                  (switch_rule
                    (switch_label)
                    (block
                      (local_variable_declaration
                        type: (integral_type)
                        declarator: (variable_declarator
                          name: (identifier)
                          value: (decimal_integer_literal)))
                      (yield_statement
                        (identifier)))))))))))))

==================================
switch expressions added
==================================

class Test {
    int i;
    static void foo(int i, int j) {
        // switch expressions inside of a binary expression
        int x = switch (i) { default -> 1; } + switch (j) { default -> 2; };
    }
}

---

(program
  (class_declaration
    name: (identifier)
    body: (class_body
      (field_declaration
        type: (integral_type)
        declarator: (variable_declarator
          name: (identifier)))
      (method_declaration
        (modifiers)
        type: (void_type)
        name: (identifier)
        parameters: (formal_parameters
          (formal_parameter
            type: (integral_type)
            name: (identifier))
          (formal_parameter
            type: (integral_type)
            name: (identifier)))
        body: (block
          (line_comment)
          (local_variable_declaration
            type: (integral_type)
            declarator: (variable_declarator
              name: (identifier)
              value: (binary_expression
                left: (switch_expression
                  condition: (parenthesized_expression
                    (identifier))
                  body: (switch_block
                    (switch_rule
                      (switch_label)
                      (expression_statement
                        (decimal_integer_literal)))))
                right: (switch_expression
                  condition: (parenthesized_expression
                    (identifier))
                  body: (switch_block
                    (switch_rule
                      (switch_label)
                      (expression_statement
                        (decimal_integer_literal)))))))))))))

==================================
type arguments
==================================

class Box <T> {
  private T theObject;
  public Box( T arg) { theObject = arg; }
  // more code
}

---

(program
  (class_declaration
    (identifier)
      (type_parameters
        (type_parameter
          (type_identifier)))
    (class_body
      (field_declaration
        (modifiers)
          (type_identifier)
          (variable_declarator (identifier)))
      (constructor_declaration
        (modifiers)
        (identifier)
        (formal_parameters
          (formal_parameter
            (type_identifier)
            (identifier)))
        (constructor_body
          (expression_statement (assignment_expression
            (identifier)
              (identifier)))))
      (line_comment))))

==================================
wildcard
==================================

class WildcardDemo {
  List<? extends B> a;
}

---

(program
  (class_declaration
    (identifier)
      (class_body
        (field_declaration
          (generic_type
            (type_identifier)
            (type_arguments
              (wildcard (type_identifier))))
          (variable_declarator (identifier))))))

==================================
type arguments with generic types
==================================

class someClass <T> {
  public List<T> someMethod() {
     List< T > list = Collections.< T >emptyList();
     return list;
  }
  public static <S> void anotherMethod(S arg) {
     List< S > list = Collections.< S >emptyList();
  }
}

---

(program
  (class_declaration
    (identifier)
    (type_parameters
      (type_parameter
        (type_identifier)))
      (class_body
        (method_declaration
          (modifiers)
            (generic_type
              (type_identifier)
              (type_arguments (type_identifier)))
            (identifier)
            (formal_parameters)
            (block
              (local_variable_declaration
                (generic_type
                  (type_identifier)
                  (type_arguments (type_identifier)))
                (variable_declarator
                  (identifier)
                  (method_invocation
                    (identifier)
                    (type_arguments (type_identifier))
                    (identifier)
                    (argument_list))))
              (return_statement (identifier))))
        (method_declaration
          (modifiers)
          (type_parameters
            (type_parameter
              (type_identifier)))
          (void_type)
            (identifier)
            (formal_parameters
              (formal_parameter
                (type_identifier)
                (identifier)))
            (block
              (local_variable_declaration
                (generic_type
                  (type_identifier)
                  (type_arguments (type_identifier)))
                (variable_declarator
                  (identifier)
                  (method_invocation
                    (identifier)
                    (type_arguments (type_identifier))
                    (identifier)
                    (argument_list)))))))))

==================================
empty type arguments
==================================

Box<Integer> integerBox = new Box<>();

---

(program
  (local_variable_declaration
    (generic_type (type_identifier) (type_arguments (type_identifier)))
    (variable_declarator
      (identifier)
      (object_creation_expression
        (generic_type (type_identifier) (type_arguments))
        (argument_list)))))

=================
method references
=================

action = bar::method;
foo.bar::method;
String[]::new;
Foo<T>::apply;
super::something;

---

(program
  (expression_statement (assignment_expression (identifier) (method_reference (identifier) (identifier))))
  (expression_statement (method_reference (field_access (identifier) (identifier)) (identifier)))
  (expression_statement (method_reference (array_type (type_identifier) (dimensions))))
  (expression_statement (method_reference (generic_type (type_identifier) (type_arguments (type_identifier))) (identifier)))
  (expression_statement (method_reference (super) (identifier))))

================================================================================
Non-ascii identifiers
================================================================================

fügeKnotenEin = 1;
$cibleVisée2 = 2;

--------------------------------------------------------------------------------

(program
  (expression_statement
    (assignment_expression
      (identifier)
      (decimal_integer_literal)))
  (expression_statement
    (assignment_expression
      (identifier)
      (decimal_integer_literal))))
