Java Code Examples for jdk.javadoc.doclet.DocletEnvironment#getDocTrees()

The following examples show how to use jdk.javadoc.doclet.DocletEnvironment#getDocTrees() . 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 File: Test.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(DocletEnvironment root) {
    DocTrees docTrees = root.getDocTrees();
    System.out.println("classes:" + ElementFilter.typesIn(root.getIncludedElements()));

    Element klass = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
    String text = "";
    try {
        DocCommentTree dcTree = docTrees.getDocCommentTree(klass, overviewpath);
        text = dcTree.getFullBody().toString();
    } catch (IOException ioe) {
        throw new Error(ioe);
    }

    if (text.length() < 64)
        System.err.println("text: '" + text + "'");
    else
        System.err.println("text: '"
                + text.substring(0, 20)
                + "..."
                + text.substring(text.length() - 20)
                + "'");
    return text.startsWith("ABC") && text.endsWith("XYZ");
}
 
Example 2
Source File: T4994049.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(DocletEnvironment root) {
    DocTrees trees = root.getDocTrees();

    SourcePositions sourcePositions = trees.getSourcePositions();
    for (TypeElement klass : ElementFilter.typesIn(root.getIncludedElements())) {
        for (ExecutableElement method : getMethods(klass)) {
            if (method.getSimpleName().toString().equals("tabbedMethod")) {
                TreePath path = trees.getPath(method);
                CompilationUnitTree cu = path.getCompilationUnit();
                long pos = sourcePositions.getStartPosition(cu, path.getLeaf());
                LineMap lineMap = cu.getLineMap();
                long columnNumber = lineMap.getColumnNumber(pos);
                if (columnNumber == 9) {
                    System.out.println(columnNumber + ": OK!");
                    return true;
                } else {
                    System.err.println(columnNumber + ": wrong tab expansion");
                    return false;
                }
            }
        }
    }
    return false;
}
 
Example 3
Source File: InlineTagsWithBraces.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(DocletEnvironment root) {
        DocTrees trees = root.getDocTrees();
        TypeElement cd = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
        DocCommentTree docCommentTree = trees.getDocCommentTree(cd);
        List<? extends DocTree> tags = docCommentTree.getBody();

        for (int i = 0; i < tags.size(); i++) {
            System.out.println(tags.get(0).getKind());
//            if (!tags[i].name().equals(expectedTags[i]) ||
//                        !tags[i].text().equals(expectedText[i])) {
//                throw new Error("Tag \"" + tags[i] + "\" not as expected");
//            }
        }

        return true;
    }
 
Example 4
Source File: BreakIteratorWarning.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean run(DocletEnvironment root) {
    TypeElement cd = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
    VariableElement fd = getFields(cd).get(0);
    DocTrees docTrees = root.getDocTrees();
    DocCommentTree docCommentTree = docTrees.getDocCommentTree(fd);
    List<? extends DocTree> firstSentence = docCommentTree.getFirstSentence();
    return true;
}
 
Example 5
Source File: NoStar.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public boolean run(DocletEnvironment root) {
    Set<TypeElement> classes = ElementFilter.typesIn(root.getIncludedElements());
    if (classes.size() != 1)
        throw new Error("1 " + Arrays.asList(classes));
    TypeElement self = classes.iterator().next();
    DocTrees trees = root.getDocTrees();
    DocCommentTree docCommentTree = trees.getDocCommentTree(self);
    String c = docCommentTree.getFullBody().toString();
    System.out.println("\"" + c + "\"");
    return c.equals("First sentence.\n0\n 1\n  2\n   3\n    4\n     5");
}
 
Example 6
Source File: BeakerxDoclet.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@Override
public boolean run(DocletEnvironment docEnv) {
  HashMap<String, ClassInspect> inspects = new HashMap<>();
  DocTrees docTrees = docEnv.getDocTrees();
  for (TypeElement t : ElementFilter.typesIn(docEnv.getIncludedElements())) {
    DocCommentTree docCommentTree = docTrees.getDocCommentTree(t);
    String comment = (docCommentTree != null) ? docCommentTree.getFullBody().toString() : "";
    ClassInspect classInspect = new ClassInspect(t.getSimpleName().toString(), t.getQualifiedName().toString(), comment);
    inspects.put(classInspect.getFullName(), classInspect);
    List<MethodInspect> constructors = new ArrayList<>();
    List<MethodInspect> methods = new ArrayList<>();
    for (Element ee : t.getEnclosedElements()) {
      if (ee.getModifiers().contains(Modifier.PUBLIC) || ee.getModifiers().contains(Modifier.PROTECTED)) {
        if (ee.getKind().equals(ElementKind.CONSTRUCTOR)) {
          constructors.add(getInspect(ee, docTrees));
        } else if (ee.getKind().equals(ElementKind.METHOD)) {
          methods.add(getInspect(ee, docTrees));
        }
      }
    }
    classInspect.setMethods(methods);
    classInspect.setConstructors(constructors);
  }
  SerializeInspect serializeInspect = new SerializeInspect();
  String json = serializeInspect.toJson(inspects);
  serializeInspect.saveToFile(json);
  return true;
}
 
Example 7
Source File: DumpJavaDoc.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public boolean run(DocletEnvironment docEnv) {
    final Elements utils = docEnv.getElementUtils();
    final DocTrees docTrees = docEnv.getDocTrees();
    
    try (OutputStream os = Files.newOutputStream(Paths.get(dumpFileName))) {
        final Properties javaDocMap = new Properties();
        for (Element element : docEnv.getIncludedElements()) {
            if (element.getKind() == ElementKind.CLASS) {
                final TypeElement classDoc = (TypeElement) element;
                final DocCommentTree classCommentTree = docTrees.getDocCommentTree(classDoc);
                
                if (classCommentTree != null) {
                    javaDocMap.put(classDoc.toString(), getAllComments(classCommentTree.getFullBody()));
                }
                
                for (Element member: classDoc.getEnclosedElements()) {
                    // Skip all non-public methods
                    if (!member.getModifiers().contains(Modifier.PUBLIC)) {
                        continue;
                    }
                    
                    if (member.getKind() == ElementKind.METHOD) {
                        final ExecutableElement method = (ExecutableElement) member;
                        final DocCommentTree methodCommentTree = docTrees.getDocCommentTree(method);
                        final String qualifiedName = utils.getBinaryName(classDoc) + "." + method.getSimpleName();
                        
                        if (methodCommentTree == null) {
                            javaDocMap.put(qualifiedName, "");
                        } else  {
                            javaDocMap.put(qualifiedName, getAllComments(methodCommentTree.getFullBody()));
                            for (DocTree tree: methodCommentTree.getBlockTags()) {
                                if (tree.getKind() == DocTree.Kind.RETURN) {
                                    final ReturnTree returnTree = (ReturnTree) tree;
                                    javaDocMap.put(qualifiedName + ".returnCommentTag", 
                                        getAllComments(returnTree.getDescription()));
                                } else if (tree.getKind() == DocTree.Kind.PARAM) {
                                    final ParamTree paramTree = (ParamTree) tree;
                                    final int index = getParamIndex(method, paramTree);
                                    if (index >= 0) {
                                        javaDocMap.put(qualifiedName + ".paramCommentTag." + index, 
                                            getAllComments(paramTree.getDescription()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        
        javaDocMap.store(os, "");
        os.flush();
    } catch (final IOException ex) {
        reporter.print(Diagnostic.Kind.ERROR, ex.getMessage());
    }
    
    return true;
}
 
Example 8
Source File: Taglet.java    From sis with Apache License 2.0 2 votes vote down vote up
/**
 * Initializes this taglet with the given doclet environment and doclet.
 *
 * @param env     the environment in which the taglet is running.
 * @param doclet  the doclet that instantiated this taglet.
 */
@Override
public void init(final DocletEnvironment env, final Doclet doclet) {
    reporter = (Reporter) ((Supplier<?>) doclet).get();
    trees = env.getDocTrees();
}