1616
1717package com .google .errorprone .bugpatterns .javadoc ;
1818
19+ import static com .google .common .collect .Range .closedOpen ;
1920import static com .google .errorprone .BugPattern .SeverityLevel .WARNING ;
2021import static com .google .errorprone .bugpatterns .javadoc .Utils .getDiagnosticPosition ;
22+ import static com .google .errorprone .bugpatterns .javadoc .Utils .getEndPosition ;
2123import static com .google .errorprone .bugpatterns .javadoc .Utils .getStartPosition ;
2224import static com .google .errorprone .matchers .Description .NO_MATCH ;
2325
26+ import com .google .common .collect .ImmutableRangeSet ;
2427import com .google .common .collect .ImmutableSet ;
25- import com .google .common .collect .Sets ;
28+ import com .google .common .collect .Range ;
2629import com .google .errorprone .BugPattern ;
2730import com .google .errorprone .VisitorState ;
2831import com .google .errorprone .bugpatterns .BugChecker ;
2932import com .google .errorprone .bugpatterns .BugChecker .ClassTreeMatcher ;
3033import com .google .errorprone .bugpatterns .BugChecker .MethodTreeMatcher ;
3134import com .google .errorprone .bugpatterns .BugChecker .VariableTreeMatcher ;
3235import com .google .errorprone .matchers .Description ;
36+ import com .sun .source .doctree .DocTree ;
3337import com .sun .source .doctree .DocTree .Kind ;
3438import com .sun .source .doctree .LinkTree ;
3539import com .sun .source .doctree .LiteralTree ;
@@ -74,30 +78,32 @@ private Description handle(@Nullable DocTreePath path, VisitorState state) {
7478 if (path == null ) {
7579 return NO_MATCH ;
7680 }
77- ImmutableSet <Integer > recognisedTags = findRecognisedTags (path , state );
81+ ImmutableRangeSet <Integer > recognisedTags = findRecognisedTags (path , state );
7882 ImmutableSet <Integer > tagStrings = findTags (((DCDocComment ) path .getDocComment ()).comment );
7983
80- for (int pos : Sets .difference (tagStrings , recognisedTags )) {
81- state .reportMatch (
82- buildDescription (getDiagnosticPosition (pos , path .getTreePath ().getLeaf ())).build ());
84+ for (int pos : tagStrings ) {
85+ if (!recognisedTags .contains (pos )) {
86+ state .reportMatch (
87+ buildDescription (getDiagnosticPosition (pos , path .getTreePath ().getLeaf ())).build ());
88+ }
8389 }
8490
8591 return NO_MATCH ;
8692 }
8793
88- private ImmutableSet <Integer > findRecognisedTags (DocTreePath path , VisitorState state ) {
89- ImmutableSet .Builder <Integer > tags = ImmutableSet .builder ();
94+ private ImmutableRangeSet <Integer > findRecognisedTags (DocTreePath path , VisitorState state ) {
95+ ImmutableRangeSet .Builder <Integer > tags = ImmutableRangeSet .builder ();
9096 new DocTreePathScanner <Void , Void >() {
9197 @ Override
9298 public Void visitLink (LinkTree linkTree , Void unused ) {
93- tags .add (getStartPosition (linkTree , state ));
99+ tags .add (getRange (linkTree , state ));
94100 return super .visitLink (linkTree , null );
95101 }
96102
97103 @ Override
98104 public Void visitLiteral (LiteralTree literalTree , Void unused ) {
99105 if (literalTree .getKind ().equals (Kind .CODE )) {
100- tags .add (getStartPosition (literalTree , state ));
106+ tags .add (getRange (literalTree , state ));
101107 }
102108 return super .visitLiteral (literalTree , null );
103109 }
@@ -113,4 +119,8 @@ private static ImmutableSet<Integer> findTags(Comment comment) {
113119 }
114120 return tags .build ();
115121 }
122+
123+ private static Range <Integer > getRange (DocTree tree , VisitorState state ) {
124+ return closedOpen (getStartPosition (tree , state ), getEndPosition (tree , state ));
125+ }
116126}
0 commit comments