com.sun.codemodel.JConditional Maven / Gradle / Ivy
Go to download
Old JAXB Binding Compiler. Contains source code needed for binding customization files into java sources.
In other words: the *tool* to generate java classes for the given xml representation.
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://jwsdp.dev.java.net/CDDLv1.0.html
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
* add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your
* own identifying information: Portions Copyright [yyyy]
* [name of copyright owner]
*/
package com.sun.codemodel;
/**
* If statement, with optional else clause
*/
public class JConditional implements JStatement {
/**
* JExpression to test to determine branching
*/
private JExpression test = null;
/**
* JBlock of statements for "then" clause
*/
private JBlock _then = new JBlock();
/**
* JBlock of statements for optional "else" clause
*/
private JBlock _else = null;
/**
* Constructor
*
* @param test
* JExpression which will determine branching
*/
JConditional(JExpression test) {
this.test = test;
}
/**
* Return the block to be excuted by the "then" branch
*
* @return Then block
*/
public JBlock _then() {
return _then;
}
/**
* Create a block to be executed by "else" branch
*
* @return Newly generated else block
*/
public JBlock _else() {
if (_else == null) _else = new JBlock();
return _else;
}
/**
* Creates ... else if(...) ... code.
*/
public JConditional _elseif(JExpression boolExp) {
return _else()._if(boolExp);
}
public void state(JFormatter f) {
if(test==JExpr.TRUE) {
_then.generateBody(f);
return;
}
if(test==JExpr.FALSE) {
_else.generateBody(f);
return;
}
if (JOp.hasTopOp(test)) {
f.p("if ").g(test);
} else {
f.p("if (").g(test).p(')');
}
f.g(_then);
if (_else != null)
f.p("else").g(_else);
f.nl();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy