JavaDocUtils { public String getParameterSummary(String paramName, Element element) { String comment = elements.getDocComment(element); if (StringUtils.isBlank(comment)) { return null; } comment = comment.trim(); StringBuilder parameterCommentBuilder = new StringBuilder(); boolean insideParameter = false; StringTokenizer st = new StringTokenizer(comment, "\n\r"); while (st.hasMoreTokens()) { String nextToken = st.nextToken().trim(); if (nextToken.startsWith("@param " + paramName + " " ) || nextToken.equals("@param " + paramName)) { insideParameter = true; } else if (nextToken.startsWith("@")) { insideParameter = false; } if (insideParameter) { parameterCommentBuilder.append(nextToken).append(" "); } } int startIndex = 7 + paramName.length() + 1; if (parameterCommentBuilder.length() < startIndex) { return null; } String parameterComment = parameterCommentBuilder.substring(startIndex); StringBuilder strippedCommentBuilder = new StringBuilder(); boolean insideTag = false; for (int i = 0; i < parameterComment.length(); i++) { if (parameterComment.charAt(i) == '{' && parameterComment.charAt(i + 1) == '@') { insideTag = true; } else if (parameterComment.charAt(i) == '}') { insideTag = false; } else { if (!insideTag) { strippedCommentBuilder.append(parameterComment.charAt(i)); } } } String strippedComment = strippedCommentBuilder.toString().trim(); while (strippedComment.length() > 0 && strippedComment.charAt(strippedComment.length() - 1) == '\n') { strippedComment = StringUtils.chomp(strippedComment); } return strippedComment; } JavaDocUtils(Elements elements); String getSummary(Element element); boolean hasTag(String tagName, Element element); String getTagContent(String tagName, Element element); String getParameterSummary(String paramName, Element element);  }
@Test public void getParameterSummary() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Bla bla bla\n" + " \n" + " @param name the name\n" + " @param content the content"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); assertEquals("the content", javaDocUtils.getParameterSummary("content", executableElement)); }
@Test public void getParameterSummaryMultiline() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Bla bla bla\n" + " \n" + " @param name the name\n" + " @param content the \n" + "content"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); assertEquals("the content", javaDocUtils.getParameterSummary("content", executableElement)); }
@Test public void getParameterSummaryParameterNamesDontMatch() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Bla bla bla\n" + " \n" + " @param name the name\n" + " @param content the content"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); assertTrue(StringUtils.isBlank(javaDocUtils.getParameterSummary("cont", executableElement))); }
@Test public void getParameterSummaryParameterNotDocumented() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Bla bla bla\n" + " \n" + " @param name the name\n" + " @param content the content"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); assertTrue(StringUtils.isBlank(javaDocUtils.getParameterSummary("value", executableElement))); }
@Test public void getParameterSummaryParameterWithEmptyComment() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Bla bla bla\n" + " \n" + " @param name the name\n" + " @param content"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); assertTrue(StringUtils.isBlank(javaDocUtils.getParameterSummary("content", executableElement))); }
@Test public void getParameterSummaryStartingAtNextLine() throws Exception { when(elements.getDocComment(executableElement)).thenReturn("\n" + " Authorize a payment\n" + " \n" + " {@sample.xml ../../../doc/mule-module-paypal.xml.sample paypal:authorize}\n" + " @param transactionId\n" + " The value of the order's transaction identification number"); JavaDocUtils javaDocUtils = new JavaDocUtils(elements); assertEquals("The value of the order's transaction identification number", javaDocUtils.getParameterSummary("transactionId", executableElement)); }