use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class ParsingSteps method thenLambdaInStatementInMethodInClassBlockStatement.
@Then("lambda in statement $statementPosition in method $methodPosition in class $classPosition block statement is \"$expectedBody\"")
public void thenLambdaInStatementInMethodInClassBlockStatement(int statementPosition, int methodPosition, int classPosition, String expectedBody) {
LambdaExpr lambdaExpr = getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
BlockStmt blockStmt = lambdaExpr.getBody().asBlockStmt();
Statement lambdaStmt = blockStmt.getStatement(0);
assertThat(lambdaStmt.toString(), is(expectedBody));
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class NodeRemovalTest method testRemoveStatementFromMethodBody.
@Test
public void testRemoveStatementFromMethodBody() {
ClassOrInterfaceDeclaration testClass = cu.addClass("testC");
MethodDeclaration addMethod = testClass.addMethod("testM");
BlockStmt methodBody = addMethod.createBody();
Statement addStatement = methodBody.addAndGetStatement("test");
assertEquals(1, methodBody.getStatements().size());
boolean remove = addStatement.remove();
assertEquals(true, remove);
assertEquals(0, methodBody.getStatements().size());
}
use of com.github.javaparser.ast.stmt.Statement in project javaparser by javaparser.
the class LexicalDifferenceCalculatorTest method csmModelAfterAddingStatementToEmptyBlock.
@Test
public void csmModelAfterAddingStatementToEmptyBlock() throws IOException {
LexicalDifferenceCalculator ldc = new LexicalDifferenceCalculator();
considerExample("ASimpleClassWithMoreFormatting_step3");
MethodDeclaration setter = cu.getClassByName("MyRenamedClass").get().getMethodsByName("setAField").get(0);
Statement assignStatement = new ExpressionStmt(new AssignExpr(new FieldAccessExpr(new ThisExpr(), "aField"), new NameExpr("aField"), AssignExpr.Operator.ASSIGN));
LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel = ldc.calculatedSyntaxModelAfterListAddition(ConcreteSyntaxModel.forClass(BlockStmt.class), ObservableProperty.STATEMENTS, setter.getBody().get().getStatements(), 0, assignStatement);
int index = 0;
assertEquals(CsmElement.token(GeneratedJavaParserConstants.LBRACE), calculatedSyntaxModel.elements.get(index++));
assertEquals(CsmElement.newline(), calculatedSyntaxModel.elements.get(index++));
assertEquals(CsmElement.indent(), calculatedSyntaxModel.elements.get(index++));
assertTrue(isChild(calculatedSyntaxModel.elements.get(index++), ExpressionStmt.class));
assertEquals(CsmElement.newline(), calculatedSyntaxModel.elements.get(index++));
assertEquals(CsmElement.unindent(), calculatedSyntaxModel.elements.get(index++));
assertEquals(CsmElement.token(GeneratedJavaParserConstants.RBRACE), calculatedSyntaxModel.elements.get(index++));
assertEquals(index, calculatedSyntaxModel.elements.size());
}
Aggregations