package com.bootdo.jparser;
import java.io.File;
import java.io.FileNotFoundException;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.CompilationUnit;
public class Jparser {
public static void main(String[] args) {
try {
//将一个java代码的文本解析为一棵CompilationUnit类型的树
CompilationUnit unit = JavaParser.parse(new File("D:\\Atools\\sts-bundle\\stsWorkspace\\bootdo2\\src\\main\\java\\com\\bootdo\\jparser\\DetectedController.java"));
classUnit vc = new classUnit();
//在指定的树上进行搜索,然后根据遇到的节点的类型调用具体的回调
//vc.visit(unit, null);
unit.accept(vc,null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
package com.bootdo.jparser;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.javaparser.ast.ImportDeclaration;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.PackageDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.body.Parameter;
impo