本文整理汇总了Java中com.github.javaparser.ast.stmt.IfStmt类的典型用法代码示例。如果您正苦于以下问题:Java IfStmt类的具体用法?Java IfStmt怎么用?Java IfStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IfStmt类属于com.github.javaparser.ast.stmt包,在下文中一共展示了IfStmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public Node visit(final IfStmt n, final A arg) {
visitComment(n, arg);
final Expression condition = (Expression)
n.getCondition().accept(this, arg);
if (condition == null) {
return null;
}
n.setCondition(condition);
final Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg);
if (thenStmt == null) {
// Remove the entire statement if the then-clause was removed.
// DumpVisitor, used for toString, has no null check for the
// then-clause.
return null;
}
n.setThenStmt(thenStmt);
if (n.getElseStmt() != null) {
n.setElseStmt((Statement) n.getElseStmt().accept(this, arg));
}
return n;
}
示例2: parseIfStatement
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
/**
*
* @param is
* a github javaparser IfStatement
* @param attributes
* the list of attributes of the class,
* to potentially get a type from the name
* @param bd
* a body declaration
* @return
* an IfStatement structure
*/
private IfStatement parseIfStatement(IfStmt is, List<Attribute> attributes, BodyDeclaration bd) {
IfStatement ifSt = new IfStatement();
List<Stmt> body = new ArrayList<>();
ifSt.setCondition(parseExpression(is.getCondition(), attributes, bd.getBeginLine()));
body.addAll(parseStatement(is.getThenStmt(), attributes, bd));
if (is.getElseStmt() != null) {
List<Stmt> elsStmts = new ArrayList<>();
elsStmts.addAll(parseStatement(is.getElseStmt(), attributes, bd));
ifSt.setElseStmt(elsStmts);
}
ifSt.setBody(body);
ifSt.setLine(is.getBeginLine() - bd.getBeginLine());
return ifSt;
}
示例3: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public Boolean visit(final IfStmt n1, final Node arg) {
final IfStmt n2 = (IfStmt) arg;
if (!nodeEquals(n1.getCondition(), n2.getCondition())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getThenStmt(), n2.getThenStmt())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getElseStmt(), n2.getElseStmt())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例4: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public Boolean visit(final IfStmt n1, final Node arg) {
final IfStmt n2 = (IfStmt) arg;
if (!nodeEquals(n1.getCondition(), n2.getCondition())) {
return false;
}
if (!nodeEquals(n1.getThenStmt(), n2.getThenStmt())) {
return false;
}
if (!nodeEquals(n1.getElseStmt(), n2.getElseStmt())) {
return false;
}
return true;
}
示例5: isBlockStmt
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
private static boolean isBlockStmt(Node n) {
return n instanceof BlockStmt
|| n instanceof DoStmt
|| n instanceof ForStmt
|| n instanceof ForeachStmt
|| n instanceof IfStmt
|| n instanceof SwitchStmt
|| n instanceof TryStmt
|| n instanceof WhileStmt;
}
示例6: 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();
}
}
}
示例7: doMerge
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public IfStmt doMerge(IfStmt first, IfStmt second) {
IfStmt is = new IfStmt();
is.setCondition(mergeSingle(first.getCondition(),second.getCondition()));
is.setElseStmt(mergeSingle(first.getElseStmt(),second.getElseStmt()));
is.setThenStmt(mergeSingle(first.getThenStmt(),second.getThenStmt()));
return is;
}
示例8: doIsEquals
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public boolean doIsEquals(IfStmt first, IfStmt second) {
if(!isEqualsUseMerger(first.getCondition(),second.getCondition())) return false;
if(!isEqualsUseMerger(first.getElseStmt(),second.getElseStmt())) return false;
if(!isEqualsUseMerger(first.getThenStmt(),second.getThenStmt())) return false;
return true;
}
示例9: 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();
}
}
示例10: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public void visit(final IfStmt n, final A arg) {
visitComment(n.getComment(), arg);
n.getCondition().accept(this, arg);
n.getThenStmt().accept(this, arg);
if (n.getElseStmt() != null) {
n.getElseStmt().accept(this, arg);
}
}
示例11: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public void visit(final IfStmt n, final A arg) {
jw.write(n);
visitComment(n.getComment(), arg);
n.getCondition().accept(this, arg);
n.getThenStmt().accept(this, arg);
if (n.getElseStmt() != null) {
n.getElseStmt().accept(this, arg);
}
}
示例12: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override public Node visit(final IfStmt n, final A arg) {
n.setCondition((Expression) n.getCondition().accept(this, arg));
n.setThenStmt((Statement) n.getThenStmt().accept(this, arg));
if (n.getElseStmt() != null) {
n.setElseStmt((Statement) n.getElseStmt().accept(this, arg));
}
return n;
}
示例13: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override
public Node visit(IfStmt _n, Object _arg) {
Expression condition = cloneNodes(_n.getCondition(), _arg);
Statement thenStmt = cloneNodes(_n.getThenStmt(), _arg);
Statement elseStmt = cloneNodes(_n.getElseStmt(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
IfStmt r = new IfStmt(
_n.getRange(),
condition, thenStmt, elseStmt
);
r.setComment(comment);
return r;
}
示例14: 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();
}
}
示例15: visit
import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override
public Node visit(
IfStmt n, Map<Node, Node> arg
) {
if (arg.containsKey(n)) {
return arg.get(n);
}
return super.visit(n, arg);
}