Interface JBlock

All Superinterfaces:
JCommentable, JStatement
All Known Subinterfaces:
JCatch, JFor, JIf, JTry

public interface JBlock extends JStatement, JCommentable
A block of code, to which statements may be added.
Author:
David M. Lloyd
  • Method Details

    • blankLine

      JBlock blankLine()
      Insert a blank line at this point.
      Returns:
      this block
    • block

      JBlock block(JBlock.Braces braces)
      Create a nested sub-block at this point.
      Parameters:
      braces - the rule for adding braces
      Returns:
      the nested block
    • _if

      JIf _if(JExpr cond)
      Insert an if statement at this point.
      Parameters:
      cond - the if condition
      Returns:
      the if statement
    • _while

      JBlock _while(JExpr cond)
      Insert a while statement at this point.
      Parameters:
      cond - the while condition
      Returns:
      the while statement
    • _do

      JBlock _do(JExpr cond)
      Insert a do/while statement at this point.
      Parameters:
      cond - the while condition
      Returns:
      the while statement
    • label

      JLabel label(String name)
      Add a label at this point, which may be used for future branch instructions.
      Parameters:
      name - the label name
      Returns:
      the label
    • anonLabel

      JLabel anonLabel()
      Add a label at this point whose unique name is automatically generated.
      Returns:
      the label
    • forwardLabel

      JLabel forwardLabel()
      Create a forward label that can be named and attached later.
      Returns:
      the forward label
    • label

      JLabel label(JLabel label, String name)
      Name and attach a forward label.
      Parameters:
      label - the label to name and attach
      name - the label name
      Returns:
      the attached label
    • anonLabel

      JLabel anonLabel(JLabel label)
      Name and attach a forward label as anonymous.
      Parameters:
      label - the label to name and attach
      Returns:
      the attached label
    • _continue

      JStatement _continue()
      Insert a continue statement at this point.
      Returns:
      the statement
    • _continue

      JStatement _continue(JLabel label)
      Insert a labelled continue statement at this point.
      Parameters:
      label - the label
      Returns:
      the statement
    • _break

      JStatement _break()
      Insert a break statement at this point.
      Returns:
      the statement
    • _break

      JStatement _break(JLabel label)
      Insert a labelled break statement at this point.
      Parameters:
      label - the label
      Returns:
      the statement
    • forEach

      JBlock forEach(int mods, String type, String name, JExpr iterable)
      Insert a "for-each" style for loop at this point.
      Parameters:
      mods - the item variable modifiers
      type - the item variable type
      name - the item variable name
      iterable - the iterable or array expression
      Returns:
      the body of the for loop
    • forEach

      JBlock forEach(int mods, JType type, String name, JExpr iterable)
      Insert a "for-each" style for loop at this point.
      Parameters:
      mods - the item variable modifiers
      type - the item variable type
      name - the item variable name
      iterable - the iterable or array expression
      Returns:
      the body of the for loop
    • forEach

      JBlock forEach(int mods, Class<?> type, String name, JExpr iterable)
      Insert a "for-each" style for loop at this point.
      Parameters:
      mods - the item variable modifiers
      type - the item variable type
      name - the item variable name
      iterable - the iterable or array expression
      Returns:
      the body of the for loop
    • _for

      JFor _for()
      Insert a for loop at this point.
      Returns:
      the for loop
    • _switch

      JSwitch _switch(JExpr expr)
      Insert a switch statement at this point.
      Parameters:
      expr - the switch expression
      Returns:
      the switch statement
    • _return

      JStatement _return(JExpr expr)
      Insert a return statement at this point.
      Parameters:
      expr - the expression to return
      Returns:
      the statement
    • _return

      JStatement _return()
      Insert a void return statement at this point.
      Returns:
      the statement
    • _assert

      JStatement _assert(JExpr expr)
      Insert an assert statement at this point.
      Parameters:
      expr - the expression to assert
      Returns:
      the statement
    • _assert

      JStatement _assert(JExpr expr, JExpr message)
      Insert an assert statement at this point with a message.
      Parameters:
      expr - the expression to assert
      message - the assertion message
      Returns:
      the statement
    • callThis

      JCall callThis()
      Insert a this() call at this point.
      Returns:
      the call
    • callSuper

      JCall callSuper()
      Insert a super() call at this point.
      Returns:
      the call
    • add

      JStatement add(JExpr expr)
      Insert an expression statement at this point. Expressions which are invalid statements may generate an error at the time this method is called, or at compile time.
      Parameters:
      expr - the expression to add
      Returns:
      the statement
    • call

      JCall call(ExecutableElement element)
      Insert a method invocation at this point. Note that these two invocations are identical:
      
          block.call(element);
          block.add(JExprs.call(element));
      
      Parameters:
      element - the program element whose name to use
      Returns:
      the method call
    • call

      JCall call(JExpr obj, ExecutableElement element)
      Insert a method invocation at this point.
      Parameters:
      obj - the expression upon which to invoke
      element - the program element whose name to use
      Returns:
      the method call
    • call

      JCall call(String name)
      Insert a method invocation at this point. Note that these two invocations are identical:
      
          block.call(methodName);
          block.add(JExprs.call(methodName));
      
      Parameters:
      name - the method name
      Returns:
      the method call
    • call

      JCall call(JExpr obj, String name)
      Insert a method invocation at this point.
      Parameters:
      obj - the expression upon which to invoke
      name - the method name
      Returns:
      the method call
    • callStatic

      JCall callStatic(ExecutableElement element)
      Insert a type-qualified static method invocation at this point.
      Parameters:
      element - the program element whose name and type to use
      Returns:
      the method call
    • callStatic

      JCall callStatic(String type, String name)
      Insert a type-qualified static method invocation at this point.
      Parameters:
      type - the type upon which to invoke
      name - the method name
      Returns:
      the method call
    • callStatic

      JCall callStatic(JType type, String name)
      Insert a type-qualified static method invocation at this point.
      Parameters:
      type - the type upon which to invoke
      name - the method name
      Returns:
      the method call
    • callStatic

      JCall callStatic(Class<?> type, String name)
      Insert a type-qualified static method invocation at this point.
      Parameters:
      type - the type upon which to invoke
      name - the method name
      Returns:
      the method call
    • _new

      JCall _new(String type)
      Insert an object construction statement at this point.
      Parameters:
      type - the type to instantiate
      Returns:
      the constructor call
    • _new

      JCall _new(JType type)
      Insert an object construction statement at this point.
      Parameters:
      type - the type to instantiate
      Returns:
      the constructor call
    • _new

      JCall _new(Class<?> type)
      Insert an object construction statement at this point.
      Parameters:
      type - the type to instantiate
      Returns:
      the constructor call
    • _newAnon

      JAnonymousClassDef _newAnon(String type)
      Insert an object construction statement for an anonymous class at this point.
      Parameters:
      type - the type to instantiate
      Returns:
      the anonymous class definition
    • _newAnon

      JAnonymousClassDef _newAnon(JType type)
      Insert an object construction statement for an anonymous class at this point.
      Parameters:
      type - the type to instantiate
      Returns:
      the anonymous class definition
    • _newAnon

      JAnonymousClassDef _newAnon(Class<?> type)
      Insert an object construction statement for an anonymous class at this point.
      Parameters:
      type - the type to instantiate
      Returns:
      the anonymous class definition
    • _class

      JClassDef _class(int mods, String name)
      Insert a local class definition at this point.
      Parameters:
      mods - the class modifiers
      name - the local class name
      Returns:
      the local class definition
    • _synchronized

      JBlock _synchronized(JExpr synchExpr)
      Insert a synchronized block at this point.
      Parameters:
      synchExpr - the lock expression
      Returns:
      the synchronized block
    • assign

      JStatement assign(JAssignableExpr target, JExpr e1)
      Insert an assignment (=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • addAssign

      JStatement addAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (+=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • subAssign

      JStatement subAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (-=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • mulAssign

      JStatement mulAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (*=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • divAssign

      JStatement divAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (/=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • modAssign

      JStatement modAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (%=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • andAssign

      JStatement andAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (&=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • orAssign

      JStatement orAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (|=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • xorAssign

      JStatement xorAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (^=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • shrAssign

      JStatement shrAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (>>=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • lshrAssign

      JStatement lshrAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (>>>=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • shlAssign

      JStatement shlAssign(JAssignableExpr target, JExpr e1)
      Insert an assignment (<<=) expression at this point.
      Parameters:
      target - the assignment target
      e1 - the expression to apply
      Returns:
      the statement
    • postInc

      JStatement postInc(JAssignableExpr target)
      Insert a postfix ++ expression at this point.
      Parameters:
      target - the target expression
      Returns:
      the statement
    • postDec

      JStatement postDec(JAssignableExpr target)
      Insert a postfix -- expression at this point.
      Parameters:
      target - the target expression
      Returns:
      the statement
    • preInc

      JStatement preInc(JAssignableExpr target)
      Insert a prefix ++ expression at this point.
      Parameters:
      target - the target expression
      Returns:
      the statement
    • preDec

      JStatement preDec(JAssignableExpr target)
      Insert a prefix -- expression at this point.
      Parameters:
      target - the target expression
      Returns:
      the statement
    • empty

      JStatement empty()
      Insert an empty statement at this point (just a semicolon).
      Returns:
      the statement
    • _throw

      JStatement _throw(JExpr expr)
      Insert a throw statement at this point.
      Parameters:
      expr - the expression to throw
      Returns:
      the statement
    • _try

      JTry _try()
      Insert a try block at this point.
      Returns:
      the try block
    • var

      JVarDeclaration var(int mods, String type, String name, JExpr value)
      Insert a local variable declaration at this point.
      Parameters:
      mods - the variable modifiers
      type - the local variable type
      name - the local variable name
      value - the local variable's initializer expression
      Returns:
      the local variable declaration
    • var

      JVarDeclaration var(int mods, JType type, String name, JExpr value)
      Insert a local variable declaration at this point.
      Parameters:
      mods - the variable modifiers
      type - the local variable type
      name - the local variable name
      value - the local variable's initializer expression
      Returns:
      the local variable declaration
    • var

      JVarDeclaration var(int mods, Class<?> type, String name, JExpr value)
      Insert a local variable declaration at this point.
      Parameters:
      mods - the variable modifiers
      type - the local variable type
      name - the local variable name
      value - the local variable's initializer expression
      Returns:
      the local variable declaration
    • var

      JVarDeclaration var(int mods, String type, String name)
      Insert a local variable declaration at this point.
      Parameters:
      mods - the variable modifiers
      type - the local variable type
      name - the local variable name
      Returns:
      the local variable declaration
    • var

      JVarDeclaration var(int mods, JType type, String name)
      Insert a local variable declaration at this point.
      Parameters:
      mods - the variable modifiers
      type - the local variable type
      name - the local variable name
      Returns:
      the local variable declaration
    • var

      JVarDeclaration var(int mods, Class<?> type, String name)
      Insert a local variable declaration at this point.
      Parameters:
      mods - the variable modifiers
      type - the local variable type
      name - the local variable name
      Returns:
      the local variable declaration
    • tempVar

      JExpr tempVar(String type, JExpr value)
      Insert a local variable declaration at this point with a generated name.
      Parameters:
      type - the local variable type
      value - the local variable's initializer expression
      Returns:
      the local variable expression
    • tempVar

      JExpr tempVar(JType type, JExpr value)
      Insert a local variable declaration at this point with a generated name.
      Parameters:
      type - the local variable type
      value - the local variable's initializer expression
      Returns:
      the local variable expression
    • tempVar

      JExpr tempVar(Class<?> type, JExpr value)
      Insert a local variable declaration at this point with a generated name.
      Parameters:
      type - the local variable type
      value - the local variable's initializer expression
      Returns:
      the local variable expression
    • tempName

      String tempName()
      Generate a temporary variable name.
      Returns:
      the generated name