Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CtJavadoc#getShortDescription #1827

Merged
merged 2 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/spoon/test/comment/CommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package spoon.test.comment.testclasses;

/**
* A short description without a proper end
*/
public class OtherJavaDoc {
}