File tree 3 files changed +49
-5
lines changed
main/java/spoon/support/reflect/code
3 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -85,17 +85,27 @@ public <E extends CtJavaDoc> E removeTag(CtJavaDocTag tag) {
85
85
86
86
@ Override
87
87
public String getShortDescription () {
88
- int indexEndSentence = this .getContent (). indexOf ( '.' );
89
- if (indexEndSentence == -1 ) {
90
- indexEndSentence = this .getContent ().indexOf ('\n' );
88
+ int indexOfFirstSentenceEnd = indexOfFirstSentenceEnd ( this .getContent ());
89
+ if (indexOfFirstSentenceEnd == -1 ) {
90
+ indexOfFirstSentenceEnd = this .getContent ().indexOf ('\n' );
91
91
}
92
- if (indexEndSentence != -1 ) {
93
- return this .getContent ().substring (0 , indexEndSentence + 1 ).trim ();
92
+ if (indexOfFirstSentenceEnd != -1 ) {
93
+ return this .getContent ().substring (0 , indexOfFirstSentenceEnd + 1 ).trim ();
94
94
} else {
95
95
return this .getContent ().trim ();
96
96
}
97
97
}
98
98
99
+ private int indexOfFirstSentenceEnd (String content ) {
100
+ int index = content .indexOf ('.' );
101
+ while (index < content .length () - 1
102
+ && !Character .isWhitespace (content .charAt (index + 1 ))
103
+ && index != -1 ) {
104
+ index = content .indexOf ('.' , index + 1 );
105
+ }
106
+ return index ;
107
+ }
108
+
99
109
/**
100
110
* Parses the content string to split in two: the description and the Javadoc tags
101
111
*/
Original file line number Diff line number Diff line change 80
80
import spoon .test .comment .testclasses .TestClassWithComments ;
81
81
import spoon .test .comment .testclasses .WildComments ;
82
82
import spoon .test .comment .testclasses .WindowsEOL ;
83
+ import spoon .test .comment .testclasses .JavaDocWithLink ;
83
84
84
85
import java .io .File ;
85
86
import java .io .FileInputStream ;
@@ -169,6 +170,22 @@ public void testJavadocShortAndLongComment() {
169
170
assertEquals ("A short description without a proper end" , classJavaDoc .getLongDescription ());
170
171
}
171
172
173
+ @ Test
174
+ public void testJavadocCommentWithLink () {
175
+ // contract: the CtJavaDoc short and long descriptions are correct when the Javadoc comment contains a qualified name
176
+ Factory f = getSpoonFactory ();
177
+ CtClass <?> type = (CtClass <?>) f .Type ().get (JavaDocWithLink .class );
178
+ CtJavaDoc classJavaDoc = (CtJavaDoc ) type .getComments ().get (0 );
179
+ assertEquals ("{@link spoon.Launcher Launcher}." , classJavaDoc .getShortDescription ());
180
+
181
+ classJavaDoc = (CtJavaDoc ) type .getField ("field1" ).getComments ().get (0 );
182
+ assertEquals ("{@link spoon.Launcher Launcher}" , classJavaDoc .getShortDescription ());
183
+
184
+ classJavaDoc = (CtJavaDoc ) type .getField ("field2" ).getComments ().get (0 );
185
+ assertEquals ("{@link spoon.Launcher Launcher}." , classJavaDoc .getShortDescription ());
186
+ assertEquals ("Additional text." , classJavaDoc .getLongDescription ());
187
+ }
188
+
172
189
@ Test
173
190
public void testJavaDocCommentOnMac () {
174
191
String EOL = "\n " ;
Original file line number Diff line number Diff line change
1
+ package spoon .test .comment .testclasses ;
2
+
3
+ /**
4
+ * {@link spoon.Launcher Launcher}.
5
+ */
6
+ public class JavaDocWithLink {
7
+
8
+ /**
9
+ * {@link spoon.Launcher Launcher}
10
+ */
11
+ int field1 ;
12
+
13
+ /**
14
+ * {@link spoon.Launcher Launcher}. Additional text.
15
+ */
16
+ int field2 ;
17
+ }
You can’t perform that action at this time.
0 commit comments