@Test public void formatterHandlesAllCommentElements() { Comment c = new Comment(Arrays.asList( new CommentText("before "), new InlineLink(new Link("label", "className", "memberName", null)), new CommentText(" "), new InlineValue(new Value("a.b.c.ClassName", "memberName")), new CommentText(" "), new InlineValue(new Value(null, null)), new CommentText(" "), new InlineTag("code", "List<String>"), new CommentText(" "), new InlineTag("literal", "<>&\""), new InlineTag("unrecognized", "foo"), new CommentText(" "), new CommentElement() { @Override public String toString() { return "unexpected element"; } }, new CommentText(" after") )); String expected = "before {@link className#memberName label} {@value a.b.c.ClassName#memberName} {@value} <code>List&lt;String&gt;</code> &lt;&gt;&amp;&quot;{@unrecognized foo} unexpected element after"; assertEquals(expected, formatter.format(c)); }
public String format(Comment comment) { if (comment == null) { return ""; } StringBuilder sb = new StringBuilder(); for (CommentElement e : comment) { if (e instanceof CommentText) { sb.append(renderText((CommentText) e)); } else if (e instanceof InlineLink) { sb.append(renderLink((InlineLink) e)); } else if (e instanceof InlineValue) { sb.append(renderValue((InlineValue) e)); } else if (e instanceof InlineTag) { sb.append(renderTag((InlineTag) e)); } else { sb.append(renderUnrecognized(e)); } } return sb.toString(); }
CommentFormatter { public String format(Comment comment) { if (comment == null) { return ""; } StringBuilder sb = new StringBuilder(); for (CommentElement e : comment) { if (e instanceof CommentText) { sb.append(renderText((CommentText) e)); } else if (e instanceof InlineLink) { sb.append(renderLink((InlineLink) e)); } else if (e instanceof InlineValue) { sb.append(renderValue((InlineValue) e)); } else if (e instanceof InlineTag) { sb.append(renderTag((InlineTag) e)); } else { sb.append(renderUnrecognized(e)); } } return sb.toString(); } }
CommentFormatter { public String format(Comment comment) { if (comment == null) { return ""; } StringBuilder sb = new StringBuilder(); for (CommentElement e : comment) { if (e instanceof CommentText) { sb.append(renderText((CommentText) e)); } else if (e instanceof InlineLink) { sb.append(renderLink((InlineLink) e)); } else if (e instanceof InlineValue) { sb.append(renderValue((InlineValue) e)); } else if (e instanceof InlineTag) { sb.append(renderTag((InlineTag) e)); } else { sb.append(renderUnrecognized(e)); } } return sb.toString(); }  }
CommentFormatter { public String format(Comment comment) { if (comment == null) { return ""; } StringBuilder sb = new StringBuilder(); for (CommentElement e : comment) { if (e instanceof CommentText) { sb.append(renderText((CommentText) e)); } else if (e instanceof InlineLink) { sb.append(renderLink((InlineLink) e)); } else if (e instanceof InlineValue) { sb.append(renderValue((InlineValue) e)); } else if (e instanceof InlineTag) { sb.append(renderTag((InlineTag) e)); } else { sb.append(renderUnrecognized(e)); } } return sb.toString(); }  String format(Comment comment); }
CommentFormatter { public String format(Comment comment) { if (comment == null) { return ""; } StringBuilder sb = new StringBuilder(); for (CommentElement e : comment) { if (e instanceof CommentText) { sb.append(renderText((CommentText) e)); } else if (e instanceof InlineLink) { sb.append(renderLink((InlineLink) e)); } else if (e instanceof InlineValue) { sb.append(renderValue((InlineValue) e)); } else if (e instanceof InlineTag) { sb.append(renderTag((InlineTag) e)); } else { sb.append(renderUnrecognized(e)); } } return sb.toString(); }  String format(Comment comment);  }