com.sun.source.doctree.DocCommentTree Java Examples
The following examples show how to use
com.sun.source.doctree.DocCommentTree.
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: Analyzer.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Void visitDocComment(DocCommentTree node, List<ErrorDescription> errors) { DocTreePath currentDocPath = getCurrentPath(); Void value = super.visitDocComment(node, errors); DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions(); while (!tagStack.isEmpty()) { StartElementTree startTree = tagStack.pop(); Name tagName = startTree.getName(); HtmlTag tag = HtmlTag.get(tagName); if (tag.endKind == HtmlTag.EndKind.REQUIRED) { int s = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree); int e = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree); errors.add(ErrorDescriptionFactory.forSpan(ctx, s, e, TAG_START_UNMATCHED(tagName))); } } return value; }
Example #2
Source File: Env.java From hottub with GNU General Public License v2.0 | 6 votes |
/** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; currDocComment = comment; currElement = trees.getElement(currPath); currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement); AccessKind ak = AccessKind.PUBLIC; for (TreePath p = path; p != null; p = p.getParentPath()) { Element e = trees.getElement(p); if (e != null && e.getKind() != ElementKind.PACKAGE) { ak = min(ak, AccessKind.of(e.getModifiers())); } } currAccess = ak; }
Example #3
Source File: Env.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; currDocComment = comment; currElement = trees.getElement(currPath); currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement); AccessKind ak = AccessKind.PUBLIC; for (TreePath p = path; p != null; p = p.getParentPath()) { Element e = trees.getElement(p); if (e != null && e.getKind() != ElementKind.PACKAGE && e.getKind() != ElementKind.MODULE) { ak = min(ak, AccessKind.of(e.getModifiers())); } } currAccess = ak; }
Example #4
Source File: ModuleInfoTreeAccess.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void testTreePathForModuleDecl(Path base) throws Exception { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) { Path src = base.resolve("src"); tb.writeJavaFiles(src, "/** Test module */ module m1x {}"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(src)); JavacTask task = (JavacTask) compiler.getTask(null, fm, null, null, null, files); task.analyze(); JavacTrees trees = JavacTrees.instance(task); ModuleElement mdle = (ModuleElement) task.getElements().getModuleElement("m1x"); TreePath path = trees.getPath(mdle); assertNotNull("path", path); ModuleElement mdle1 = (ModuleElement) trees.getElement(path); assertNotNull("mdle1", mdle1); DocCommentTree docCommentTree = trees.getDocCommentTree(mdle); assertNotNull("docCommentTree", docCommentTree); } }
Example #5
Source File: Env.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; currDocComment = comment; currElement = trees.getElement(currPath); currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement); AccessKind ak = AccessKind.PUBLIC; for (TreePath p = path; p != null; p = p.getParentPath()) { Element e = trees.getElement(p); if (e != null && e.getKind() != ElementKind.PACKAGE) { ak = min(ak, AccessKind.of(e.getModifiers())); } } currAccess = ak; }
Example #6
Source File: FindLocalUsagesQuery.java From netbeans with Apache License 2.0 | 6 votes |
private void handleJavadoc(TreePath el) { if(el != null) { switch(el.getLeaf().getKind()) { case METHOD: case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: case VARIABLE: DocCommentTree docCommentTree = info.getDocTrees().getDocCommentTree(el); if(docCommentTree != null) { DocTreePath docTreePath = new DocTreePath(el, docCommentTree); docScanner.scan(docTreePath, null); } default: break; } } }
Example #7
Source File: Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: VeryPretty.java From netbeans with Apache License 2.0 | 6 votes |
private VeryPretty(Context context, CodeStyle cs, Map<Tree, ?> tree2Tag, Map<Tree, DocCommentTree> tree2Doc, Map<?, int[]> tag2Span, String origText) { names = Names.instance(context); enclClass = null; commentHandler = CommentHandlerService.instance(context); operators = Operators.instance(context); widthEstimator = new WidthEstimator(context); danglingElseChecker = new DanglingElseChecker(); prec = TreeInfo.notExpression; this.cs = cs; out = new CharBuffer(cs.getRightMargin(), cs.getTabSize(), cs.expandTabToSpaces()); out.addTrimObserver(this); this.indentSize = cs.getIndentSize(); this.tree2Tag = tree2Tag; this.tree2Doc = tree2Doc == null ? Collections.EMPTY_MAP : tree2Doc; this.tag2Span = (Map<Object, int[]>) tag2Span;//XXX this.origText = origText; this.comments = CommentHandlerService.instance(context); }
Example #9
Source File: DocCommentProcessor.java From hottub with GNU General Public License v2.0 | 5 votes |
private void check() { DocCommentTree dc = trees.getDocCommentTree(getCurrentPath()); if (dc == null) return; DocTreeScanner<Void, Void> s = new DocTreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree tree, Void ignore) { messager.printMessage(Diagnostic.Kind.NOTE, tree.getDiagnostic().getMessage(null)); return null; } }; s.scan(dc, null); }
Example #10
Source File: JavadocUtilities.java From netbeans with Apache License 2.0 | 5 votes |
public static DocCommentTree findInheritedDoc(CompilationInfo javac, Element elm) { if (elm.getKind() == ElementKind.METHOD) { TypeElement clazz = (TypeElement) elm.getEnclosingElement(); return searchInInterfaces(javac, clazz, clazz, (ExecutableElement) elm, new HashSet<TypeElement>()); } return null; }
Example #11
Source File: RefactoringVisitor.java From netbeans with Apache License 2.0 | 5 votes |
private void scanJavadoc(TreePath path, Element p) { DocCommentTree docCommentTree = workingCopy.getDocTrees().getDocCommentTree(path); if(docCommentTree != null) { DocTreePath docTreePath = new DocTreePath(path, docCommentTree); docScanner.scan(docTreePath, p); } }
Example #12
Source File: JavacTrees.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public DocCommentTree getDocCommentTree(TreePath path) { CompilationUnitTree t = path.getCompilationUnit(); Tree leaf = path.getLeaf(); if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { JCCompilationUnit cu = (JCCompilationUnit) t; if (cu.docComments != null) { return cu.docComments.getCommentTree((JCTree) leaf); } } return null; }
Example #13
Source File: Checker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitDocComment(DocCommentTree tree, Void ignore) { super.visitDocComment(tree, ignore); for (TagStackItem tsi: tagStack) { warnIfEmpty(tsi, null); if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT && tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) { StartElementTree t = (StartElementTree) tsi.tree; env.messages.error(HTML, t, "dc.tag.not.closed", t.getName()); } } return null; }
Example #14
Source File: Test.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void checkComment() { DocCommentTree dc = trees.getDocCommentTree(getCurrentPath()); if (dc != null) { out.println("comment: " + dc.toString().replaceAll("\\s+", " ")); docComments++; } }
Example #15
Source File: VeryPretty.java From netbeans with Apache License 2.0 | 5 votes |
private void printPrecedingComments(JCTree tree, boolean printWhitespace) { if (!precedingCommentsHandled.add(tree)) { return; } CommentSet commentSet = commentHandler.getComments(tree); java.util.List<Comment> pc = commentSet.getComments(CommentSet.RelativePosition.PRECEDING); DocCommentTree doc = tree2Doc.get(tree); if (!pc.isEmpty()) { Comment javadoc = null; for (Comment comment : pc) { if(comment.style() == Style.JAVADOC) { javadoc = comment; } } for (Comment c : pc) { if(doc != null && c == javadoc) { print((DCTree)doc); doc = null; } else { printComment(c, true, printWhitespace); } } } if(doc!=null) { print((DCTree)doc); } }
Example #16
Source File: DocTreePath.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Creates a DocTreePath for a root node. * * @param treePath the TreePath from which the root node was created. * @param t the DocCommentTree to create the path for. */ public DocTreePath(TreePath treePath, DocCommentTree t) { treePath.getClass(); t.getClass(); this.treePath = treePath; this.docComment = t; this.parent = null; this.leaf = t; }
Example #17
Source File: Test.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void checkComment() { DocCommentTree dc = trees.getDocCommentTree(getCurrentPath()); if (dc != null) { out.println("comment: " + dc.toString().replaceAll("\\s+", " ")); docComments++; } }
Example #18
Source File: RemoveUnusedImports.java From google-java-format with Apache License 2.0 | 5 votes |
private void scanJavadoc() { if (getCurrentPath() == null) { return; } DocCommentTree commentTree = trees.getDocCommentTree(getCurrentPath()); if (commentTree == null) { return; } docTreeSymbolScanner.scan(new DocTreePath(getCurrentPath(), commentTree), null); }
Example #19
Source File: JavadocCompletionUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks whether Doc instance matches to its token sequence representation. * @param javadoc Doc instance of javadoc * @param ts javadoc token sequence * @return true if it is valid javadoc * * @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=139147">139147</a> */ public static boolean isInvalidDocInstance(DocCommentTree javadoc, TokenSequence<JavadocTokenId> ts) { if (javadoc == null || javadoc.getFullBody().isEmpty()) { if (!ts.isEmpty()) { ts.moveStart(); return !(ts.moveNext() && isTokenOfEmptyJavadoc(ts.token()) && ts.moveNext() == false); } } return false; }
Example #20
Source File: ElementJavadoc.java From netbeans with Apache License 2.0 | 5 votes |
private void appendReference(StringBuilder sb, ReferenceTree ref, List<? extends DocTree> label, TreePath docPath, DocCommentTree doc, DocTrees trees) { String sig = ref.getSignature(); if (sig != null && sig.length() > 0) { if (sig.charAt(0) == '#') { //NOI18N sig = sig.substring(1); } sig = sig.replace('#', '.'); //NOI18N } Element element = trees.getElement(DocTreePath.getPath(docPath, doc, ref)); if (element != null) { createLink(sb, element, label == null || label.isEmpty() ? sig : inlineTags(label, docPath, doc, trees, null)); //NOI18N } else { sb.append(label == null || label.isEmpty() ? sig : inlineTags(label, docPath, doc, trees, null)); } }
Example #21
Source File: JavacTrees.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override @DefinedBy(Api.COMPILER_TREE) public DocCommentTree getDocCommentTree(Element e) { TreePath path = getPath(e); if (path == null) { return null; } return getDocCommentTree(path); }
Example #22
Source File: DocTreePath.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Creates a DocTreePath for a root node. * * @param treePath the TreePath from which the root node was created. * @param t the DocCommentTree to create the path for. */ public DocTreePath(TreePath treePath, DocCommentTree t) { treePath.getClass(); t.getClass(); this.treePath = treePath; this.docComment = t; this.parent = null; this.leaf = t; }
Example #23
Source File: BeakerxDoclet.java From beakerx with Apache License 2.0 | 5 votes |
@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 #24
Source File: DocTreePath.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Creates a DocTreePath for a root node. * * @param treePath the TreePath from which the root node was created. * @param t the DocCommentTree to create the path for. */ public DocTreePath(TreePath treePath, DocCommentTree t) { treePath.getClass(); t.getClass(); this.treePath = treePath; this.docComment = t; this.parent = null; this.leaf = t; }
Example #25
Source File: DocTreePath.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Creates a DocTreePath for a root node. * * @param treePath the TreePath from which the root node was created. * @param t the DocCommentTree to create the path for. */ public DocTreePath(TreePath treePath, DocCommentTree t) { treePath.getClass(); t.getClass(); this.treePath = treePath; this.docComment = t; this.parent = null; this.leaf = t; }
Example #26
Source File: VisibleMemberMap.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void addToPropertiesMap(Element propertyMethod, Element commentSource) { if (null == propertyMethod || null == commentSource) { return; } DocCommentTree docTree = utils.getDocCommentTree(propertyMethod); /* The second condition is required for the property buckets. In * this case the comment is at the property method (not at the field) * and it needs to be listed in the map. */ if ((docTree == null) || propertyMethod.equals(commentSource)) { classPropertiesMap.put(propertyMethod, commentSource); } }
Example #27
Source File: DocTreePathHandle.java From netbeans with Apache License 2.0 | 5 votes |
public DocTreePath resolve(CompilationInfo javac) throws IllegalArgumentException { TreePath p = parent.resolve(javac); if (p == null) { return null; } DocCommentTree docCommentTree = javac.getDocTrees().getDocCommentTree(p); return new DocTreePath(p, docCommentTree); }
Example #28
Source File: JavacTrees.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public DocCommentTree getDocCommentTree(TreePath path) { CompilationUnitTree t = path.getCompilationUnit(); Tree leaf = path.getLeaf(); if (t instanceof JCTree.JCCompilationUnit && leaf instanceof JCTree) { JCCompilationUnit cu = (JCCompilationUnit) t; if (cu.docComments != null) { return cu.docComments.getCommentTree((JCTree) leaf); } } return null; }
Example #29
Source File: DocCommentProcessor.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void check() { DocCommentTree dc = trees.getDocCommentTree(getCurrentPath()); if (dc == null) return; DocTreeScanner<Void, Void> s = new DocTreeScanner<Void, Void>() { @Override public Void visitErroneous(ErroneousTree tree, Void ignore) { messager.printMessage(Diagnostic.Kind.NOTE, tree.getDiagnostic().getMessage(null)); return null; } }; s.scan(dc, null); }
Example #30
Source File: Checker.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public Void visitDocComment(DocCommentTree tree, Void ignore) { super.visitDocComment(tree, ignore); for (TagStackItem tsi: tagStack) { warnIfEmpty(tsi, null); if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT && tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) { StartElementTree t = (StartElementTree) tsi.tree; env.messages.error(HTML, t, "dc.tag.not.closed", t.getName()); } } return null; }