Skip to content

Commit

Permalink
Add some documentation for the Javadoc patterns.
Browse files Browse the repository at this point in the history
RELNOTES: Add Javadoc docs.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215200762
  • Loading branch information
graememorgan authored and epmjohnston committed Oct 2, 2018
1 parent d4db5fa commit c57ec8c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/bugpattern/javadoc/InvalidParam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Javadoc's `@param` tag should not be used to document parameters which do not
appear in the formal parameter list. This may indicate a typo, or an omission
when refactoring.

```java {.bad}
/**
* Parses {@code input} as a proto.
*
* @param inputBytes input bytes to parse.
*/
MyProto parse(byte[] input) {
...
}
```
25 changes: 25 additions & 0 deletions docs/bugpattern/javadoc/InvalidTag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
A non-standard Javadoc tag was used, or was used in the wrong way. For example,
`@param` should be used as a block tag to describe parameters, but cannot be
used inline to link to parameters (prefer `{@code paramName}` for that).

```java {.bad}
/**
* Doubles {@param n}
*
* @returns two times n
*/
int twoTimes(int n) {
return 2 * n;
}
```

```java {.good}
/**
* Doubles {@code n}
*
* @return two times n
*/
int twoTimes(int n) {
return 2 * n;
}
```
13 changes: 13 additions & 0 deletions docs/bugpattern/javadoc/InvalidThrows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
The `@throws` tag should not document a checked exception which is not actually
thrown by the documented method.

```java {.bad}
/**
* Validates {@code n}.
*
* @throws Exception if n is negative.
*/
void validate(int n) {
...
}
```
12 changes: 12 additions & 0 deletions docs/bugpattern/javadoc/ReturnFromVoid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Methods which do not return anything should not have a `@return` tag.

```java {.bad}
/**
* Frobnicates.
*
* @return a frobnicator
*/
void frobnicator(int a) {
...
}
```

0 comments on commit c57ec8c

Please sign in to comment.