javaparser

get method statements using javaparser

谁说我不能喝 提交于 2019-12-08 03:29:30
Is it possible to get list of method statements without comments, i used method.getBody() and this is the output /* set the value of the age integer to 32 */ int age = 32; I want to make statements only are the outcome like this int age = 32; .getBody() method return BlockStmt object which is Statements in between { and } so the following code do what i want Optional<BlockStmt> block = method.getBody(); NodeList<Statement> statements = block.get().getStatements(); for (Statement tmp : statements) { tmp.removeComment(); System.out.println(tmp.toString()); } 来源: https://stackoverflow.com

How to get class level variable declarations using javaparser ?

北城余情 提交于 2019-12-02 14:11:16
问题 I want to get only the class level variable declarations. How can i get the declarations using javaparser? public class Login { private Keyword browser; private String pageTitle = "Login"; } Using javaparser have to get the details of variable "browser" like the type of browser is "KeyWord" 回答1: Not quite sure i understood your question - do you want to get all the field-members of a class? if so you can do it like this: CompilationUnit cu = JavaParser.parse(javaFile); for (TypeDeclaration

How to get class level variable declarations using javaparser ?

谁都会走 提交于 2019-12-02 05:29:06
I want to get only the class level variable declarations. How can i get the declarations using javaparser? public class Login { private Keyword browser; private String pageTitle = "Login"; } Using javaparser have to get the details of variable "browser" like the type of browser is "KeyWord" Not quite sure i understood your question - do you want to get all the field-members of a class? if so you can do it like this: CompilationUnit cu = JavaParser.parse(javaFile); for (TypeDeclaration typeDec : cu.getTypes()) { List<BodyDeclaration> members = typeDec.getMembers(); if(members != null) { for