{"action":"created","issue":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/534","repository_url":"https://api.github.com/repos/javaparser/javaparser","labels_url":"https://api.github.com/repos/javaparser/javaparser/issues/534/labels{/name}","comments_url":"https://api.github.com/repos/javaparser/javaparser/issues/534/comments","events_url":"https://api.github.com/repos/javaparser/javaparser/issues/534/events","html_url":"https://github.com/javaparser/javaparser/issues/534","id":187483662,"number":534,"title":"A couple of issues about manual statement insertion into method body","user":{"login":"ducmle","id":23070975,"avatar_url":"https://avatars.githubusercontent.com/u/23070975?v=3","gravatar_id":"","url":"https://api.github.com/users/ducmle","html_url":"https://github.com/ducmle","followers_url":"https://api.github.com/users/ducmle/followers","following_url":"https://api.github.com/users/ducmle/following{/other_user}","gists_url":"https://api.github.com/users/ducmle/gists{/gist_id}","starred_url":"https://api.github.com/users/ducmle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ducmle/subscriptions","organizations_url":"https://api.github.com/users/ducmle/orgs","repos_url":"https://api.github.com/users/ducmle/repos","events_url":"https://api.github.com/users/ducmle/events{/privacy}","received_events_url":"https://api.github.com/users/ducmle/received_events","type":"User","site_admin":false},"labels":[{"id":359959666,"url":"https://api.github.com/repos/javaparser/javaparser/labels/Question","name":"Question","color":"006b75","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/javaparser/javaparser/milestones/16","html_url":"https://github.com/javaparser/javaparser/milestones/3.0.0","labels_url":"https://api.github.com/repos/javaparser/javaparser/milestones/16/labels","id":1995677,"number":16,"title":"3.0.0","description":"","creator":{"login":"matozoid","id":55701,"avatar_url":"https://avatars.githubusercontent.com/u/55701?v=3","gravatar_id":"","url":"https://api.github.com/users/matozoid","html_url":"https://github.com/matozoid","followers_url":"https://api.github.com/users/matozoid/followers","following_url":"https://api.github.com/users/matozoid/following{/other_user}","gists_url":"https://api.github.com/users/matozoid/gists{/gist_id}","starred_url":"https://api.github.com/users/matozoid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matozoid/subscriptions","organizations_url":"https://api.github.com/users/matozoid/orgs","repos_url":"https://api.github.com/users/matozoid/repos","events_url":"https://api.github.com/users/matozoid/events{/privacy}","received_events_url":"https://api.github.com/users/matozoid/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":1,"state":"open","created_at":"2016-09-10T18:59:50Z","updated_at":"2016-11-06T03:29:21Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-11-05T08:04:12Z","updated_at":"2016-11-06T03:29:21Z","closed_at":"2016-11-06T03:29:21Z","body":"Hi, \r\n\r\nWhen manually setting a method's body using this API method BlockStmt.addStatement(String) then the generated code of the method has two issues: \r\n(1) an extra semi-colon (;) is added as the last character of the last statement in the input, which causes compilation error in some cases\r\n(2) if the input contains multiple code statements separated by the next-line char ('\\n'), then only the first line is properly aligned, other lines are generated without identation.\r\n\r\nNote for issue (1) that removing the semi-colon at the end of the input statement is not an option because the the code may come from another source that contains an arbitrary number of lines.\r\n\r\nMy JavaParser version: 3.0.1-alpha.6.\r\n\r\nBelow is an example code and the generated output. The comments in the code help explain the problems.\r\n\r\n```\r\npublic class ManualMethodBody {\r\n  public static void main(String[] args) {\r\n    CompilationUnit codeUnit = JavaParser.parse(\"class Test {}\");\r\n    \r\n    ClassOrInterfaceDeclaration testCls = codeUnit.getClassByName(\"Test\");\r\n    \r\n    MethodDeclaration method = testCls.addMethod(\"greeting\", Modifier.PUBLIC);\r\n    BlockStmt body = method.createBody();\r\n    // an extra ';' is added to end of first and third statement, but not to the second\r\n    // '\\n' char causes the third statement to be misaligned!\r\n    body.addStatement(\"System.out.println(\\\"hello\\\");\");\r\n    body.addStatement(\"System.out.print(\\\"world\\\");\\n System.out.println(\\\"...\\\");\");\r\n\r\n    System.out.println(testCls);\r\n  }\r\n}\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nclass Test {\r\n\r\n    public void greeting() {\r\n        System.out.println(\"hello\");;\r\n        System.out.print(\"world\");\r\n System.out.println(\"...\");;\r\n    }\r\n}\r\n```\r\n\r\nThanks for your help.\r\n"},"comment":{"url":"https://api.github.com/repos/javaparser/javaparser/issues/comments/258658108","html_url":"https://github.com/javaparser/javaparser/issues/534#issuecomment-258658108","issue_url":"https://api.github.com/repos/javaparser/javaparser/issues/534","id":258658108,"user":{"login":"ducmle","id":23070975,"avatar_url":"https://avatars.githubusercontent.com/u/23070975?v=3","gravatar_id":"","url":"https://api.github.com/users/ducmle","html_url":"https://github.com/ducmle","followers_url":"https://api.github.com/users/ducmle/followers","following_url":"https://api.github.com/users/ducmle/following{/other_user}","gists_url":"https://api.github.com/users/ducmle/gists{/gist_id}","starred_url":"https://api.github.com/users/ducmle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ducmle/subscriptions","organizations_url":"https://api.github.com/users/ducmle/orgs","repos_url":"https://api.github.com/users/ducmle/repos","events_url":"https://api.github.com/users/ducmle/events{/privacy}","received_events_url":"https://api.github.com/users/ducmle/received_events","type":"User","site_admin":false},"created_at":"2016-11-06T03:29:21Z","updated_at":"2016-11-06T03:29:21Z","body":"Yes it worked. Thank you very much. \r\n\r\nAnd i agree that if you could add this as a method in BlockStmt class then it would be great. \r\nIf you do then in my opinion you should still keep the method addStatement(String) as it is and instead introduce a new method like addStatement(BlockStmt).\r\n\r\nThanks."}}
{"actor":{"display_login":"ducmle"}}