com.sun.source.doctree.DocTree Java Examples
The following examples show how to use
com.sun.source.doctree.DocTree.
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: DocTreePath.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public Iterator<DocTree> iterator() { return new Iterator<DocTree>() { public boolean hasNext() { return next != null; } public DocTree next() { DocTree t = next.leaf; next = next.parent; return t; } public void remove() { throw new UnsupportedOperationException(); } private DocTreePath next = DocTreePath.this; }; }
Example #2
Source File: ReferenceTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void checkReference(ReferenceTree tree, List<? extends DocTree> label) { String sig = tree.getSignature(); Element found = trees.getElement(new DocTreePath(getCurrentPath(), tree)); if (found == null) { System.err.println(sig + " NOT FOUND"); } else { System.err.println(sig + " found " + found.getKind() + " " + found); } String expect = "UNKNOWN"; if (label.size() > 0 && label.get(0) instanceof TextTree) expect = ((TextTree) label.get(0)).getBody(); if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) { error(tree, "Unexpected value found: " + found +", expected: " + expect); } }
Example #3
Source File: ModuleGraph.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public String toString(List<? extends DocTree> tags, Element element) { if (!enableModuleGraph) { return ""; } String moduleName = ((ModuleElement) element).getQualifiedName().toString(); String imageFile = moduleName + "-graph.png"; int thumbnailHeight = -1; String hoverImage = ""; if (!moduleName.equals("java.base")) { thumbnailHeight = 100; // also appears in the stylesheet hoverImage = "<span>" + getImage(moduleName, imageFile, -1, true) + "</span>"; } return "<dt>" + "<span class=\"simpleTagLabel\">Module Graph:</span>\n" + "</dt>" + "<dd>" + "<a class=moduleGraph href=\"" + imageFile + "\">" + getImage(moduleName, imageFile, thumbnailHeight, false) + hoverImage + "</a>" + "</dd>"; }
Example #4
Source File: DocTreePath.java From JDKSourceCode1.8 with MIT License | 6 votes |
public Iterator<DocTree> iterator() { return new Iterator<DocTree>() { public boolean hasNext() { return next != null; } public DocTree next() { DocTree t = next.leaf; next = next.parent; return t; } public void remove() { throw new UnsupportedOperationException(); } private DocTreePath next = DocTreePath.this; }; }
Example #5
Source File: DocTreePath.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public Iterator<DocTree> iterator() { return new Iterator<DocTree>() { public boolean hasNext() { return next != null; } public DocTree next() { DocTree t = next.leaf; next = next.parent; return t; } public void remove() { throw new UnsupportedOperationException(); } private DocTreePath next = DocTreePath.this; }; }
Example #6
Source File: Messages.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected void report(Group group, Diagnostic.Kind dkind, DocTree tree, String code, Object... args) { if (options.isEnabled(group, env.currAccess)) { String msg = (code == null) ? (String) args[0] : localize(code, args); env.trees.printMessage(dkind, msg, tree, env.currDocComment, env.currPath.getCompilationUnit()); stats.record(group, dkind, code); } }
Example #7
Source File: JavacTrees.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public void printMessage(Diagnostic.Kind kind, CharSequence msg, com.sun.source.doctree.DocTree t, com.sun.source.doctree.DocCommentTree c, com.sun.source.tree.CompilationUnitTree root) { printMessage(kind, msg, ((DCTree) t).pos((DCDocComment) c), root); }
Example #8
Source File: UserTaglet.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public Content getTagletOutput(Element holder, TagletWriter writer) { Content output = writer.getOutputInstance(); Utils utils = writer.configuration().utils; List<? extends DocTree> tags = utils.getBlockTags(holder, getName()); if (!tags.isEmpty()) { String tagString = userTaglet.toString(tags, holder); if (tagString != null) { output.addContent(new RawHtml(tagString)); } } return output; }
Example #9
Source File: TagletWriterImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public Content propertyTagOutput(Element element, DocTree tag, String prefix) { Content body = new ContentBuilder(); CommentHelper ch = utils.getCommentHelper(element); body.addContent(new RawHtml(prefix)); body.addContent(" "); body.addContent(HtmlTree.CODE(new RawHtml(ch.getText(tag)))); body.addContent("."); Content result = HtmlTree.P(body); return result; }
Example #10
Source File: SimpleDocTreeVisitorTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void run() throws Exception { List<File> files = new ArrayList<File>(); File testSrc = new File(System.getProperty("test.src")); for (File f: testSrc.listFiles()) { if (f.isFile() && f.getName().endsWith(".java")) files.add(f); } JavacTool javac = JavacTool.create(); StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); JavacTask t = javac.getTask(null, fm, null, null, null, fos); DocTrees trees = DocTrees.instance(t); Iterable<? extends CompilationUnitTree> units = t.parse(); Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class); DeclScanner ds = new DeclScanner(trees, found); for (CompilationUnitTree unit: units) { ds.scan(unit, null); } for (DocTree.Kind k: DocTree.Kind.values()) { if (!found.contains(k) && k != DocTree.Kind.OTHER) error("not found: " + k); } if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example #11
Source File: DocTreeNode.java From netbeans with Apache License 2.0 | 5 votes |
public DocTreeNode(CompilationInfo info, TreePath declaration, DocCommentTree docComment, DocTree tree) { super(new NodeChilren(children(info, declaration, docComment, tree))); this.info = info; this.docComment = docComment; this.tree = tree; setDisplayName(tree.getKind() + ":" + tree.toString()); }
Example #12
Source File: CommentHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public TypeElement getReferencedClass(Configuration c, DocTree dtree) { Element e = getReferencedElement(c, dtree); if (e == null) { return null; } else if (c.utils.isTypeElement(e)) { return (TypeElement) e; } else if (!c.utils.isPackage(e)) { return c.utils.getEnclosingTypeElement(e); } return null; }
Example #13
Source File: ReferenceTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public Void visitSee(SeeTree tree, Void ignore) { List<? extends DocTree> refLabel = tree.getReference(); if (refLabel.size() > 1 && (refLabel.get(0) instanceof ReferenceTree)) { ReferenceTree ref = (ReferenceTree) refLabel.get(0); List<? extends DocTree> label = refLabel.subList(1, refLabel.size()); checkReference(ref, label); } return null; }
Example #14
Source File: Checker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void checkAllowsText(DocTree tree) { TagStackItem top = tagStack.peek(); if (top != null && top.tree.getKind() == DocTree.Kind.START_ELEMENT && !top.tag.acceptsText()) { if (top.flags.add(Flag.REPORTED_BAD_INLINE)) { env.messages.error(HTML, tree, "dc.text.not.allowed", ((StartElementTree) top.tree).getName()); } } }
Example #15
Source File: CommentHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public ReferenceTree getType(DocTree dtree) { if (dtree.getKind() == SERIAL_FIELD) { return ((SerialFieldTree)dtree).getType(); } else { return null; } }
Example #16
Source File: ImmutableDocTreeTranslator.java From netbeans with Apache License 2.0 | 5 votes |
protected final UnknownInlineTagTree rewriteChildren(UnknownInlineTagTree tree) { UnknownInlineTagTree value = tree; List<? extends DocTree> content = translateDoc(tree.getContent()); if (content != tree.getContent()) { value = make.UnknownInlineTag(((DCTree.DCUnknownInlineTag) tree).name, tree.getContent()); } return value; }
Example #17
Source File: Checker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void warnIfEmpty(DocTree tree, List<? extends DocTree> list) { for (DocTree d: list) { switch (d.getKind()) { case TEXT: if (hasNonWhitespace((TextTree) d)) return; break; default: return; } } env.messages.warning(SYNTAX, tree, "dc.empty", tree.getKind().tagName); }
Example #18
Source File: DocCommentTreeApiTester.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Tests getting a DocCommentTree from an element, as well * as test if break iterator setter/getter works correctly. * * @param javaFileName a test file to be processed * @param expected the expected output * @throws java.io.IOException */ public void runElementAndBreakIteratorTests(String javaFileName, String expected) throws IOException { List<File> javaFiles = new ArrayList<>(); javaFiles.add(new File(testSrc, javaFileName)); List<File> dirs = new ArrayList<>(); dirs.add(new File(testSrc)); try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) { fm.setLocation(javax.tools.StandardLocation.SOURCE_PATH, dirs); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles); final JavacTask t = javac.getTask(null, fm, null, null, null, fos); final DocTrees trees = DocTrees.instance(t); Iterable<? extends Element> elements = t.analyze(); Element klass = elements.iterator().next(); DocCommentTree dcTree = trees.getDocCommentTree(klass); List<? extends DocTree> firstSentence = dcTree.getFirstSentence(); StringWriter sw = new StringWriter(); DocPretty pretty = new DocPretty(sw); pretty.print(firstSentence); check("getDocCommentTree(Element)", expected, sw.toString()); BreakIterator bi = BreakIterator.getSentenceInstance(Locale.FRENCH); trees.setBreakIterator(bi); BreakIterator nbi = trees.getBreakIterator(); if (bi.equals(nbi)) { pass++; check("getDocCommentTree(Element) with BreakIterator", expected, sw.toString()); } else { fail++; System.err.println("BreakIterators don't match"); } } }
Example #19
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public List<? extends DocTree> getBlockTags(Element element, String tagName) { DocTree.Kind kind = null; switch (tagName) { case "author": case "deprecated": case "hidden": case "param": case "return": case "see": case "serial": case "since": case "throws": case "exception": case "version": kind = DocTree.Kind.valueOf(tagName.toUpperCase()); return getBlockTags(element, kind); case "serialData": kind = SERIAL_DATA; return getBlockTags(element, kind); case "serialField": kind = SERIAL_FIELD; return getBlockTags(element, kind); default: kind = DocTree.Kind.UNKNOWN_BLOCK_TAG; break; } List<? extends DocTree> blockTags = getBlockTags(element, kind); List<DocTree> out = new ArrayList<>(); String tname = tagName.startsWith("@") ? tagName.substring(1) : tagName; CommentHelper ch = getCommentHelper(element); for (DocTree dt : blockTags) { if (ch.getTagName(dt).equals(tname)) { out.add(dt); } } return out; }
Example #20
Source File: Checker.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override public Void visitLiteral(LiteralTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); if (tree.getKind() == DocTree.Kind.CODE) { for (TagStackItem tsi: tagStack) { if (tsi.tag == HtmlTag.CODE) { env.messages.warning(HTML, tree, "dc.tag.code.within.code"); break; } } } return super.visitLiteral(tree, ignore); }
Example #21
Source File: Checker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitLiteral(LiteralTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); if (tree.getKind() == DocTree.Kind.CODE) { for (TagStackItem tsi: tagStack) { if (tsi.tag == HtmlTag.CODE) { env.messages.warning(HTML, tree, "dc.tag.code.within.code"); break; } } } return super.visitLiteral(tree, ignore); }
Example #22
Source File: JavacTrees.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private DocTree getLastChild(DocTree tree) { final DocTree[] last = new DocTree[] {null}; tree.accept(new DocTreeScanner<Void, Void>() { @Override @DefinedBy(Api.COMPILER_TREE) public Void scan(DocTree node, Void p) { if (node != null) last[0] = node; return null; } }, null); return last[0]; }
Example #23
Source File: DocTreeMaker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public DCThrows newExceptionTree(ReferenceTree name, List<? extends DocTree> description) { // TODO: verify the reference is just to a type (not a field or method) DCThrows tree = new DCThrows(Kind.EXCEPTION, (DCReference) name, cast(description)); tree.pos = pos; return tree; }
Example #24
Source File: Messages.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected void report(Group group, Diagnostic.Kind dkind, DocTree tree, String code, Object... args) { if (options.isEnabled(group, env.currAccess)) { String msg = (code == null) ? (String) args[0] : localize(code, args); env.trees.printMessage(dkind, msg, tree, env.currDocComment, env.currPath.getCompilationUnit()); stats.record(group, dkind, code); } }
Example #25
Source File: Checker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitLink(LinkTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); // simulate inline context on tag stack HtmlTag t = (tree.getKind() == DocTree.Kind.LINK) ? HtmlTag.CODE : HtmlTag.SPAN; tagStack.push(new TagStackItem(tree, t)); try { return super.visitLink(tree, ignore); } finally { tagStack.pop(); } }
Example #26
Source File: VeryPretty.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitVersion(VersionTree node, Void p) { printTagName(node); print(" "); for (DocTree docTree : node.getBody()) { doAccept((DCTree)docTree); } return null; }
Example #27
Source File: RefactoringVisitor.java From netbeans with Apache License 2.0 | 4 votes |
@Override public DocTree visitValue(ValueTree node, Element p) { return instance.visitValue(node, p); }
Example #28
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public boolean isEntity(DocTree doctree) { return isKind(doctree, ENTITY); }
Example #29
Source File: RefactoringVisitor.java From netbeans with Apache License 2.0 | 4 votes |
@Override public DocTree visitSee(SeeTree node, Element p) { return instance.visitSee(node, p); }
Example #30
Source File: Utils.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public boolean isLiteral(DocTree doctree) { return isKind(doctree, LITERAL); }