8000 fix(ast): update JavaDocComment to support @return. · googleapis/sdk-platform-java@537e33c · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 537e33c

Browse files
committed
fix(ast): update JavaDocComment to support @return.
1 parent 9b7336d commit 537e33c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/main/java/com/google/api/generator/engine/ast/JavaDocComment.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public abstract static class Builder {
5252
String throwsDescription = null;
5353
String deprecated = null;
5454
List<String> paramsList = new ArrayList<>();
55+
String returnText = null;
5556
List<String> componentsList = new ArrayList<>();
5657
// Private accessor, set complete and consolidated comment.
5758
abstract Builder setComment(String comment);
@@ -69,6 +70,11 @@ public Builder setDeprecated(String deprecatedText) {
6970
return this;
7071
}
7172

73+
public Builder setReturn(String returnDescription) {
74+
returnText = returnDescription;
75+
return this;
76+
}
77+
7278
public Builder addParam(String name, String description) {
7379
paramsList.add(String.format("@param %s %s", name, processParamComment(description)));
7480
return this;
@@ -130,12 +136,16 @@ public boolean emptyComments() {
130136
&& Strings.isNullOrEmpty(throwsDescription)
131137
&& Strings.isNullOrEmpty(deprecated)
132138
&& paramsList.isEmpty()
139+
&& Strings.isNullOrEmpty(returnText)
133140
&& componentsList.isEmpty();
134141
}
135142

136143
public JavaDocComment build() {
137-
// @param, @throws and @deprecated should always get printed at the end.
144+
// @param, @return, @throws and @deprecated should always get printed at the end.
138145
componentsList.addAll(paramsList);
146+
if (!Strings.isNullOrEmpty(returnText)) {
147+
componentsList.add(String.format("@return %s", returnText));
148+
}
139149
if (!Strings.isNullOrEmpty(throwsType)) {
140150
componentsList.add(
141151
String.format("@throws %s %s", throwsType, HtmlEscaper.process(throwsDescription)));

src/test/java/com/google/api/generator/engine/ast/JavaDocCommentTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,30 @@ public void createJavaDocComment_throwsAndDeprecated() {
178178
assertEquals(expected, javaDocComment.comment());
179179
}
180180

181+
@Test
182+
public void createJavaDocComment_paramsAndReturn() {
183+
// No matter how many times or order `setThrows` and `setDeprecated` are called,
184+
// only one @throws and @deprecated will be printed.
185+
String paramName1 = "shelfName";
186+
String paramDescription1 = "The name of the shelf where books are published to.";
187+
String paramName2 = "shelf";
188+
String paramDescription2 = "The shelf to create.";
189+
String returnText = "This is the method return text.";
190+
191+
JavaDocComment javaDocComment =
192+
JavaDocComment.builder()
193+
.addParam(paramName1, paramDescription1)
194+
.addParam(paramName2, paramDescription2)
195+
.setReturn(returnText)
196+
.build();
197+
String expected =
198+
LineFormatter.lines(
199+
"@param shelfName The name of the shelf where books are published to.\n",
200+
"@param shelf The shelf to create.\n",
201+
"@return This is the method return text.");
202+
assertEquals(expected, javaDocComment.comment());
203+
}
204+
181205
@Test
182206
public void createJavaDocComment_allComponents() {
183207
// No matter what order `setThrows`, `setDeprecated` are called,
@@ -190,6 +214,7 @@ public void createJavaDocComment_allComponents() {
190214
String paramDescription1 = "The name of the shelf where books are published to.";
191215
String paramName2 = "shelf";
192216
String paramDescription2 = "The shelf to create.";
217+
String returnText = "This is the method return text.";
193218
String paragraph1 =
194219
"This class provides the ability to make remote calls to the backing service through"
195220
+ " method calls that map to API methods. Sample code to get started:";
@@ -210,6 +235,7 @@ public void createJavaDocComment_allComponents() {
210235
.addParagraph(paragraph2)
211236
.addOrderedList(orderedList)
212237
.addParam(paramName2, paramDescription2)
238+
.setReturn(returnText)
213239
.build();
214240
String expected =
215241
LineFormatter.lines(
@@ -225,6 +251,7 @@ public void createJavaDocComment_allComponents() {
225251
"</ol>\n",
226252
"@param shelfName The name of the shelf where books are published to.\n",
227253
"@param shelf The shelf to create.\n",
254+
"@return This is the method return text.\n",
228255
"@throws com.google.api.gax.rpc.ApiException if the remote call fails.\n",
229256
"@deprecated Use the {@link ArchivedBookName} class instead.");
230257
assertEquals(expected, javaDocComment.comment());

0 commit comments

Comments
 (0)
0