• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java IfStmt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.github.javaparser.ast.stmt.IfStmt的典型用法代码示例。如果您正苦于以下问题:Java IfStmt类的具体用法?Java IfStmt怎么用?Java IfStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IfStmt类属于com.github.javaparser.ast.stmt包,在下文中一共展示了IfStmt类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:ModifierVisitorAdapter.java


示例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;
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:28,代码来源:Parser.java


示例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;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:EqualsVisitor.java


示例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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:18,代码来源:EqualsVisitor.java


示例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;
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:11,代码来源:SrcRemapper.java


示例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();
        }
    }
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:40,代码来源:ASTDumpVisitor.java


示例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;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:10,代码来源:IfStmtMerger.java


示例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;
  }
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:9,代码来源:IfStmtMerger.java


示例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();
}
   }
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:33,代码来源:DumpVisitor.java


示例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);
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:9,代码来源:VoidVisitorAdapter.java


示例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);
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:10,代码来源:JsonVisitorAdapter.java


示例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;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:9,代码来源:ModifierVisitorAdapter.java


示例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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:15,代码来源:CloneVisitor.java


示例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();
	}
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:33,代码来源:DumpVisitor.java


示例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);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:10,代码来源:ConcreteModifierVisitor.java


示例16: 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();
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:58,代码来源:SrcRemapper.java


示例17: visit

import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override
public void visit(IfStmt n, Script arg) {
}
 
开发者ID:Nosorog,项目名称:nosorog-core,代码行数:4,代码来源:NoOpVisitor.java


示例18: solveSymbolAsValue

import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override
public Optional<Value> solveSymbolAsValue(String name, TypeSolver typeSolver) {

    // if we're in a multiple Variable declaration line (for ex: double a=0, b=a;)
    SymbolDeclarator symbolDeclarator = JavaParserFactory.getSymbolDeclarator(wrappedNode, typeSolver);
    Optional<Value> symbolReference = solveWithAsValue(symbolDeclarator, name, typeSolver);
    if (symbolReference.isPresent()) {
        return symbolReference;
    }

    // we should look in all the statements preceding, treating them as SymbolDeclarators
    if (getParentNode(wrappedNode) instanceof com.github.javaparser.ast.body.MethodDeclaration) {
        return getParent().solveSymbolAsValue(name, typeSolver);
    }
    if (getParentNode(wrappedNode) instanceof LambdaExpr) {
        return getParent().solveSymbolAsValue(name, typeSolver);
    }
    if (getParentNode(wrappedNode) instanceof IfStmt) {
        return getParent().solveSymbolAsValue(name, typeSolver);
    }
    if (!(getParentNode(wrappedNode) instanceof NodeWithStatements)) {
        return getParent().solveSymbolAsValue(name, typeSolver);
    }
    NodeWithStatements<?> nodeWithStmt = (NodeWithStatements<?>) getParentNode(wrappedNode);
    int position = -1;
    for (int i = 0; i < nodeWithStmt.getStatements().size(); i++) {
        if (nodeWithStmt.getStatements().get(i).equals(wrappedNode)) {
            position = i;
        }
    }
    if (position == -1) {
        throw new RuntimeException();
    }
    for (int i = position - 1; i >= 0; i--) {
        symbolDeclarator = JavaParserFactory.getSymbolDeclarator(nodeWithStmt.getStatements().get(i), typeSolver);
        symbolReference = solveWithAsValue(symbolDeclarator, name, typeSolver);
        if (symbolReference.isPresent()) {
            return symbolReference;
        }
    }

    // if nothing is found we should ask the parent context
    Context parentContext = getParent();
    return parentContext.solveSymbolAsValue(name, typeSolver);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:46,代码来源:StatementContext.java


示例19: visit

import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override
public void visit(final IfStmt n, final Context ctx) {
  visitNode(n, ctx);
  super.visit(n, ctx);

}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:7,代码来源:LocalVariableCollector.java


示例20: visit

import com.github.javaparser.ast.stmt.IfStmt; //导入依赖的package包/类
@Override
public void visit(IfStmt n, Void arg) {
    out.println("IfStmt: " + (extended ? n : n.getCondition()));
    super.visit(n, arg);
}
 
开发者ID:JCTools,项目名称:JCTools,代码行数:6,代码来源:TraceVisitor.java



注:本文中的com.github.javaparser.ast.stmt.IfStmt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HttpGet类代码示例发布时间:2022-05-22
下一篇:
Java BusLineResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap