use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class CommentParsingSteps method thenBlockStatementInMethodInClassHasTotalContainedComments.
@Then("block statement in method $methodPosition in class $classPosition has $expectedCount total contained comments")
public void thenBlockStatementInMethodInClassHasTotalContainedComments(int methodPosition, int classPosition, int expectedCount) {
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
MethodDeclaration methodUnderTest = getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
BlockStmt blockStmtUnderTest = methodUnderTest.getBody().orElse(null);
assertThat(blockStmtUnderTest.getAllContainedComments().size(), is(expectedCount));
}
use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class CommentParsingSteps method thenBlockStatementInMethodInClassIs.
@Then("block statement in method $methodPosition in class $classPosition orphan comment $commentPosition is \"$expectedContent\"")
public void thenBlockStatementInMethodInClassIs(int methodPosition, int classPosition, int commentPosition, String expectedContent) {
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
MethodDeclaration methodUnderTest = getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
BlockStmt blockStmtUnderTest = methodUnderTest.getBody().orElse(null);
Comment commentUnderTest = blockStmtUnderTest.getOrphanComments().get(commentPosition - 1);
assertThat(commentUnderTest.getContent(), is(equalToIgnoringWhiteSpace(expectedContent)));
}
use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class ManipulationSteps method whenABlockStmtIsAddedToMethodInClass.
@When("a BlockStmt is added to method $methodPosition in class $classPosition")
public void whenABlockStmtIsAddedToMethodInClass(int methodPosition, int classPosition) {
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
method.setBody(new BlockStmt());
}
use of com.github.javaparser.ast.stmt.BlockStmt 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.BlockStmt 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());
}
Aggregations