Skip to content

Commit

Permalink
MissingSummary: don't fail in the case that javac fails to provide an…
Browse files Browse the repository at this point in the history
… endpos for @see.

Fixes external #1444

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=288656035
  • Loading branch information
graememorgan authored and netdpb committed Jan 8, 2020
1 parent a6b8826 commit d7e5866
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,22 @@ private Description generateReturnFix(

private Description generateSeeFix(DocTreePath docTreePath, SeeTree seeTree, VisitorState state) {
int pos = ((DCDocComment) docTreePath.getDocComment()).comment.getSourcePos(0);
// javac fails to provide an endpos for @see sometimes; don't emit a fix in that case.
SuggestedFix replacement = Utils.replace(seeTree, "", state);
SuggestedFix fix =
SuggestedFix.builder()
.merge(Utils.replace(seeTree, "", state))
.replace(
pos,
pos,
String.format(
"See {@link %s}.\n",
seeTree.getReference().stream().map(Object::toString).collect(joining(" "))))
.build();
replacement.isEmpty()
? replacement
: SuggestedFix.builder()
.merge(replacement)
.replace(
pos,
pos,
String.format(
"See {@link %s}.\n",
seeTree.getReference().stream()
.map(Object::toString)
.collect(joining(" "))))
.build();
return buildDescription(diagnosticPosition(docTreePath, state))
.setMessage(String.format(CONSIDER_USING_MESSAGE, "see"))
.addFix(fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.Position;
import java.util.Optional;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -65,6 +66,9 @@ static SuggestedFix replace(DocTree docTree, String replacement, VisitorState st
int startPos = getStartPosition(docTree, state);
int endPos =
(int) positions.getEndPosition(compilationUnitTree, getDocCommentTree(state), docTree);
if (endPos == Position.NOPOS) {
return SuggestedFix.builder().build();
}
return SuggestedFix.replace(startPos, endPos, replacement);
}

Expand Down

0 comments on commit d7e5866

Please sign in to comment.