/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A block of Java code, which may contain statements and local declarations.
*
* <p>
* {@link JBlock} contains a large number of factory methods that creates new
* statements/declarations. Those newly created statements/declarations are
* inserted into the {@link #pos() "current position"}. The position advances
* one every time you add a new instruction.
*/
/**
* Declarations and statements contained in this block.
* Either {@link JStatement} or {@link JDeclaration}.
*/
/**
* Whether or not this block must be braced and indented
*/
private boolean bracesRequired = true;
private boolean indentRequired = true;
/**
* Current position.
*/
private int pos;
public JBlock() {
this(true,true);
}
this.bracesRequired = bracesRequired;
this.indentRequired = indentRequired;
}
/**
* Returns a read-only view of {@link JStatement}s and {@link JDeclaration}
* in this block.
*/
}
pos++;
return statementOrDeclaration;
}
/**
* Gets the current position to which new statements will be inserted.
*
* For example if the value is 0, newly created instructions will be
* inserted at the very beginning of the block.
*
* @see #pos(int)
*/
public int pos() {
return pos;
}
/**
* Sets the current position.
*
* @return
* the old value of the current position.
* @throws IllegalArgumentException
* if the new position value is illegal.
*
* @see #pos()
*/
int r = pos;
throw new IllegalArgumentException();
return r;
}
/**
* Returns true if this block is empty and does not contain
* any statement.
*/
public boolean isEmpty() {
}
/**
* Adds a local variable declaration to this block
*
* @param type
* JType of the variable
*
* @param name
* Name of the variable
*
* @return Newly generated JVar
*/
}
/**
* Adds a local variable declaration to this block
*
* @param type
* JType of the variable
*
* @param name
* Name of the variable
*
* @param init
* Initialization expression for this variable. May be null.
*
* @return Newly generated JVar
*/
}
/**
* Adds a local variable declaration to this block
*
* @param mods
* Modifiers for the variable
*
* @param type
* JType of the variable
*
* @param name
* Name of the variable
*
* @param init
* Initialization expression for this variable. May be null.
*
* @return Newly generated JVar
*/
insert(v);
bracesRequired = true;
indentRequired = true;
return v;
}
/**
* Creates an assignment statement and adds it to this block.
*
* @param lhs
* Assignable variable or field for left hand side of expression
*
* @param exp
* Right hand side expression
*/
return this;
}
return this;
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param expr
* JExpression evaluating to the class or object upon which
* the named method will be invoked
*
* @param method
* Name of method to invoke
*
* @return Newly generated JInvocation
*/
insert(i);
return i;
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param expr
* JExpression evaluating to the class or object upon which
* the method will be invoked
*
* @param method
* JMethod to invoke
*
* @return Newly generated JInvocation
*/
}
/**
* Creates a static invocation statement.
*/
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param method
* Name of method to invoke
*
* @return Newly generated JInvocation
*/
}
/**
* Creates an invocation statement and adds it to this block.
*
* @param method
* JMethod to invoke
*
* @return Newly generated JInvocation
*/
}
/**
* Adds a statement to this block
*
* @param s
* JStatement to be added
*
* @return This block
*/
insert(s);
return this;
}
/**
* Create an If statement and add it to this block
*
* @param expr
* JExpression to be tested to determine branching
*
* @return Newly generated conditional statement
*/
}
/**
* Create a For statement and add it to this block
*
* @return Newly generated For statement
*/
}
/**
* Create a While statement and add it to this block
*
* @return Newly generated While statement
*/
}
/**
*/
}
/**
* Create a Do statement and add it to this block
*
* @return Newly generated Do statement
*/
}
/**
* Create a Try statement and add it to this block
*
* @return Newly generated Try statement
*/
}
/**
* Create a return statement and add it to this block
*/
public void _return() {
}
/**
* Create a return statement and add it to this block
*/
}
/**
* Create a throw statement and add it to this block
*/
}
/**
* Create a break statement and add it to this block
*/
public void _break() {
}
}
/**
* Create a label, which can be referenced from
* <code>continue</code> and <code>break</code> statements.
*/
insert(l);
return l;
}
/**
* Create a continue statement and add it to this block
*/
}
public void _continue() {
}
/**
* Create a sub-block and add it to this block
*/
b.bracesRequired = false;
b.indentRequired = false;
return insert(b);
}
/**
* Creates a "literal" statement directly.
*
* <p>
* Specified string is printed as-is.
* This is useful as a short-cut.
*
* <p>
* For example, you can invoke this method as:
* <code>directStatement("a=b+c;")</code>.
*/
JStatement s = new JStatement() {
public void state(JFormatter f) {
}
};
add(s);
return s;
}
if (bracesRequired)
f.p('{').nl();
if (indentRequired)
f.i();
generateBody(f);
if (indentRequired)
f.o();
if (bracesRequired)
f.p('}');
}
if (o instanceof JDeclaration)
f.d((JDeclaration) o);
else
f.s((JStatement) o);
}
}
/**
* Creates an enhanced For statement based on j2se 1.5 JLS
* and add it to this block
*
* @return Newly generated enhanced For statement per j2se 1.5
* specification
*/
}
f.g(this);
if (bracesRequired)
f.nl();
}
}