Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A {
- int x;
- public void method2() {...}
- class B {
- int number;
- public void methods() {...}
- }
- }
- CompilationUnit cu = JavaParser.parse(in);
- ClassVisitor classVisitor = new ClassVisitor();
- classVisitor.visit(cu, null);
- class ClassVisitor extends VoidVisitorAdapter<Void> {
- @Override
- public void visit(ClassOrInterfaceDeclaration n, Void arg) {
- System.out.println(n.getFields());
- // get class methods
- for(MethodDeclaration method : n.getMethods()) {
- System.out.println("Name :" + method.getName());
- System.out.println("Body :" + method.getBody().get());
- }
- }
- }
- }
- CompilationUnit cu = JavaParser.parse(in);
- for(TypeDeclaration<?> type : cu.getTypes()) {
- log.info("Type Name :{}", type.getName());
- }
- for(TypeDeclaration type : cu.getTypes()) {
- // first give all this java doc member
- List<BodyDeclaration> members = type.getMembers();
- // check all member content
- for(BodyDeclaration member : members) {
- // if member state equal ClassOrInterfaceDeclaration, and you can identify it which is inner class
- if(member.isClassOrInterfaceDeclaration()) {
- log.info("class name :{}", member.asClassOrInterfaceDeclaration().getName());
- // get inner class method
- for(MethodDeclaration method : member.asClassOrInterfaceDeclaration().getMethods()) {
- log.info("Method Name :{}", method.getName());
- }
- VerifyInnerClassAndParse(member.asClassOrInterfaceDeclaration());
- }
- }
- }
Add Comment
Please, Sign In to add comment