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()); }
protected void processServiceClass(ClassDoc service, Configuration configuration) { Tag[] serviceTagArray = service.tags(WRTagTaglet.NAME); for (int i = 0; i < serviceTagArray.length; i++) { Set<String> serviceTags = WRTagTaglet.getTagSet(serviceTagArray[i] .text()); for (Iterator<String> iter = serviceTags.iterator(); iter.hasNext();) { String tag = iter.next(); if (!this.taggedOpenAPIMethods.containsKey(tag)) { this.taggedOpenAPIMethods .put(tag, new HashSet<MethodDoc>()); } // all method of this service should be processed later. for (int j = 0; j < service.methods().length; j++) { if (configuration.nodeprecated && Util.isDeprecated(service.methods()[j])) { continue; } this.taggedOpenAPIMethods.get(tag) .add(service.methods()[j]); } } this.wrDoc.getWRTags().addAll(serviceTags); } }
protected LinkedList<ModificationRecord> parseModificationRecords(Tag[] tags) { LinkedList<ModificationRecord> result = new LinkedList<ModificationRecord>(); for (int i = 0; i < tags.length; i++) { if ("@author".equalsIgnoreCase(tags[i].name())) { ModificationRecord record = new ModificationRecord(); record.setModifier(tags[i].text()); if (i + 1 < tags.length) { if ("@version".equalsIgnoreCase(tags[i + 1].name())) { record.setVersion(tags[i + 1].text()); if (i + 2 < tags.length && ("@" + WRMemoTaglet.NAME).equalsIgnoreCase(tags[i + 2].name())) { record.setMemo(tags[i + 2].text()); } } else if (("@" + WRMemoTaglet.NAME).equalsIgnoreCase(tags[i + 1].name())) { record.setMemo(tags[i + 1].text()); } } result.add(record); } } return result; }
protected ParameterOccurs parseParameterOccurs(Tag[] tags) { for (int i = 0; i < tags.length; i++) { if (("@" + WROccursTaglet.NAME).equalsIgnoreCase(tags[i].name())) { if (WROccursTaglet.REQUIRED.equalsIgnoreCase(tags[i].text())) { return ParameterOccurs.REQUIRED; } else if (WROccursTaglet.OPTIONAL.equalsIgnoreCase(tags[i].text())) { return ParameterOccurs.OPTIONAL; } else if (WROccursTaglet.DEPENDS.equalsIgnoreCase(tags[i].text())) { return ParameterOccurs.DEPENDS; } else { this.logger.warn("Unexpected WROccursTaglet: " + tags[i].text()); } } } return null; }
@Override protected APIParameter getOutputParam(MethodDoc methodDoc) { APIParameter apiParameter = null; if (methodDoc.returnType() != null) { apiParameter = new APIParameter(); apiParameter.setParameterOccurs(ParameterOccurs.REQUIRED); apiParameter.setType(this.getTypeName(methodDoc.returnType(), false)); for (Tag tag : methodDoc.tags("return")) { apiParameter.setDescription(tag.text()); } HashSet<String> processingClasses = new HashSet<String>(); apiParameter.setFields(this.getFields(methodDoc.returnType(), ParameterType.Response, processingClasses)); apiParameter.setHistory(this.getModificationHistory(methodDoc .returnType())); } return apiParameter; }
/** * @param inlineTags map of (custom) tag names in javadoc to its text. * * @return mocked class doc. */ public static ClassDoc mockClassDoc(final String javadocText, final Map<String, String> inlineTags) { // mock class final ClassDoc mockedClassDoc = Mockito.mock(ClassDoc.class); // mock the javadoc text final Tag[] javadoc = Arrays.stream(javadocText.split("\n")) .map(line -> mockTag(null, line)) .toArray(Tag[]::new); Mockito.when(mockedClassDoc.firstSentenceTags()).thenReturn(javadoc); final Tag[] inline = inlineTags.entrySet().stream() .map(entry -> mockTag(entry.getKey(), entry.getValue())) .toArray(Tag[]::new); Mockito.when(mockedClassDoc.inlineTags()).thenReturn(inline); return mockedClassDoc; }
public String toString(Tag tag) { final String methodName = tag.holder().name(); final String fileName = tag.holder().position().file().toString(); // Note: this makes an assumption that this method is in the battlecode/ package. final String className = fileName.substring(fileName.lastIndexOf("battlecode/"), fileName.length() - 5); // remove .java final MethodCostUtil.MethodData data = MethodCostUtil.getMethodData(className, methodName, LOADER); final int cost; if (data == null) { System.err.println("Warning: no method cost for method: " + className + "/" + methodName + "; assuming 0"); cost = 0; } else { cost = data.cost; } return "<dt><strong>Bytecode cost:</strong></dt><dd><code>" + cost + "</code></dd>"; }
/** * Given an array of <code>Tag</code>s representing this custom * tag, return its string representation. * @param tags the array of <code>Tag</code>s representing of this custom tag. */ public String toString(Tag[] tags) { final String NEWLINE = System.lineSeparator(); if (CreateHTMLKeywords.keywordDescriptionMap == null) CreateHTMLKeywords.initializeKeywordDescriptionMap(); if (tags.length == 0)return null; String result = "\n<DT><B>" + HEADER + "</B></DT>"; result += "<div class=\"block\"><ul>" + NEWLINE; result += "<li>"; int counter = 0; for (int i = 0; i < tags.length; i++) { for (String tag : StringUtils.split(tags [i].text () , ",")) { if (counter > 0) result += ", "; tag = tag.trim (); Pair<String,String> pair = CreateHTMLKeywords.keywordDescriptionMap.get (tag); result += "<a href=\"../../../../../keyword_" + pair.getSecond() + ".html\">" + tag + "</a>"; counter ++; } } result += "</li>" + NEWLINE; result += "</ul></div>" + NEWLINE; return result; }
/** * Given an array of <code>Tag</code>s representing this custom * tag, return its string representation. * @param tags the array of <code>Tag</code>s representing of this custom tag. */ public String toString(Tag[] tags) { if (tags.length == 0) { return null; } //String result = "\n<DT><B>" + HEADER + "</B></DT>"; String result = ""; result += "<div class=\"block\"><table cellpadding=2 cellspacing=0><tr><td>"; for (int i = 0; i < tags.length; i++) { if (i > 0) { result += "<p></p>"; } result += getAlgorithmAssociatedToTag (tags[i]).getDescription(); } return result + "</td></tr></table></div>\n"; }
private IAlgorithm getAlgorithmAssociatedToTag (Tag tag) { File javaFileObject = tag.holder ().position ().file(); String theClassName = ""; while (!javaFileObject.getName ().equals("net2plan")) { theClassName = javaFileObject.getName () + "." + theClassName; if (javaFileObject.getParentFile() == null) break; else javaFileObject = javaFileObject.getParentFile(); } theClassName = "com.net2plan." + theClassName; theClassName = theClassName.substring(0 , theClassName.length ()-6); //without .java IAlgorithm alg = null; try { Class algorithmClass = Taglet_Description.class.getClassLoader().loadClass(theClassName); if (!IAlgorithm.class.isAssignableFrom(algorithmClass)) return null; // not an algorithm alg = (IAlgorithm) algorithmClass.getConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException ("Unexpected exception trying to load class of '" + theClassName + "'"); } return alg; }
/** * Given an array of <code>Tag</code>s representing this custom * tag, return its string representation. * @param tags the array of <code>Tag</code>s representing of this custom tag. */ public String toString(Tag[] tags) { if (tags.length == 0) return null; String result = "\n<DT><B>" + HEADER + "</B></DT>"; result += "<div class=\"block\"><table cellpadding=2 cellspacing=0><tr><td>"; for (int i = 0; i < tags.length; i++) { if (i > 0) result += "<p></p>"; Object algorithm = getAlgorithmAssociatedToTag (tags[i]); if (algorithm == null) continue; if (algorithm instanceof IAlgorithm) result += printInformation(((IAlgorithm) algorithm).getParameters()); else if (algorithm instanceof IReport) result += printInformation(((IReport) algorithm).getParameters()); else if (algorithm instanceof IEventGenerator) result += printInformation(((IEventGenerator) algorithm).getParameters()); else if (algorithm instanceof IEventProcessor) result += printInformation(((IEventProcessor) algorithm).getParameters()); else throw new RuntimeException ("Bad: " + algorithm); } return result + "</td></tr></table></div>\n"; }
public String toString(Tag[] tags) { if (!enabled || tags.length == 0) { return null; } else { StringBuffer result = new StringBuffer(); result.append("<div class=\"classdoc-tag-section-header\">"); result.append(HEADER); result.append("</div>"); result.append("<dl class=\"classdoc-list\">"); for (int i = 0; i < tags.length; i++) { result.append("<dt>"); result.append(tags[i].text()); result.append("</dt>"); } result.append("</dl>"); return result.toString(); } }
public String toString(Tag[] tags) { if (!enabled || tags.length == 0) { return null; } else { StringBuffer result = new StringBuffer(); result.append("<div class=\"classdoc-tag-section-header\">"); result.append(header); result.append("</div>"); result.append("<dl class=\"classdoc-list\">"); for (int i = 0; i < tags.length; i++) { result.append("<dt>"); result.append(tags[i].text()); result.append("</dt>"); } result.append("</dl>"); return result.toString(); } }
protected void printInlineTaglet(Tag tag, TagletContext context, TagletPrinter output) { Taglet taglet = (Taglet)tagletMap.get(tag.name().substring(1)); if (null != taglet) { String tagletString; if (taglet instanceof GnuExtendedTaglet) { tagletString = ((GnuExtendedTaglet)taglet).toString(tag, context); } else { tagletString = taglet.toString(tag); } if (null != tagletString) { output.printTagletString(tagletString); } } else { printWarning("Unknown tag: " + tag.name()); } }
public String toString(Tag tag) { String[] splitted = split(tag); if (splitted == null) return ""; File file = resolve(splitted[0], tag.position()); String contents = null; if (file.exists()) { try { contents = Tools.readTextFile(file); contents = contents.replaceAll("<", "<"); contents = contents.replaceAll(">", ">"); } catch (IOException e) { contents = "Cannot read file '" + file + "': " + e; System.err.println(tag.position() + ": cannot read file '" + file + "'!"); } } else { contents = "File '" + file + "' does not exist!"; System.err.println(tag.position() + ": File '" + file + "' does not exist!"); } return "<pre>" + contents + "</pre><br><center><i>Figure:</i> " + splitted[2] + "</center>"; }
/** * This methods will process the given ``inlineTags`` * comment text, by replacing each link tags * by effective markdown link. * * @param inlineTags Inline tags to generate description from. */ public void description(final Tag [] inlineTags) { for (final Tag tag : inlineTags) { if (("Text").equals(tag.name())) { text(tag.text()); } else if (("@link").equals(tag.name())) { final SeeTag seeTag = (SeeTag) tag; final ClassDoc classDoc = seeTag.referencedClass(); if (classDoc != null) { classLink(source, classDoc); } else { // TODO : Process other link type here. text(tag.text()); } } } }
public static void returnDoc(ApiDoc apiDoc, ClassDoc classDoc, MethodDoc methodDoc) throws Exception { Method method = DocletUtil.getMethodByDoc(Class.forName(classDoc.qualifiedTypeName()), methodDoc); Type returnType = method.getGenericReturnType(); if (returnType.toString().equalsIgnoreCase("void")) { return; } ResultDoc resultDoc = new ResultDoc(); Tag[] tags = methodDoc.tags("return"); if (tags != null && tags.length == 1) { String[] returnTexts = tags[0].text().split("(e.g|eg|e.g.|example|exam|例如|如)(:|:)", 2); resultDoc.setDesc(returnTexts[0]); resultDoc.setExampleValue(returnTexts.length==2 ? returnTexts[1] : ""); resultDoc.setName(""); resultDoc.setType(methodDoc.returnType().typeName() + methodDoc.returnType().dimension()); } addRefType(classDoc, returnType, resultDoc); apiDoc.setResultDoc(resultDoc); }
/** * 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 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()); }
/** * 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 String toComment(Tag tag) { if (tag.text() == null || tag.text().length() == 0) return null; StringBuilder comment = new StringBuilder(); // Analyse each token and produce comment node for (Tag t : tag.inlineTags()) { Taglet taglet = options.getTagletForName(t.name()); if (taglet != null) { comment.append(taglet.toString(t)); } else { comment.append(t.text()); } } return comment.toString(); }
private static List<String> createResourceItem(FieldDoc field){ Tag[] tags = field.tags("@"+ExternalResources.NAME); if(tags.length == 0){ return Collections.emptyList(); } List<String> ret = new ArrayList<>(); String pkg = field.containingPackage().name(); int levels = pkg.length() - pkg.replaceAll("\\.", "").length() + 1; StringBuilder linkLevels = new StringBuilder(""); for(int i = 0; i < levels; i++){ linkLevels.append("../"); } for(Tag tag : tags){ ret.add("<a href=\""+linkLevels.toString()+tag.text().replaceAll("\\.", "/")+".html\">" + tag.text() + "</a> (key = " + field.constantValue() + ")"); } return ret; }
private String tagsToString(List<Tag> tags) { StringBuilder sb = new StringBuilder(); for (Tag tag : tags) { sb.append(tag.name()).append(" ").append(tag.text()).append("\n"); // NOI18N } return sb.toString(); }
private PSOperatorDoc(ClassDoc classDoc, MethodDoc methodDoc) { this.declaringClassDoc = classDoc; this.methodDoc = methodDoc; this.description = methodDoc.commentText().replace('\n', ' '); this.paramDesc = ""; Tag[] paramTags = methodDoc.tags("param"); for (Tag paramTag : paramTags) { String paraStr = paramTag.text(); String paraName = paraStr.substring(0, paraStr.indexOf(' ')).replace('\n', ' ');; String paraDesc = paraStr.substring(paraStr.indexOf(' ') + 1).replace('\n', ' ');; this.paramDesc += "<br> - `" + paraName + "`: " + paraDesc; } this.returnType = methodDoc.returnType(); // ParameterizedType returnType = methodDoc.returnType().asParameterizedType(); // this.inputType = returnType.typeArguments()[0]; // this.outputType = returnType.typeArguments()[1]; // this.completeSignature = "Function<" + this.inputType + ", " + this.outputType + "> " + methodDoc.toString(); String shortSignature = classDoc.name() + "." + methodDoc.name() + "("; boolean firstParameter = true; for (Parameter parameter : methodDoc.parameters()) { if (firstParameter) { shortSignature += Utils.getSimpleTypeName(parameter.type()) + " " + parameter.name(); firstParameter = false; } else { shortSignature += ", " + Utils.getSimpleTypeName(parameter.type()) + " " + parameter.name(); } } shortSignature += ")"; this.shortSignature = shortSignature; }
/** * {@inheritDoc} * @see com.sun.tools.doclets.internal.toolkit.taglets.InheritableTaglet#inherit(com.sun.tools.doclets.internal.toolkit.util.DocFinder.Input, com.sun.tools.doclets.internal.toolkit.util.DocFinder.Output) */ @Override public void inherit(Input input, Output output) { if (input.method != null) { final Tag[] tags = input.method.tags(tagName); if (tags.length > 0) { output.holder = input.method; output.holderTag = tags[0]; output.inlineTags = input.isFirstSentence ? tags[0].firstSentenceTags() : tags[0].inlineTags(); } } }
/** * Appends the formatted definition tag to the given buffer. * @return out */ private StringBuilder writeTag(StringBuilder out, Tag tag, TagletWriter writer) { return out.append(DocletConstants.NL) .append("<DD><CODE>") .append(writer.commentTagsToOutput(tag, null, tag.inlineTags(), false)) .append("</CODE></DD>"); }
public static String concat(Tag[] tags) { StringBuilder result = new StringBuilder(); for (int i = 0; i < tags.length - 1; i++) { result.append(tags[i].text()); result.append("/n"); } if (tags.length > 0) { result.append(tags[tags.length - 1].text()); } return result.toString(); }
public String toString(Tag[] tags) { StringBuilder result = new StringBuilder(); for (int i = 0; i< tags.length - 1; i++) { result.append(tags[i].text()); result.append("/n"); } if(tags.length > 0) { result.append(tags[tags.length - 1].text()); } return result.toString(); }
public static String concat(Tag[] tags) { StringBuilder result = new StringBuilder(); for (int i = 0; i< tags.length - 1; i++) { result.append(tags[i].text()); result.append("/n"); } if(tags.length > 0) { result.append(tags[tags.length - 1].text()); } return result.toString(); }
public static String concatToString(Tag[] tags) { StringBuilder result = new StringBuilder(); for (int i = 0; i < tags.length - 1; i++) { result.append(tags[i].text()); result.append(SPLITTER); } if (tags.length > 0) { result.append(tags[tags.length - 1].text()); } return result.toString(); }
@Override public String toString(Tag[] tags) { StringBuilder result = new StringBuilder(); for (int i = 0; i < tags.length - 1; i++) { result.append(tags[i].text()); result.append(','); } if (tags.length > 0) { result.append(tags[tags.length - 1].text()); } return result.toString(); }