use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class ParsingSteps method getLambdaExprInStatementInMethodInClass.
private LambdaExpr getLambdaExprInStatementInMethodInClass(int statementPosition, int methodPosition, int classPosition) {
Statement statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
VariableDeclarationExpr expression = ((ExpressionStmt) statement).getExpression().asVariableDeclarationExpr();
VariableDeclarator variableDeclarator = expression.getVariable(0);
return (LambdaExpr) variableDeclarator.getInitializer().orElse(null);
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class DumpVisitor method visit.
@Override
public void visit(LambdaExpr n, Object arg) {
printJavaComment(n.getComment(), arg);
List<Parameter> parameters = n.getParameters();
boolean printPar = false;
printPar = n.isParametersEnclosed();
if (printPar) {
printer.print("(");
}
if (parameters != null) {
for (Iterator<Parameter> i = parameters.iterator(); i.hasNext(); ) {
Parameter p = i.next();
p.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
}
if (printPar) {
printer.print(")");
}
printer.print(" -> ");
Statement body = n.getBody();
if (body instanceof ExpressionStmt) {
// Print the expression directly
((ExpressionStmt) body).getExpression().accept(this, arg);
} else {
body.accept(this, arg);
}
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class ModifierVisitorAdapter method visit.
@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) {
// then-clause.
return null;
}
n.setThenStmt(thenStmt);
if (n.getElseStmt() != null) {
n.setElseStmt((Statement) n.getElseStmt().accept(this, arg));
}
return n;
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(LambdaExpr _n, Object _arg) {
List<Parameter> lambdaParameters = visit(_n.getParameters(), _arg);
Statement body = cloneNodes(_n.getBody(), _arg);
return new LambdaExpr(_n.getRange(), lambdaParameters, body, _n.isParametersEnclosed());
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class Issue257 method issue257.
@Test
public void issue257() throws FileNotFoundException {
String pathToSourceFile = adaptPath("src/test/resources/issue257/A.java.txt");
CompilationUnit cu = JavaParser.parse(new File(pathToSourceFile));
Statement statement = cu.getClassByName("A").get().getMethodsByName("run").get(0).getBody().get().getStatement(0);
ExpressionStmt expressionStmt = (ExpressionStmt) statement;
Expression expression = expressionStmt.getExpression();
JavaParserFacade.get(typeSolver).getType(expression);
}
Aggregations