/**Get javadoc for given element. * @deprecated The new DocTree API should be used to traverse Javadoc comments. * Use {@link DocTrees#getDocCommentTree(javax.lang.model.element.Element)} instead. */ @Deprecated public Doc javaDocFor(Element element) { if (element != null) { DocEnv env = DocEnv.instance(ctx); switch (element.getKind()) { case ANNOTATION_TYPE: case CLASS: case ENUM: case INTERFACE: return env.getClassDoc((ClassSymbol)element); case ENUM_CONSTANT: case FIELD: return env.getFieldDoc((VarSymbol)element); case METHOD: if (((MethodSymbol)element).enclClass().getKind() == ElementKind.ANNOTATION_TYPE) return env.getAnnotationTypeElementDoc((MethodSymbol)element); return env.getMethodDoc((MethodSymbol)element); case CONSTRUCTOR: return env.getConstructorDoc((MethodSymbol)element); case PACKAGE: return env.getPackageDoc((PackageSymbol)element); } } return null; }
private Comment updateJavadoc(Element method, Element targetElement, boolean addDeprecated) { Doc javadoc = workingCopy.getElementUtilities().javaDocFor(method); List<Tag> otherTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags())); List<Tag> returnTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags("@return"))); // NOI18N List<Tag> throwsTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags("@throws"))); // NOI18N List<Tag> paramTags = new LinkedList<Tag>(Arrays.asList(javadoc.tags("@param"))); // NOI18N otherTags.removeAll(returnTags); otherTags.removeAll(throwsTags); otherTags.removeAll(paramTags); StringBuilder text = new StringBuilder(javadoc.commentText()).append("\n\n"); // NOI18N text.append(tagsToString(paramTags)); text.append(tagsToString(returnTags)); text.append(tagsToString(throwsTags)); text.append(tagsToString(otherTags)); if(addDeprecated) { String target = targetElement.asType().toString() + "#" + method.getSimpleName(); // NOI18N text.append(org.openide.util.NbBundle.getMessage(MoveMembersTransformer.class, "TAG_Deprecated", target)); } Comment comment = Comment.create(Comment.Style.JAVADOC, NOPOS, NOPOS, NOPOS, text.toString()); return comment; }
/** * {@inheritDoc} * @see com.sun.tools.doclets.internal.toolkit.taglets.Taglet#getTagletOutput(com.sun.javadoc.Doc, com.sun.tools.doclets.internal.toolkit.taglets.TagletWriter) */ @Override public TagletOutput getTagletOutput(Doc doc, TagletWriter writer) throws IllegalArgumentException { Tag[] tags = doc.tags(getName()); if (tags.length==0 && doc instanceof MethodDoc) { // inherit if necessary and possible final DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) doc, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; } if (tags.length==0) return null; final StringBuilder out = writeHeader(new StringBuilder()); for(Tag tag : tags) { writeTag(out, tag, writer); } return new TagletOutputImpl(out.toString()); }
/** * @param usedClassToPackagesMap ClassDoc to (PackageDoc to (UsageType to (Set of Doc))) */ private void addUsedBy(Map usedClassToPackagesMap, ClassDoc usedClass, UsageType usageType, Doc user, PackageDoc userPackage) { Map packageToUsageTypeMap = (Map)usedClassToPackagesMap.get(usedClass); if (null == packageToUsageTypeMap) { packageToUsageTypeMap = new HashMap(); usedClassToPackagesMap.put(usedClass, packageToUsageTypeMap); } Map usageTypeToUsersMap = (Map)packageToUsageTypeMap.get(userPackage); if (null == usageTypeToUsersMap) { usageTypeToUsersMap = new TreeMap(); packageToUsageTypeMap.put(userPackage, usageTypeToUsersMap); } Set userSet = (Set)usageTypeToUsersMap.get(usageType); if (null == userSet) { userSet = new TreeSet(); // FIXME: we need the collator from Main here usageTypeToUsersMap.put(usageType, userSet); } userSet.add(user); }
/** * {@inheritDoc} */ @Override public Content getTagletOutput(Doc doc, TagletWriter writer) throws IllegalArgumentException { Tag[] tags = doc.tags(getName()); if (tags.length==0 && doc instanceof MethodDoc) { // inherit if necessary and possible final DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) doc, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; } if (tags.length==0) return null; final StringBuilder out = writeHeader(new StringBuilder()); for(Tag tag : tags) { writeTag(out, tag, writer); } return new RawHtml(out.toString()); }
/** * Transforms common tags on the Doc object into XML. * * @param doc The Doc object. * @return The corresponding list of nodes. */ private static List<XMLNode> toStandardTags(Doc doc) { // Create the comment node List<XMLNode> nodes = new ArrayList<XMLNode>(); // Handle the tags for (Tag tag : doc.tags()) { Taglet taglet = options.getTagletForName(tag.name().length() > 1? tag.name().substring(1) : ""); if (taglet instanceof BlockTag) { nodes.add(((BlockTag) taglet).toXMLNode(tag)); } } // Add the node to the host return nodes; }
/** * Transforms comments on the Doc object into XML. * * @param doc The Doc object. * @param node The node to add the comment nodes to. */ private static XMLNode toTags(Doc doc) { // Create the comment node XMLNode node = new XMLNode("tags"); boolean hasTags = false; // Handle the tags for (Tag tag : doc.tags()) { Taglet taglet = options.getTagletForName(tag.name().length() > 1? tag.name().substring(1) : ""); if (taglet != null && !(taglet instanceof BlockTag)) { XMLNode tNode = new XMLNode("tag"); tNode.attribute("name", tag.name()); tNode.text(taglet.toString(tag)); node.child(tNode); hasTags = true; } } // Add the node to the host return hasTags? node : null; }
/** * Transforms comments on the Doc object into XML. * * @param doc The Doc object. * @param node The node to add the comment nodes to. */ private static XMLNode toComment(Doc doc) { if (doc.commentText() == null || doc.commentText().length() == 0) return null; XMLNode node = new XMLNode("comment", doc, doc.position().line()); StringBuilder comment = new StringBuilder(); // Analyse each token and produce comment node for (Tag t : doc.inlineTags()) { Taglet taglet = options.getTagletForName(t.name()); if (taglet != null) { comment.append(taglet.toString(t)); } else { comment.append(t.text()); } } return node.text(comment.toString()); }
private static boolean exclude(Doc doc) { // if (doc.name().contains("UnitTest")) { // return true; // } if (doc != null) { if (doc.tags(EXCLUDE_TAG).length > 0) { return true; } else if (doc instanceof ProgramElementDoc) { if (exclude(((ProgramElementDoc) doc).containingPackage())) { return true; } else if (exclude(((ProgramElementDoc) doc).containingClass())) { return true; } } } // nothing above found a reason to exclude return false; }
private static Object process(Object obj, Class expect) { if (obj == null) { return null; } Class cls = obj.getClass(); if (cls.getName().startsWith("com.sun.")) { return Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), new ExcludeHandler(obj)); } else if (obj instanceof Object[]) { Class componentType = expect.getComponentType(); Object[] array = (Object[]) obj; List<Object> list = new ArrayList<>(array.length); for (Object entry : array) { if ((entry instanceof Doc) && exclude((Doc) entry)) { continue; } list.add(process(entry, componentType)); } return list.toArray((Object[]) Array.newInstance(componentType, list.size())); } else { return obj; } }
private String parseIdentifier(Doc doc) { if (doc instanceof ClassDoc) { ClassDoc classDoc = (ClassDoc) doc; return parseIdentifier((Doc) classDoc.containingPackage()) + classDoc.name() + "/"; } else if (doc instanceof AnnotationTypeElementDoc) { AnnotationTypeElementDoc annotationTypeElementDoc = (AnnotationTypeElementDoc) doc; return parseIdentifier((Doc) annotationTypeElementDoc.containingClass()) + "#" + annotationTypeElementDoc.name(); } else if (doc instanceof FieldDoc) { FieldDoc fieldDoc = (FieldDoc) doc; return parseIdentifier((Doc) fieldDoc.containingClass()) + "#" + fieldDoc.name(); } else if (doc instanceof ConstructorDoc) { ConstructorDoc constructorDoc = (ConstructorDoc) doc; return parseIdentifier((Doc) constructorDoc.containingClass()) + "#" + constructorDoc.name() + URLEncoder.encode(constructorDoc.flatSignature()); } else if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; return parseIdentifier((Doc) methodDoc.containingClass()) + "#" + methodDoc.name() + URLEncoder.encode(methodDoc.flatSignature()); } else { return "/" + doc.name() + "/"; } }
/** * Checks the type of the program element and determines comment * accordingly. */ @Override public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) { Doc doc = tag.holder(); String text; if (doc instanceof MethodDoc) { text = methodDoc((MethodDoc) doc); } else if (doc instanceof ClassDoc) { text = classDoc((ClassDoc) doc); } else if (doc instanceof FieldDoc) { text = fieldDoc((FieldDoc) doc); } else { throw new IllegalStateException("Should not happen."); } if (isFirstSentence(writer)) { text = getFirstSentence(text); } TagletOutput result = writer.getOutputInstance(); result.setOutput(text); return result; }
private static String getFirstSentence(Doc doc) { Tag[] tags = doc.firstSentenceTags(); if (tags.length == 0) { return null; } StringBuilder buffer = new StringBuilder(); for (Tag tag : tags) { if (tag instanceof SeeTag) { buffer.append("{"); buffer.append(tag.name()); buffer.append(" "); buffer.append(((SeeTag)tag).referencedClassName()); buffer.append("}"); } else { buffer.append(tag.text()); } } return buffer.toString(); }
private String formatDeprecatedTags(Doc doc) { Tag[] deprecatedTags = doc.tags("deprecated"); if(deprecatedTags.length > 0) { StringBuilder deprecatedText = new StringBuilder(); for(int i = 0; i < deprecatedTags.length; i++) { deprecatedText.append(deprecatedTags[i].text()); if(i < deprecatedTags.length - 1) { deprecatedText.append(" "); } } return deprecatedText.toString(); } else { return null; } }
/** * Filters out hidden elements. */ private static Object filterHidden(Object o, Class<?> expected) { if (o == null) { return null; } Class<?> type = o.getClass(); if (type.getName().startsWith("com.sun.")) { // TODO: Implement interfaces from superclasses, too. return Proxy .newProxyInstance(type.getClassLoader(), type.getInterfaces(), new HideHandler(o)); } else if (o instanceof Object[]) { Class<?> componentType = expected.getComponentType(); Object[] array = (Object[]) o; List<Object> list = new ArrayList<Object>(array.length); for (Object entry : array) { if ((entry instanceof Doc) && isHidden((Doc) entry)) { continue; } list.add(filterHidden(entry, componentType)); } return list.toArray((Object[]) Array.newInstance(componentType, list.size())); } else { return o; } }
@Test public void testTagRender() { Doc mockDoc = mock(Doc.class); Tag mockTag = mock(Tag.class); String tagName = "tagName"; String tagText = "tagText"; String asciidoctorRenderedString = "rendered"; when(mockTag.name()).thenReturn(tagName); when(mockTag.text()).thenReturn(tagText); when(mockDoc.getRawCommentText()).thenReturn("input"); when(mockDoc.commentText()).thenReturn("input"); when(mockDoc.tags()).thenReturn(new Tag[]{mockTag}); when(mockAsciidoctor.render(eq("input"), argThat(new OptionsMatcher(false)))).thenReturn("input"); when(mockAsciidoctor.render(eq(tagText), argThat(new OptionsMatcher(true)))).thenReturn(asciidoctorRenderedString); renderer.renderDoc(mockDoc); verify(mockAsciidoctor).render(eq("input"), argThat(new OptionsMatcher(false))); verify(mockAsciidoctor).render(eq(tagText), argThat(new OptionsMatcher(true))); verify(mockDoc).setRawCommentText("input"); verify(mockDoc).setRawCommentText("input\n" + tagName + " " + asciidoctorRenderedString + "\n"); }
/** * @param usedClassToPackagesMap ClassDoc to (PackageDoc to (UsageType to (Set of Doc))) */ private void addUsedBy(Map<ClassDoc,Map<PackageDoc,Map<UsageType,Set<Doc>>>> usedClassToPackagesMap, ClassDoc usedClass, UsageType usageType, Doc user, PackageDoc userPackage) { Map<PackageDoc,Map<UsageType,Set<Doc>>> packageToUsageTypeMap = usedClassToPackagesMap.get(usedClass); if (null == packageToUsageTypeMap) { packageToUsageTypeMap = new HashMap<PackageDoc,Map<UsageType,Set<Doc>>>(); usedClassToPackagesMap.put(usedClass, packageToUsageTypeMap); } Map<UsageType,Set<Doc>> usageTypeToUsersMap = packageToUsageTypeMap.get(userPackage); if (null == usageTypeToUsersMap) { usageTypeToUsersMap = new TreeMap<UsageType,Set<Doc>>(); packageToUsageTypeMap.put(userPackage, usageTypeToUsersMap); } Set<Doc> userSet = usageTypeToUsersMap.get(usageType); if (null == userSet) { userSet = new TreeSet<Doc>(); // FIXME: we need the collator from Main here usageTypeToUsersMap.put(usageType, userSet); } userSet.add(user); }
public String getPathToRoot(Doc doc) { String path = ""; if (doc != null && !(doc instanceof RootDoc)) { String name = doc.name(); if (doc instanceof ClassDoc) { name = ((ClassDoc) doc).containingPackage().name(); } for (int i = 0; i != name.split("\\.").length; i++) { path += "../"; } } return path; }
public String getPathToRoot() { String path = ""; Doc doc = (Doc) getVariables().get("curitem"); if (getVariables().get("manualPath") != null) { path = (String) getVariables().get("manualPath"); } else if (doc != null && !(doc instanceof RootDoc)) { String name = doc.name(); if (doc instanceof ClassDoc) { name = ((ClassDoc) doc).containingPackage().name(); } for (int i = 0; i != name.split("\\.").length; i++) { path += "../"; } } return path; }
/** * Compares full desc. to short desc. to see wether more infos avail. * @return */ public boolean hasMoreInfos(Doc doc) { //System.out.println(doc.name()); String s1, s2; try { s1 = docWriter.commentTagsToString(null, doc, doc.inlineTags(), false); s2 = docWriter.commentTagsToString(null, doc, doc.firstSentenceTags(), true); } catch (ClassCastException e) { // java/lang/StringBuilder.html codePointAt javadic causes this -> why ?? System.err.println("Error parsing comments for " + doc.name()); return false; } return s1.length() > s2.length() || doc.tags("return").length > 0 || doc.tags("param").length > 0 || doc.tags("see").length > 0 || doc.tags("since").length > 0 || doc.tags("throws").length > 0 || doc.tags("exception").length > 0; }
public Vector getSeeTags() { // adjust the path, so the links get build correctly docWriter.relativePath = getPathToRoot(); Doc pack = (Doc) getVariables().get("curitem"); Tag[] tags = pack.tags("see"); Vector results = new Vector(); for (int i = 0; i != tags.length; i++) { SeeTag tag = (SeeTag) tags[i]; String link = docWriter.seeTagToString(tag); results.add(link); } return results; }
public String getFullDescription(Doc doc) { String text = docWriter.commentTagsToString(null, doc, doc.inlineTags(), false); if (text == null) { text = ""; } if (!containsBreaks(text)) { /** * If there is no html tag, it's probably a raw text comments that would gain * fromm converting line feeds into <br/> */ text = text.replaceAll("\n", "<br/>"); } return text; }
/** * Convert the javadoc comments into an array of my CommentInfo objects. * @param doc * @param cinfos */ private void addSummaryAndRemarksCommentInfo(Doc doc, ArrayList<CommentInfo> cinfos) { String summaryText = concatTags(doc.firstSentenceTags()); String totalText = concatTags(doc.inlineTags()); String remarksText = ""; if (totalText.length() > summaryText.length()) { remarksText = totalText.substring(summaryText.length()).trim(); } if (summaryText.length() != 0) { cinfos.add(makeCommentInfo(CommentInfo.KIND_SUMMARY, summaryText)); } if (remarksText.length() != 0) { cinfos.add(makeCommentInfo(CommentInfo.KIND_REMARKS, remarksText)); } for (Tag tag : doc.tags()) { cinfos.add(makeCommentInfo(tag.kind(), tag.text())); } }
/**Get javadoc for given element. */ public Doc javaDocFor(Element element) { // if (element != null) { // DocEnv env = DocEnv.instance(ctx); // switch (element.getKind()) { // case ANNOTATION_TYPE: // case CLASS: // case ENUM: // case INTERFACE: // return env.getClassDoc((ClassSymbol)element); // case ENUM_CONSTANT: // case FIELD: // return env.getFieldDoc((VarSymbol)element); // case METHOD: // if (((MethodSymbol)element).enclClass().getKind() == ElementKind.ANNOTATION_TYPE) // return env.getAnnotationTypeElementDoc((MethodSymbol)element); // return env.getMethodDoc((MethodSymbol)element); // case CONSTRUCTOR: // return env.getConstructorDoc((MethodSymbol)element); // case PACKAGE: // return env.getPackageDoc((PackageSymbol)element); // } // } return null; }
private static MethodDoc searchInMethods( CompilationInfo javac, TypeElement class2query, TypeElement overriderClass, ExecutableElement overrider) { for (Element elm : class2query.getEnclosedElements()) { if (elm.getKind() == ElementKind.METHOD && javac.getElements().overrides(overrider, (ExecutableElement) elm, overriderClass)) { Doc jdoc = javac.getElementUtilities().javaDocFor(elm); return (jdoc != null && jdoc.getRawCommentText().length() > 0)? (MethodDoc) jdoc: null; } } return null; }
private static Object[] filter(Doc[] array, Class<?> componentType) { if (array == null || array.length == 0) { return array; } List<Object> list = new ArrayList<Object>(array.length); for (Doc entry : array) { if (!exclude(entry)) { list.add(process(entry, componentType)); } } return list.toArray((Object[]) Array.newInstance(componentType, list .size())); }
private static Object[] filter(Doc[] array, Class<?> componentType) { if (array == null || array.length == 0) { return array; } List<Object> list = new ArrayList<Object>(array.length); for (Doc entry : array) { if (!exclude(entry)) { list.add(process(entry, componentType)); } } return list.toArray((Object[]) Array.newInstance(componentType, list.size())); }
private static boolean isResource(Doc doc) { for (Tag t : doc.tags()) { if (t.kind().equals("@h2.resource")) { return true; } } return false; }
void error(Doc d, String s) { SourcePosition sp = d != null ? d.position() : null; if (sp != null) { root.printError(sp, s); } else { root.printError(s); } okSoFar = false; }
void info(Doc d, String s) { if (verbose) { SourcePosition sp = d != null ? d.position() : null; if (log != null) { log.println((sp != null ? sp.toString() + " : " : "") + s); log.flush(); } if (sp != null) { root.printNotice(sp, s); } else { root.printNotice(s); } } }
void notice(Doc d, String s) { SourcePosition sp = d != null ? d.position() : null; if (log != null) { log.println((sp != null ? sp.toString() + " : " : "") + s); log.flush(); } if (sp != null) { root.printNotice(sp, s); } else { root.printNotice(s); } }
public Doc source() { if (setter.isPresent()) { // More likely to be public return setter.get(); } return field.get(); }
/** * Constructs the XMLNode. * * @param name The name of the element * @param doc The source java document the node belongs to. */ public XMLNode(String name, Doc doc, int line) { this._name = name; this._doc = doc; this._attributes = new HashMap<String, String>(); this._children = new ArrayList<XMLNode>(); this._content = new StringBuilder(); this._line = line; }