In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to use Qdox tools, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
QDox is a simple and efficient Java source code parser that can extract Java classes, interfaces, methods, parameter names, types, etc. Give me a brief introduction to how to use it.
Integration
The latest version of 2.0-M10
Maven
Com.thoughtworks.qdox qdox 2.0-M10
Gradle
Compile group: 'com.thoughtworks.qdox', name:' qdox', version: '2.0 Murray M10' usage package com.mini.test;import java.util.Random / * QDox test * @ author: jujun chen * @ date: 2019-07-07 * / public class TestClass extends BaseTestClass implements Test {/ * login interface * @ param userName user name * @ param password password * @ return Person object * / public Person Login (String userName, String password) {int age = new Random (). NextInt () Person person = new Person (userName, password, age); System.out.println (person); return person;}} class Person {private String userName; private String password; private int age; public Person (String userName, String password, int age) {this.userName = userName; this.password = password; this.age = age;} class BaseTestClass {} interface Test {}
Test:
@ Test public void getMeClass () throws IOException {JavaProjectBuilder builder = new JavaProjectBuilder (); builder.addSourceTree (new File ("src/main/java/com/mini/test")); / / all class System.out.println under the directory ("all class==== under the directory"); Collection classes = builder.getClasses (); System.out.println (classes + "\ n") / / get JavaClass javaClass = builder.getClassByName ("com.mini.test.TestClass") according to the fully qualified name of class; / / get the comment System.out.println of the class ("= get the comment of the class = ="); System.out.println (javaClass.getComment ()); List classTags = javaClass.getTags () ClassTags.forEach (item-> {System.out.println (item.getName () + "+ item.getValue ());}); System.out.println ("\ n "); / / get inherited parent System.out.println (" = = get inherited parent = = "); System.out.println (javaClass.getSuperClass () +"\ n ") / / get interface System.out.println ("= get interface ="); System.out.println (javaClass.getImplements () + "\ n"); / / get method System.out.println ("= get method ="); List methods = javaClass.getMethods (); System.out.println (methods + "\ n") / / get Login method JavaMethod javaMethod = methods.get (0); / / method return type System.out.println ("= get method return type ="); System.out.println (javaMethod.getReturns () + "\ n"); / / get parameter System.out.println ("= get parameter ="); List parameters = javaMethod.getParameters () System.out.println (parameters); / / get parameter type / / get userName parameter JavaParameter parameter = parameters.get (0); / / parameter name System.out.println (parameter.getName ()); / / parameter type System.out.println (parameter.getType () + "\ n"); System.out.println ("= get method comment =") / / get method comments System.out.println (javaMethod.getComment ()); / / get parameters remarks List tags = javaMethod.getTags (); tags.forEach (item-> {System.out.println (item.getName () + ":" + item.getValue ());});}
Test results:
= all class==== [class com.mini.test.TestClass, class com.mini.test.Person, class com.mini.test.BaseTestClass, interface com.mini.test.Test] in the directory = get comments on the class = QDox test author:jujun chendate:2019/07/07==== get inherited parent class = com.mini.test.BaseTestClass==== get interface = [com.mini.test.Test] = = get method = [public com.mini.test.Person com.mini.test.TestClass.Login (java.lang.String) Java.lang.String)] = get method return type = com.mini.test.Person==== get parameter = [String userName, String password] userNamejava.lang.String==== get method comment = login interface param:userName username param:password password return:Person object
Using this tool, you can parse the Java source code, which is very convenient and fast. Think about it, you can use it to do something to improve productivity.
About how to use Qdox tools to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.