Java Code Examples for com.github.javaparser.ast.visitor.VoidVisitorAdapter

The following examples show how to use com.github.javaparser.ast.visitor.VoidVisitorAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: joyqueue   Author: chubaostream   File:    License: Apache License 2.0 6 votes vote down vote up
private Map<String, JavadocComment> parseDoc(File classFile) {
    Map<String, JavadocComment> classDoc = new HashMap<>();
    try {
        CompilationUnit cu = StaticJavaParser.parse(classFile, StandardCharsets.UTF_8);
        new VoidVisitorAdapter<Object>() {
            public void visit(JavadocComment comment, Object arg) {
                super.visit(comment, arg);
                if (comment.getCommentedNode().get() instanceof MethodDeclaration) {
                    MethodDeclaration node = (MethodDeclaration) comment.getCommentedNode().get();
                    classDoc.put(methodName(node), comment);
        }.visit(cu, null);
    } catch (Exception e) {"ERROR PROCESSING ", e);
    return classDoc;
Example #2
Source Project: enkan   Author: kawasima   File:    License: Eclipse Public License 1.0 6 votes vote down vote up
public List<EntityField> analyze(File source) throws IOException, ParseException {
    List<EntityField> entityFields = new ArrayList<>();
    CompilationUnit cu = JavaParser.parse(source);
    cu.accept(new VoidVisitorAdapter<List<EntityField>>() {
        public void visit(FieldDeclaration fd, List<EntityField> f) {
            if (fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Column"))) {
                Class<?> type = null;
                switch (fd.getType().toString()) {
                    case "String": type = String.class; break;
                    case "Long": type = Long.class; break;
                    case "Integer": type = Integer.class; break;
                    case "boolean": type = boolean.class; break;
                if (type == null) return;
                f.add(new EntityField(
                        fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Id"))));
    }, entityFields);

    return entityFields;
Example #3
Source Project: deadcode4j   Author: Scout24   File:    License: Apache License 2.0 5 votes vote down vote up
public void calculatesTypeNames() throws IOException, ParseException {
    CompilationUnit compilationUnit = JavaParser.parse(

    compilationUnit.accept(new VoidVisitorAdapter<Void>() {
        public void visit(StringLiteralExpr n, Void arg) {
            assertThat("Name of anonymous class is invalid!", Nodes.getTypeName(n), is(n.getValue()));
    }, null);
Example #4
Source Project: xDoc   Author: treeleafj   File:    License: MIT License 4 votes vote down vote up
public static Map<String, String> analysisFieldComments(Class<?> classz) {

        final Map<String, String> commentMap = new HashMap(10);

        List<Class> classes = new LinkedList<>();

        Class nowClass = classz;

        while (true) {
            classes.add(0, nowClass);
            if (Object.class.equals(nowClass) || Object.class.equals(nowClass.getSuperclass())) {
            nowClass = nowClass.getSuperclass();

        for (Class clz : classes) {
            String path = JavaSourceFileManager.getInstance().getPath(clz.getSimpleName());
            if (StringUtils.isBlank(path)) {
            try (FileInputStream in = new FileInputStream(path)) {
                CompilationUnit cu = javaParser.parse(in).getResult().get();

                new VoidVisitorAdapter<Void>() {
                    public void visit(FieldDeclaration n, Void arg) {
                        String name = n.getVariable(0).getName().asString();

                        String comment = "";
                        if (n.getComment().isPresent()) {
                            comment = n.getComment().get().getContent();

                        if (name.contains("=")) {
                            name = name.substring(0, name.indexOf("=")).trim();

                        commentMap.put(name, CommentUtils.parseCommentText(comment));
                }.visit(cu, null);

            } catch (Exception e) {
                logger.warn("读取java原文件失败:{}", path, e.getMessage(), e);

        return commentMap;