I am using Com.GitHub.java parser for generating java code. i am facing a problem . problem is :
I have need bellow output . This line "String result = null;" need to show before try statement .
But it is showing inside of try statement.
My Source code: https://pastebin.mozilla.org/McXbnU7w
Maven dependency:
<!-- https://mvnrepository.com/artifact/com.github.javaparser/javaparser-core -->
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>3.24.4</version>
</dependency>
Expected output of my code:
public Response saveProduct(ProductDto productDto) throws ServletException, IOException {
String result = null;
try {
createMyProduct.setProduct(productDto.getProduct());
createMyProduct.execute(parameterMap);
result = createMyProduct.getResult();
} catch (BusinessException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(result).build();
}
You need to add as many blocks as you need. E.g.
String result = nullshould be treated as a separate block andtryblock should be another block. You cannot shove all statements in one block. Also inaddingExceptionmethod, you are addingtryblock into anotherBlockStmt. That is not needed. It will put extra curly braces. Here is updated code: