Skip to content

Commit

Permalink
ignore javadoc comments for commented out code check
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed Apr 10, 2024
1 parent bbb274b commit 5bfc4dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

Expand All @@ -26,6 +27,10 @@ public class CommentedOutCodeCheck extends IntegratedCheck {
private static final Comparator<SourcePosition> POSITION_COMPARATOR =
Comparator.comparingInt(SourcePosition::getSourceStart);
private static final Translatable MESSAGE = new LocalizedMessage("commented-out-code");
private static final Set<CtComment.CommentType> ALLOWED_COMMENT_TYPES = Set.of(
CtComment.CommentType.BLOCK,
CtComment.CommentType.INLINE
);

@Override
protected void check(StaticAnalysis staticAnalysis, DynamicAnalysis dynamicAnalysis) {
Expand All @@ -34,6 +39,9 @@ protected void check(StaticAnalysis staticAnalysis, DynamicAnalysis dynamicAnaly
staticAnalysis.processWith(new AbstractProcessor<CtComment>() {
@Override
public void process(CtComment comment) {
if (!ALLOWED_COMMENT_TYPES.contains(comment.getCommentType())) {
return;
}
String content = comment.getContent().trim();

if (StringUtils.containsAny(content, ';', '{', '}', '=')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,27 @@ public class Test {

problems.assertExhausted();
}

@Test
void testJavadoc() throws IOException, LinterException {
ProblemIterator problems = this.checkIterator(
StringSourceInfo.fromSourceString(
JavaVersion.JAVA_17,
"RunCommand",
"""
/**
* This {@link RunCommand} executes a run on the target.
*
* @author Programmieren-Team
*/
public class RunCommand {
// some comment
}
"""
),
PROBLEM_TYPES
);

problems.assertExhausted();
}
}

0 comments on commit 5bfc4dd

Please sign in to comment.