use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class NodeWithParametersBuildersTest method testGetParamByName.
@Test
public void testGetParamByName() {
MethodDeclaration addMethod = cu.addClass("test").addMethod("foo", Modifier.PUBLIC);
Parameter addAndGetParameter = addMethod.addAndGetParameter(int.class, "yay");
assertEquals(addAndGetParameter, addMethod.getParameterByName("yay").get());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class NodeWithParametersBuildersTest method testGetParamByType.
@Test
public void testGetParamByType() {
MethodDeclaration addMethod = cu.addClass("test").addMethod("foo", Modifier.PUBLIC);
Parameter addAndGetParameter = addMethod.addAndGetParameter(int.class, "yay");
assertEquals(addAndGetParameter, addMethod.getParameterByType("int").get());
assertEquals(addAndGetParameter, addMethod.getParameterByType(int.class).get());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class NodeWithThrownExceptionsBuildersTest method testThrows.
@Test
public void testThrows() {
MethodDeclaration addMethod = cu.addClass("test").addMethod("foo", Modifier.PUBLIC);
addMethod.addThrownException(IllegalStateException.class);
assertEquals(1, addMethod.getThrownExceptions().size());
assertEquals(true, addMethod.isThrown(IllegalStateException.class));
addMethod.addThrownException(parseClassOrInterfaceType("Test"));
assertEquals(2, addMethod.getThrownExceptions().size());
assertEquals("Test", addMethod.getThrownException(1).toString());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class NodeWithJavadocTest method getJavadocOnMethodWithLineCommentShouldReturnEmptyOptional.
@Test
public void getJavadocOnMethodWithLineCommentShouldReturnEmptyOptional() {
MethodDeclaration method = new MethodDeclaration();
method.setLineComment("Lorem Ipsum.");
assertFalse(method.getJavadocComment().isPresent());
assertFalse(method.getJavadoc().isPresent());
}
use of com.github.javaparser.ast.body.MethodDeclaration in project javaparser by javaparser.
the class ArrayTypeTest method getParameterWithArrays.
@Test
public void getParameterWithArrays() {
MethodDeclaration methodDeclaration = parseBodyDeclaration("void a(@C int @A[] a @B[]) {}").asMethodDeclaration();
Parameter parameter = methodDeclaration.getParameter(0);
ArrayType outerArrayType = parameter.getType().asArrayType();
ArrayType innerArrayType = outerArrayType.getComponentType().asArrayType();
PrimitiveType elementType = innerArrayType.getComponentType().asPrimitiveType();
assertThat(elementType).isInstanceOf(PrimitiveType.class);
assertThat(outerArrayType.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("A")));
assertThat(innerArrayType.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("B")));
assertThat(parameter.getAnnotations()).containsExactly(new MarkerAnnotationExpr(parseName("C")));
assertThat(parameter.getType().getParentNode().get()).isSameAs(parameter);
}
Aggregations