Skip to content

Commit

Permalink
Merge pull request #246 from forge/javadoc_fix
Browse files Browse the repository at this point in the history
Handle spaces in JavadocImpl.getFullSpace
  • Loading branch information
gastaldi authored Jul 9, 2022
2 parents 85e9bf9 + c93c16e commit a45cacd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Set;

import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TextElement;
import org.jboss.forge.roaster.model.JavaDocTag;
Expand Down Expand Up @@ -93,22 +92,14 @@ public String getFullText()
List<Object> fragments = tagElement.fragments();
for (Iterator<Object> iterator = fragments.iterator(); iterator.hasNext();)
{
Object fragment = iterator.next();
if (fragment instanceof SimpleName)
String fragment = iterator.next().toString();
if (text.length() > 0 && (!fragment.startsWith(" ") && text.charAt(text.length() - 1) != ' '))
{
// Param name
text.append(' ').append(fragment);
}
else
{
text.append(fragment);
if (iterator.hasNext())
{
text.append(' ');
}
text.append(' ');
}
text.append(fragment);
}
text.append(System.getProperty("line.separator"));
text.append(System.lineSeparator());
}
return text.toString().trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class JavaDocTest
{
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String LINE_SEPARATOR = System.lineSeparator();

@Test
public void testJavaDocParsing()
Expand Down Expand Up @@ -205,4 +205,25 @@ public void testJavaDocFullTextShouldFormatParamWithSpace()
+ "@return the modified text",
method.getJavaDoc().getFullText());
}


@Test
public void testJavadocFullTextWithSeeTags() {
JavaClassSource src = Roaster.parse(JavaClassSource.class,
"package issue;\npublic class Issue { \n" +
" /**\n" +
" * Convenience entry point for {@link IdCard} assertions when being mixed with other \"assertThat\" assertion libraries.\n" +
" *\n" +
" * @see #assertThat\n" +
" */\n" +
" public static String someMethod(String actual) {\n" +
" return actual;\n" +
" }}");
MethodSource<JavaClassSource> method = src.getMethods().get(0);
assertEquals(
"Convenience entry point for {@link IdCard} assertions when being mixed with other \"assertThat\" assertion libraries.\n"
+ "@see #assertThat",
method.getJavaDoc().getFullText());

}
}

0 comments on commit a45cacd

Please sign in to comment.