use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class Issue200 method issue200.
@Test
public void issue200() {
CompilationUnit cu = parseSample("Issue200");
ClassOrInterfaceDeclaration clazz = Navigator.demandClass(cu, "JavaTest");
MethodDeclaration methodDeclaration = Navigator.demandMethod(clazz, "foo");
TypeSolver typeSolver = new ReflectionTypeSolver();
JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
List<ReturnStmt> nodesByType = methodDeclaration.findAll(ReturnStmt.class);
assertEquals("java.util.stream.Stream<JavaTest.Solved>", javaParserFacade.getType((nodesByType.get(0)).getExpression().get()).describe());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class ParseErrorRecoveryTest method bodystatementClosingBraceRecovery.
@Test
public void bodystatementClosingBraceRecovery() {
MethodDeclaration cu = parser.parse(ParseStart.CLASS_BODY, provider("int x(){X X X}")).getResult().get().asMethodDeclaration();
Statement xxx = cu.getBody().get();
assertEquals(UNPARSABLE, xxx.getParsed());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class ParseErrorRecoveryTest method bodystatementSemicolonRecovery.
@Test
public void bodystatementSemicolonRecovery() {
MethodDeclaration cu = parser.parse(ParseStart.CLASS_BODY, provider("int x(){X X X;}")).getResult().get().asMethodDeclaration();
Statement xxx = cu.getBody().get().getStatements().get(0);
assertEquals(UNPARSABLE, xxx.getParsed());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class NodeTest method removeAllOnRequiredProperty.
@Test
public void removeAllOnRequiredProperty() {
CompilationUnit cu = parse("class X{ void x(){}}");
MethodDeclaration methodDeclaration = cu.getType(0).getMethods().get(0);
methodDeclaration.getName().removeForced();
// Name is required, so to remove it the whole method is removed.
assertEquals(String.format("class X {%1$s}%1$s", EOL), cu.toString());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class CloneGenerator method generateNode.
@Override
protected void generateNode(BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
nodeCu.addImport(CloneVisitor.class);
MethodDeclaration cloneMethod = (MethodDeclaration) parseBodyDeclaration(f("@Override public %s clone() { return (%s) accept(new CloneVisitor(), null); }", nodeMetaModel.getTypeNameGenerified(), nodeMetaModel.getTypeNameGenerified()));
addOrReplaceWhenSameSignature(nodeCoid, cloneMethod);
}
Aggregations