diff --git a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java index fbd4d316ca4..933843bca5d 100644 --- a/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java +++ b/src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java @@ -92,20 +92,23 @@ public String getShortDescription() { if (indexEndSentence == -1) { indexEndSentence = this.getContent().indexOf("\n"); } - if (indexEndSentence == -1) { - indexEndSentence = this.getContent().length(); - } if (indexEndSentence != -1) { return this.getContent().substring(0, indexEndSentence + 1).trim(); + } else { + return this.getContent().trim(); } - return ""; } @Override public String getLongDescription() { int indexStartLongDescription = getShortDescription().length(); - return this.getContent().substring(indexStartLongDescription).trim(); + if (indexStartLongDescription < this.getContent().trim().length()) { + return this.getContent().substring(indexStartLongDescription).trim(); + } else { + return this.getContent().trim(); + } + } @Override diff --git a/src/test/java/spoon/test/comment/CommentTest.java b/src/test/java/spoon/test/comment/CommentTest.java index 3344aefc01c..c1bc5186827 100644 --- a/src/test/java/spoon/test/comment/CommentTest.java +++ b/src/test/java/spoon/test/comment/CommentTest.java @@ -48,6 +48,7 @@ import spoon.test.comment.testclasses.InlineComment; import spoon.test.comment.testclasses.JavaDocComment; import spoon.test.comment.testclasses.JavaDocEmptyCommentAndTags; +import spoon.test.comment.testclasses.OtherJavaDoc; import spoon.test.comment.testclasses.WildComments; import spoon.test.comment.testclasses.WindowsEOL; @@ -130,6 +131,16 @@ public void testJavaDocCommentOnUnix() { this.testJavaDocComment(type, EOL); } + @Test + public void testJavadocShortAndLongComment() { + // contract: in case we cannot determine if it is a short comment, we take the whole content + Factory f = getSpoonFactory(); + CtClass type = (CtClass)f.Type().get(OtherJavaDoc.class); + CtJavaDoc classJavaDoc = (CtJavaDoc) type.getComments().get(0); + assertEquals("A short description without a proper end", classJavaDoc.getShortDescription()); + assertEquals("A short description without a proper end", classJavaDoc.getLongDescription()); + } + @Test public void testJavaDocCommentOnMac() { String EOL = "\n"; diff --git a/src/test/java/spoon/test/comment/testclasses/OtherJavaDoc.java b/src/test/java/spoon/test/comment/testclasses/OtherJavaDoc.java new file mode 100644 index 00000000000..d70420eb91b --- /dev/null +++ b/src/test/java/spoon/test/comment/testclasses/OtherJavaDoc.java @@ -0,0 +1,7 @@ +package spoon.test.comment.testclasses; + +/** + * A short description without a proper end + */ +public class OtherJavaDoc { +}