use of com.github.javaparser.ast.stmt.BlockStmt in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(MethodDeclaration decl, AElement elem) {
Type type = decl.getType();
List<Parameter> params = decl.getParameters();
List<TypeParameter> typeParams = decl.getTypeParameters();
Optional<ReceiverParameter> rcvrParam = decl.getReceiverParameter();
BlockStmt body = decl.getBody().orElse(null);
StringBuilder sb = new StringBuilder(decl.getNameAsString()).append('(');
AClass clazz = (AClass) elem;
AMethod method;
if (params != null) {
for (Parameter param : params) {
Type ptype = param.getType();
sb.append(getJVML(ptype));
}
}
sb.append(')').append(getJVML(type));
method = clazz.methods.vivify(sb.toString());
visitDecl(decl, method);
visitType(type, method.returnType);
if (params != null) {
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
AField field = method.parameters.vivify(i);
visitType(param.getType(), field.type);
}
}
if (rcvrParam.isPresent()) {
for (AnnotationExpr expr : rcvrParam.get().getAnnotations()) {
Annotation anno = extractAnnotation(expr);
method.receiver.type.tlAnnotationsHere.add(anno);
}
}
if (typeParams != null) {
for (int i = 0; i < typeParams.size(); i++) {
TypeParameter typeParam = typeParams.get(i);
List<ClassOrInterfaceType> bounds = typeParam.getTypeBound();
if (bounds != null) {
for (int j = 0; j < bounds.size(); j++) {
ClassOrInterfaceType bound = bounds.get(j);
BoundLocation loc = new BoundLocation(i, j);
bound.accept(this, method.bounds.vivify(loc));
}
}
}
}
return body == null ? null : body.accept(this, method);
}
use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class CommentParsingSteps method thenBlockStatementInMethodInClassHasOrphanComments.
@Then("block statement in method $methodPosition in class $classPosition has $expectedCount orphan comments")
public void thenBlockStatementInMethodInClassHasOrphanComments(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.getOrphanComments().size(), is(expectedCount));
}
use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class ParsingSteps method thenLambdaInStatementInMethodInClassBlockStatementIsNull.
@Then("lambda in statement $statementPosition in method $methodPosition in class $classPosition block statement is null")
public void thenLambdaInStatementInMethodInClassBlockStatementIsNull(int statementPosition, int methodPosition, int classPosition) {
LambdaExpr lambdaExpr = getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
BlockStmt blockStmt = lambdaExpr.getBody().asBlockStmt();
assertEquals(true, blockStmt.getStatements().isEmpty());
}
use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class JavaParser method parseBlock.
/**
* Parses the Java block contained in a {@link String} and returns a
* {@link BlockStmt} that represents it.
*
* @param blockStatement
* {@link String} containing Java block code
* @return BlockStmt representing the Java block
* @throws ParseException
* if the source code has parser errors
*/
public static BlockStmt parseBlock(final String blockStatement) {
StringReader sr = new StringReader(blockStatement);
BlockStmt result = new ASTParser(sr).Block();
sr.close();
return result;
}
use of com.github.javaparser.ast.stmt.BlockStmt in project javaparser by javaparser.
the class EqualsVisitorGenerator method generateVisitMethodBody.
@Override
protected void generateVisitMethodBody(BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
visitMethod.getParameters().forEach(p -> p.setFinal(true));
BlockStmt body = visitMethod.getBody().get();
body.getStatements().clear();
body.addStatement(f("final %s n2 = (%s) arg;", node.getTypeName(), node.getTypeName()));
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
final String getter = field.getGetterMethodName() + "()";
if (field.getNodeReference().isPresent()) {
if (field.isNodeList()) {
body.addStatement(f("if (!nodesEquals(n.%s, n2.%s)) return false;", getter, getter));
} else {
body.addStatement(f("if (!nodeEquals(n.%s, n2.%s)) return false;", getter, getter));
}
} else {
body.addStatement(f("if (!objEquals(n.%s, n2.%s)) return false;", getter, getter));
}
}
if (body.getStatements().size() == 1) {
// Only the cast line was added, but nothing is using it, so remove it again.
body.getStatements().clear();
}
body.addStatement("return true;");
}
Aggregations