本文整理汇总了Java中com.github.javaparser.ast.stmt.IfStmt.getThenStmt方法的典型用法代码示例。如果您正苦于以下问题:Java IfStmt.getThenStmt方法的具体用法?Java IfStmt.getThenStmt怎么用?Java IfStmt.getThenStmt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.javaparser.ast.stmt.IfStmt
的用法示例。
在下文中一共展示了IfStmt.getThenStmt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入方法依赖的package包/类
@Override
public void visit(final IfStmt n, final Object arg) {
printer.printLn("IfStmt");
printJavaComment(n.getComment(), arg);
printer.print("if (");
n.getCondition().accept(this, arg);
final boolean thenBlock = n.getThenStmt() instanceof BlockStmt;
if (thenBlock) // block statement should start on the same line
{
printer.print(") ");
} else {
printer.printLn(")");
printer.indent();
}
n.getThenStmt().accept(this, arg);
if (!thenBlock) {
printer.unindent();
}
if (n.getElseStmt() != null) {
if (thenBlock) {
printer.print(" ");
} else {
printer.printLn();
}
final boolean elseIf = n.getElseStmt() instanceof IfStmt;
final boolean elseBlock = n.getElseStmt() instanceof BlockStmt;
if (elseIf || elseBlock) // put chained if and start of block statement on a same level
{
printer.print("else ");
} else {
printer.printLn("else");
printer.indent();
}
n.getElseStmt().accept(this, arg);
if (!(elseIf || elseBlock)) {
printer.unindent();
}
}
}
示例2: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入方法依赖的package包/类
@Override public void visit(final IfStmt n, final Object arg) {
printJavaComment(n.getComment(), arg);
printer.print("if (");
n.getCondition().accept(this, arg);
final boolean thenBlock = n.getThenStmt() instanceof BlockStmt;
if (thenBlock) // block statement should start on the same line
printer.print(") ");
else {
printer.printLn(")");
printer.indent();
}
n.getThenStmt().accept(this, arg);
if (!thenBlock)
printer.unindent();
if (n.getElseStmt() != null) {
if (thenBlock)
printer.print(" ");
else
printer.printLn();
final boolean elseIf = n.getElseStmt() instanceof IfStmt;
final boolean elseBlock = n.getElseStmt() instanceof BlockStmt;
if (elseIf || elseBlock) // put chained if and start of block statement on a same level
printer.print("else ");
else {
printer.printLn("else");
printer.indent();
}
n.getElseStmt().accept(this, arg);
if (!(elseIf || elseBlock))
printer.unindent();
}
}
示例3: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入方法依赖的package包/类
@Override public void visit(final IfStmt n, final Object arg) {
printJavaComment(n.getComment(), arg);
printer.print("if (");
n.getCondition().accept(this, arg);
final boolean thenBlock = n.getThenStmt() instanceof BlockStmt;
if (thenBlock) // block statement should start on the same line
printer.print(") ");
else {
printer.printLn(")");
printer.indent();
}
n.getThenStmt().accept(this, arg);
if (!thenBlock)
printer.unindent();
if (n.getElseStmt() != null) {
if (thenBlock)
printer.print(" ");
else
printer.printLn();
final boolean elseIf = n.getElseStmt() instanceof IfStmt;
final boolean elseBlock = n.getElseStmt() instanceof BlockStmt;
if (elseIf || elseBlock) // put chained if and start of block statement on a same level
printer.print("else ");
else {
printer.printLn("else");
printer.indent();
}
n.getElseStmt().accept(this, arg);
if (!(elseIf || elseBlock))
printer.unindent();
}
}
示例4: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入方法依赖的package包/类
@Override
public void visit(final IfStmt n, final Void arg) {
boolean thenBlock = n.getThenStmt() instanceof BlockStmt;
while (thenBlock
&& !n.getElseStmt().isPresent()
&& ((BlockStmt) n.getThenStmt()).getStatements().size() == 1
&& !(n.getParentNode().orElse(null) instanceof IfStmt)) {
Statement stmt = ((BlockStmt) n.getThenStmt()).getStatements().get(0);
if (isBlockStmt(stmt) && !(stmt instanceof BlockStmt)) break;
n.setThenStmt(stmt);
thenBlock = n.getThenStmt() instanceof BlockStmt;
}
Node prev = getPrev(n);
if (thenBlock
&& (canAddNewLine(n) || prev instanceof IfStmt && !((IfStmt) prev).hasThenBlock())
&& !(n.getParentNode().orElse(null) instanceof IfStmt)) {
printer.println();
}
printJavaComment(n.getComment(), arg);
printer.print("if (");
n.getCondition().accept(this, arg);
printer.print(") ");
n.getThenStmt().accept(this, arg);
Node next = getNext(n);
if (n.getElseStmt().isPresent()) {
Statement elseStmt = n.getElseStmt().get();
if (thenBlock)
printer.print(" ");
else
printer.println();
final boolean elseIf = elseStmt instanceof IfStmt;
final boolean elseBlock = elseStmt instanceof BlockStmt;
if (elseIf || elseBlock) // put chained if and start of block statement on a same level
printer.print("else ");
else {
printer.println("else");
printer.indent();
}
elseStmt.accept(this, arg);
if (!(elseIf || elseBlock))
printer.unindent();
if (next != null) printer.println();
} else {
if (next != null && (thenBlock || !(next instanceof IfStmt))) printer.println();
}
}