115
115
* Default value is {@code public, protected, package, private}.
116
116
* </li>
117
117
* <li>
118
+ * Property {@code allowInlineReturn} - Control whether to allow inline return tags.
119
+ * Type is {@code boolean}.
120
+ * Default value is {@code false}.
121
+ * </li>
122
+ * <li>
118
123
* Property {@code allowMissingParamTags} - Control whether to ignore violations
119
124
* when a method has parameters but does not have matching {@code param} tags in the javadoc.
120
125
* Type is {@code boolean}.
@@ -256,13 +261,21 @@ public class JavadocMethodCheck extends AbstractCheck {
256
261
/** Compiled regexp to match Javadoc tags with no argument. */
257
262
private static final Pattern MATCH_JAVADOC_NOARG =
258
263
CommonUtil .createPattern ("^\\ s*(?>\\ *|\\ /\\ *\\ *)?\\ s*@(return|see)\\ s+\\ S" );
264
+ /** Compiled regexp to match Javadoc tags with no argument allowing inline return tag. */
265
+ private static final Pattern MATCH_JAVADOC_NOARG_INLINE_RETURN =
266
+ CommonUtil .createPattern ("^\\ s*(?>\\ *|\\ /\\ *\\ *)?\\ s*\\ {?@(return|see)\\ s+\\ S" );
259
267
/** Compiled regexp to match first part of multilineJavadoc tags. */
260
268
private static final Pattern MATCH_JAVADOC_NOARG_MULTILINE_START =
261
269
CommonUtil .createPattern ("^\\ s*(?>\\ *|\\ /\\ *\\ *)?\\ s*@(return|see)\\ s*$" );
262
270
/** Compiled regexp to match Javadoc tags with no argument and {}. */
263
271
private static final Pattern MATCH_JAVADOC_NOARG_CURLY =
264
272
CommonUtil .createPattern ("\\ {\\ s*@(inheritDoc)\\ s*\\ }" );
265
273
274
+ /**
275
+ * Control whether to allow inline return tags.
276
+ */
277
+ private boolean allowInlineReturn ;
278
+
266
279
/** Specify the access modifiers where Javadoc comments are checked. */
267
280
private AccessModifierOption [] accessModifiers = {
268
281
AccessModifierOption .PUBLIC ,
@@ -291,6 +304,16 @@ public class JavadocMethodCheck extends AbstractCheck {
291
304
/** Specify annotations that allow missed documentation. */
292
305
private Set <String > allowedAnnotations = Set .of ("Override" );
293
306
307
+ /**
308
+ * Setter to control whether to allow inline return tags.
309
+ *
310
+ * @param value a {@code boolean} value
311
+ * @since 10.22.1
312
+ */
313
+ public void setAllowInlineReturn (boolean value ) {
314
+ allowInlineReturn = value ;
315
+ }
316
+
294
317
/**
295
318
* Setter to control whether to validate {@code throws} tags.
296
319
*
@@ -511,7 +534,11 @@ private boolean hasShortCircuitTag(final DetailAST ast, final List<JavadocTag> t
511
534
* @param comment the Javadoc comment
512
535
* @return the tags found
513
536
*/
514
- private static List <JavadocTag > getMethodTags (TextBlock comment ) {
537
+ private List <JavadocTag > getMethodTags (TextBlock comment ) {
538
+ Pattern matchJavadocNoArg = MATCH_JAVADOC_NOARG ;
539
+ if (allowInlineReturn ) {
540
+ matchJavadocNoArg = MATCH_JAVADOC_NOARG_INLINE_RETURN ;
541
+ }
515
542
final String [] lines = comment .getText ();
516
543
final List <JavadocTag > tags = new ArrayList <>();
517
544
int currentLine = comment .getStartLineNo () - 1 ;
@@ -524,7 +551,7 @@ private static List<JavadocTag> getMethodTags(TextBlock comment) {
524
551
final Matcher javadocArgMissingDescriptionMatcher =
525
552
MATCH_JAVADOC_ARG_MISSING_DESCRIPTION .matcher (lines [i ]);
526
553
final Matcher javadocNoargMatcher =
527
- MATCH_JAVADOC_NOARG .matcher (lines [i ]);
554
+ matchJavadocNoArg .matcher (lines [i ]);
528
555
final Matcher noargCurlyMatcher =
529
556
MATCH_JAVADOC_NOARG_CURLY .matcher (lines [i ]);
530
557
final Matcher noargMultilineStart =
0 commit comments