Class JavaStatement

java.lang.Object
com.regnosys.rosetta.generator.java.statement.JavaStatement
All Implemented Interfaces:
TargetLanguageRepresentation
Direct Known Subclasses:
JavaAssignment, JavaBlock, JavaExpressionStatement, JavaIfThenElseStatement, JavaIfThenStatement, JavaLocalVariableDeclarationStatement, JavaReturnStatement

public abstract class JavaStatement extends Object implements TargetLanguageRepresentation
A representation of a statement in Java. Examples: - a return statement `return foo;` - a local variable declaration: `int x = 42;` - an if-then statement: `if (cond) return foo;` - a block of statements: ``` { int x = 42; if (cond) return foo; return x; } ``` Based on the Java specification: https://docs.oracle.com/javase/specs/jls/se11/html/jls-14.html#jls-BlockStatement
  • Constructor Details

    • JavaStatement

      public JavaStatement()
  • Method Details

    • toBlock

      public JavaBlock toBlock()
      Convert this statement into a block enclosed by curly braces, if this statement is not already a block. For example, given the statement `return x;`, the following block statement will be returned: ``` { return x; } ```
    • asStatementList

      public JavaStatementList asStatementList()
    • prepend

      public JavaBlock prepend(JavaStatement other)
    • append

      public JavaBlock append(JavaStatement other)
      Append the given statement to this one. Behaves the same as `other.prepend(this)`. This operation flattens block statements. Examples: - given the statements `int x = 42;` and `return x;`, appending the latter to the former results in the following block: ``` { int x = 42; return x; } ``` - given a statement `int x = 42;` and a block ``` { int y = x + 1; return y; } ``` appending the latter to the former results in the following block: ``` { int x = 42; int y = x + 1; return y; } ```