Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ public int[] getRequiredTokens() {

@Override
public void visitToken(final DetailAST ast) {
final boolean pkgIsNullMarked = Util.isPackageInfoAnnotated(Path.of(this.getFilePath()), NullabilityAnnotationsCheck::isNullMarkedAnnotation);
final DetailAST nullMarkedAnnotation = NullabilityAnnotationsCheck.getNullMarkedAnnotation(ast);
if (pkgIsNullMarked && nullMarkedAnnotation != null) {
if (nullMarkedAnnotation == null) {
return;
}
final boolean pkgIsNullMarked = Util.isPackageInfoAnnotated(Path.of(this.getFilePath()), NullabilityAnnotationsCheck::isNullMarkedAnnotation);
if (pkgIsNullMarked) {
this.log(nullMarkedAnnotation.getLineNo(), ast.getColumnNo() - 1, "Redundant NullMarked annotation");
return;
}
for (DetailAST parentDef = Util.getEnclosingTypeDeclaration(ast); parentDef != null; parentDef = Util.getEnclosingTypeDeclaration(parentDef)) {
if (NullabilityAnnotationsCheck.getNullMarkedAnnotation(parentDef) != null) {
this.log(nullMarkedAnnotation.getLineNo(), ast.getColumnNo() - 1, "Redundant NullMarked annotation");
return;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.papermc.checkstyle.checks;

import io.papermc.checkstyle.CheckTest;
import io.papermc.checkstyle.CheckTestBuilder;

class TestRedundantNullabilityCheck {

@CheckTest("testdata.RedundantNullability")
void test(final CheckTestBuilder builder) {
builder
.addViolation("10:8: Redundant NullMarked annotation")
.addViolation("14:8: Redundant NullMarked annotation")
.addViolation("18:8: Redundant NullMarked annotation")
.addViolation("22:8: Redundant NullMarked annotation")
.addCheck(new RedundantNullabilityCheck());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package testdata;

import org.jspecify.annotations.NullMarked;

public class RedundantNullability {

@NullMarked
public static class OuterClass {

@NullMarked
public static class RedundantInnerClass {
}

@NullMarked
public interface RedundantInnerInterface {
}

@NullMarked
public record RedundantInnerRecord() {
}

@NullMarked
public enum RedundantInnerEnum {
}

public static class ValidInnerClass {
}
}

public static class NonAnnotatedOuter {

@NullMarked
public static class ValidAnnotatedInner {
}
}
}
Loading