Class BasicJBlock

    • Method Detail

      • blankLine

        public JBlock blankLine()
        Description copied from interface: JBlock
        Insert a blank line at this point.
        Specified by:
        blankLine in interface JBlock
        Returns:
        this block
      • block

        public JBlock block​(JBlock.Braces braces)
        Description copied from interface: JBlock
        Create a nested sub-block at this point.
        Specified by:
        block in interface JBlock
        Parameters:
        braces - the rule for adding braces
        Returns:
        the nested block
      • _if

        public JIf _if​(JExpr cond)
        Description copied from interface: JBlock
        Insert an if statement at this point.
        Specified by:
        _if in interface JBlock
        Parameters:
        cond - the if condition
        Returns:
        the if statement
      • _while

        public JBlock _while​(JExpr cond)
        Description copied from interface: JBlock
        Insert a while statement at this point.
        Specified by:
        _while in interface JBlock
        Parameters:
        cond - the while condition
        Returns:
        the while statement
      • _do

        public JBlock _do​(JExpr cond)
        Description copied from interface: JBlock
        Insert a do/while statement at this point.
        Specified by:
        _do in interface JBlock
        Parameters:
        cond - the while condition
        Returns:
        the while statement
      • label

        public JLabel label​(java.lang.String name)
        Description copied from interface: JBlock
        Add a label at this point, which may be used for future branch instructions.
        Specified by:
        label in interface JBlock
        Parameters:
        name - the label name
        Returns:
        the label
      • anonLabel

        public JLabel anonLabel()
        Description copied from interface: JBlock
        Add a label at this point whose unique name is automatically generated.
        Specified by:
        anonLabel in interface JBlock
        Returns:
        the label
      • forwardLabel

        public JLabel forwardLabel()
        Description copied from interface: JBlock
        Create a forward label that can be named and attached later.
        Specified by:
        forwardLabel in interface JBlock
        Returns:
        the forward label
      • label

        public JLabel label​(JLabel label,
                            java.lang.String name)
        Description copied from interface: JBlock
        Name and attach a forward label.
        Specified by:
        label in interface JBlock
        Parameters:
        label - the label to name and attach
        name - the label name
        Returns:
        the attached label
      • anonLabel

        public JLabel anonLabel​(JLabel label)
        Description copied from interface: JBlock
        Name and attach a forward label as anonymous.
        Specified by:
        anonLabel in interface JBlock
        Parameters:
        label - the label to name and attach
        Returns:
        the attached label
      • _continue

        public JStatement _continue()
        Description copied from interface: JBlock
        Insert a continue statement at this point.
        Specified by:
        _continue in interface JBlock
        Returns:
        the statement
      • _continue

        public JStatement _continue​(JLabel label)
        Description copied from interface: JBlock
        Insert a labelled continue statement at this point.
        Specified by:
        _continue in interface JBlock
        Parameters:
        label - the label
        Returns:
        the statement
      • _break

        public JStatement _break()
        Description copied from interface: JBlock
        Insert a break statement at this point.
        Specified by:
        _break in interface JBlock
        Returns:
        the statement
      • _break

        public JStatement _break​(JLabel label)
        Description copied from interface: JBlock
        Insert a labelled break statement at this point.
        Specified by:
        _break in interface JBlock
        Parameters:
        label - the label
        Returns:
        the statement
      • forEach

        public JBlock forEach​(int mods,
                              java.lang.String type,
                              java.lang.String name,
                              JExpr iterable)
        Description copied from interface: JBlock
        Insert a "for-each" style for loop at this point.
        Specified by:
        forEach in interface JBlock
        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

        public JBlock forEach​(int mods,
                              JType type,
                              java.lang.String name,
                              JExpr iterable)
        Description copied from interface: JBlock
        Insert a "for-each" style for loop at this point.
        Specified by:
        forEach in interface JBlock
        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

        public JBlock forEach​(int mods,
                              java.lang.Class<?> type,
                              java.lang.String name,
                              JExpr iterable)
        Description copied from interface: JBlock
        Insert a "for-each" style for loop at this point.
        Specified by:
        forEach in interface JBlock
        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

        public JFor _for()
        Description copied from interface: JBlock
        Insert a for loop at this point.
        Specified by:
        _for in interface JBlock
        Returns:
        the for loop
      • _switch

        public JSwitch _switch​(JExpr expr)
        Description copied from interface: JBlock
        Insert a switch statement at this point.
        Specified by:
        _switch in interface JBlock
        Parameters:
        expr - the switch expression
        Returns:
        the switch statement
      • _return

        public JStatement _return​(JExpr expr)
        Description copied from interface: JBlock
        Insert a return statement at this point.
        Specified by:
        _return in interface JBlock
        Parameters:
        expr - the expression to return
        Returns:
        the statement
      • _return

        public JStatement _return()
        Description copied from interface: JBlock
        Insert a void return statement at this point.
        Specified by:
        _return in interface JBlock
        Returns:
        the statement
      • _assert

        public JStatement _assert​(JExpr expr)
        Description copied from interface: JBlock
        Insert an assert statement at this point.
        Specified by:
        _assert in interface JBlock
        Parameters:
        expr - the expression to assert
        Returns:
        the statement
      • _assert

        public JStatement _assert​(JExpr expr,
                                  JExpr message)
        Description copied from interface: JBlock
        Insert an assert statement at this point with a message.
        Specified by:
        _assert in interface JBlock
        Parameters:
        expr - the expression to assert
        message - the assertion message
        Returns:
        the statement
      • callThis

        public JCall callThis()
        Description copied from interface: JBlock
        Insert a this() call at this point.
        Specified by:
        callThis in interface JBlock
        Returns:
        the call
      • callSuper

        public JCall callSuper()
        Description copied from interface: JBlock
        Insert a super() call at this point.
        Specified by:
        callSuper in interface JBlock
        Returns:
        the call
      • add

        public JStatement add​(JExpr expr)
        Description copied from interface: JBlock
        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.
        Specified by:
        add in interface JBlock
        Parameters:
        expr - the expression to add
        Returns:
        the statement
      • call

        public JCall call​(javax.lang.model.element.ExecutableElement element)
        Description copied from interface: JBlock
        Insert a method invocation at this point. Note that these two invocations are identical:
        
            block.call(element);
            block.add(JExprs.call(element));
        
        Specified by:
        call in interface JBlock
        Parameters:
        element - the program element whose name to use
        Returns:
        the method call
      • call

        public JCall call​(JExpr obj,
                          javax.lang.model.element.ExecutableElement element)
        Description copied from interface: JBlock
        Insert a method invocation at this point.
        Specified by:
        call in interface JBlock
        Parameters:
        obj - the expression upon which to invoke
        element - the program element whose name to use
        Returns:
        the method call
      • call

        public JCall call​(java.lang.String name)
        Description copied from interface: JBlock
        Insert a method invocation at this point. Note that these two invocations are identical:
        
            block.call(methodName);
            block.add(JExprs.call(methodName));
        
        Specified by:
        call in interface JBlock
        Parameters:
        name - the method name
        Returns:
        the method call
      • call

        public JCall call​(JExpr obj,
                          java.lang.String name)
        Description copied from interface: JBlock
        Insert a method invocation at this point.
        Specified by:
        call in interface JBlock
        Parameters:
        obj - the expression upon which to invoke
        name - the method name
        Returns:
        the method call
      • callStatic

        public JCall callStatic​(javax.lang.model.element.ExecutableElement element)
        Description copied from interface: JBlock
        Insert a type-qualified static method invocation at this point.
        Specified by:
        callStatic in interface JBlock
        Parameters:
        element - the program element whose name and type to use
        Returns:
        the method call
      • callStatic

        public JCall callStatic​(java.lang.String type,
                                java.lang.String name)
        Description copied from interface: JBlock
        Insert a type-qualified static method invocation at this point.
        Specified by:
        callStatic in interface JBlock
        Parameters:
        type - the type upon which to invoke
        name - the method name
        Returns:
        the method call
      • callStatic

        public JCall callStatic​(JType type,
                                java.lang.String name)
        Description copied from interface: JBlock
        Insert a type-qualified static method invocation at this point.
        Specified by:
        callStatic in interface JBlock
        Parameters:
        type - the type upon which to invoke
        name - the method name
        Returns:
        the method call
      • callStatic

        public JCall callStatic​(java.lang.Class<?> type,
                                java.lang.String name)
        Description copied from interface: JBlock
        Insert a type-qualified static method invocation at this point.
        Specified by:
        callStatic in interface JBlock
        Parameters:
        type - the type upon which to invoke
        name - the method name
        Returns:
        the method call
      • _new

        public JCall _new​(java.lang.String type)
        Description copied from interface: JBlock
        Insert an object construction statement at this point.
        Specified by:
        _new in interface JBlock
        Parameters:
        type - the type to instantiate
        Returns:
        the constructor call
      • _new

        public JCall _new​(JType type)
        Description copied from interface: JBlock
        Insert an object construction statement at this point.
        Specified by:
        _new in interface JBlock
        Parameters:
        type - the type to instantiate
        Returns:
        the constructor call
      • _new

        public JCall _new​(java.lang.Class<?> type)
        Description copied from interface: JBlock
        Insert an object construction statement at this point.
        Specified by:
        _new in interface JBlock
        Parameters:
        type - the type to instantiate
        Returns:
        the constructor call
      • _newAnon

        public JAnonymousClassDef _newAnon​(java.lang.String type)
        Description copied from interface: JBlock
        Insert an object construction statement for an anonymous class at this point.
        Specified by:
        _newAnon in interface JBlock
        Parameters:
        type - the type to instantiate
        Returns:
        the anonymous class definition
      • _newAnon

        public JAnonymousClassDef _newAnon​(JType type)
        Description copied from interface: JBlock
        Insert an object construction statement for an anonymous class at this point.
        Specified by:
        _newAnon in interface JBlock
        Parameters:
        type - the type to instantiate
        Returns:
        the anonymous class definition
      • _newAnon

        public JAnonymousClassDef _newAnon​(java.lang.Class<?> type)
        Description copied from interface: JBlock
        Insert an object construction statement for an anonymous class at this point.
        Specified by:
        _newAnon in interface JBlock
        Parameters:
        type - the type to instantiate
        Returns:
        the anonymous class definition
      • _class

        public JClassDef _class​(int mods,
                                java.lang.String name)
        Description copied from interface: JBlock
        Insert a local class definition at this point.
        Specified by:
        _class in interface JBlock
        Parameters:
        mods - the class modifiers
        name - the local class name
        Returns:
        the local class definition
      • _synchronized

        public JBlock _synchronized​(JExpr synchExpr)
        Description copied from interface: JBlock
        Insert a synchronized block at this point.
        Specified by:
        _synchronized in interface JBlock
        Parameters:
        synchExpr - the lock expression
        Returns:
        the synchronized block
      • assign

        public JStatement assign​(JAssignableExpr target,
                                 JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (=) expression at this point.
        Specified by:
        assign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • addAssign

        public JStatement addAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (+=) expression at this point.
        Specified by:
        addAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • subAssign

        public JStatement subAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (-=) expression at this point.
        Specified by:
        subAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • mulAssign

        public JStatement mulAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (*=) expression at this point.
        Specified by:
        mulAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • divAssign

        public JStatement divAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (/=) expression at this point.
        Specified by:
        divAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • modAssign

        public JStatement modAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (%=) expression at this point.
        Specified by:
        modAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • andAssign

        public JStatement andAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (&=) expression at this point.
        Specified by:
        andAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • orAssign

        public JStatement orAssign​(JAssignableExpr target,
                                   JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (|=) expression at this point.
        Specified by:
        orAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • xorAssign

        public JStatement xorAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (^=) expression at this point.
        Specified by:
        xorAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • shrAssign

        public JStatement shrAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (>>=) expression at this point.
        Specified by:
        shrAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • lshrAssign

        public JStatement lshrAssign​(JAssignableExpr target,
                                     JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (>>>=) expression at this point.
        Specified by:
        lshrAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • shlAssign

        public JStatement shlAssign​(JAssignableExpr target,
                                    JExpr e1)
        Description copied from interface: JBlock
        Insert an assignment (<<=) expression at this point.
        Specified by:
        shlAssign in interface JBlock
        Parameters:
        target - the assignment target
        e1 - the expression to apply
        Returns:
        the statement
      • postInc

        public JStatement postInc​(JAssignableExpr target)
        Description copied from interface: JBlock
        Insert a postfix ++ expression at this point.
        Specified by:
        postInc in interface JBlock
        Parameters:
        target - the target expression
        Returns:
        the statement
      • postDec

        public JStatement postDec​(JAssignableExpr target)
        Description copied from interface: JBlock
        Insert a postfix -- expression at this point.
        Specified by:
        postDec in interface JBlock
        Parameters:
        target - the target expression
        Returns:
        the statement
      • preInc

        public JStatement preInc​(JAssignableExpr target)
        Description copied from interface: JBlock
        Insert a prefix ++ expression at this point.
        Specified by:
        preInc in interface JBlock
        Parameters:
        target - the target expression
        Returns:
        the statement
      • preDec

        public JStatement preDec​(JAssignableExpr target)
        Description copied from interface: JBlock
        Insert a prefix -- expression at this point.
        Specified by:
        preDec in interface JBlock
        Parameters:
        target - the target expression
        Returns:
        the statement
      • empty

        public JStatement empty()
        Description copied from interface: JBlock
        Insert an empty statement at this point (just a semicolon).
        Specified by:
        empty in interface JBlock
        Returns:
        the statement
      • _throw

        public JStatement _throw​(JExpr expr)
        Description copied from interface: JBlock
        Insert a throw statement at this point.
        Specified by:
        _throw in interface JBlock
        Parameters:
        expr - the expression to throw
        Returns:
        the statement
      • _try

        public JTry _try()
        Description copied from interface: JBlock
        Insert a try block at this point.
        Specified by:
        _try in interface JBlock
        Returns:
        the try block
      • var

        public JVarDeclaration var​(int mods,
                                   java.lang.String type,
                                   java.lang.String name,
                                   JExpr value)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point.
        Specified by:
        var in interface JBlock
        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

        public JVarDeclaration var​(int mods,
                                   JType type,
                                   java.lang.String name,
                                   JExpr value)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point.
        Specified by:
        var in interface JBlock
        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

        public JVarDeclaration var​(int mods,
                                   java.lang.Class<?> type,
                                   java.lang.String name,
                                   JExpr value)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point.
        Specified by:
        var in interface JBlock
        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

        public JVarDeclaration var​(int mods,
                                   java.lang.String type,
                                   java.lang.String name)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point.
        Specified by:
        var in interface JBlock
        Parameters:
        mods - the variable modifiers
        type - the local variable type
        name - the local variable name
        Returns:
        the local variable declaration
      • var

        public JVarDeclaration var​(int mods,
                                   JType type,
                                   java.lang.String name)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point.
        Specified by:
        var in interface JBlock
        Parameters:
        mods - the variable modifiers
        type - the local variable type
        name - the local variable name
        Returns:
        the local variable declaration
      • var

        public JVarDeclaration var​(int mods,
                                   java.lang.Class<?> type,
                                   java.lang.String name)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point.
        Specified by:
        var in interface JBlock
        Parameters:
        mods - the variable modifiers
        type - the local variable type
        name - the local variable name
        Returns:
        the local variable declaration
      • tempVar

        public JExpr tempVar​(java.lang.String type,
                             JExpr value)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point with a generated name.
        Specified by:
        tempVar in interface JBlock
        Parameters:
        type - the local variable type
        value - the local variable's initializer expression
        Returns:
        the local variable expression
      • tempVar

        public JExpr tempVar​(JType type,
                             JExpr value)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point with a generated name.
        Specified by:
        tempVar in interface JBlock
        Parameters:
        type - the local variable type
        value - the local variable's initializer expression
        Returns:
        the local variable expression
      • tempVar

        public JExpr tempVar​(java.lang.Class<?> type,
                             JExpr value)
        Description copied from interface: JBlock
        Insert a local variable declaration at this point with a generated name.
        Specified by:
        tempVar in interface JBlock
        Parameters:
        type - the local variable type
        value - the local variable's initializer expression
        Returns:
        the local variable expression
      • tempName

        public java.lang.String tempName()
        Description copied from interface: JBlock
        Generate a temporary variable name.
        Specified by:
        tempName in interface JBlock
        Returns:
        the generated name
      • size

        int size()
      • write

        public void write​(SourceFileWriter writer)
                   throws java.io.IOException
        Specified by:
        write in interface Writable
        Throws:
        java.io.IOException
      • hasSingleItemOfType

        boolean hasSingleItemOfType​(java.lang.Class<? extends BlockContent> type)