diff --git a/README.md b/README.md index dc00c66..8e34f8f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ plugins { dependencies { ... - archUnitExtraLib('io.github.footaku:erai:0.0.3') + archUnitExtraLib('io.github.footaku:erai:0.0.4') ... } diff --git a/build.gradle.kts b/build.gradle.kts index 550d5f4..af0d003 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "io.github.footaku" -version = "0.0.3" +version = "0.0.4" repositories { mavenLocal() @@ -73,7 +73,7 @@ publishing { create("mavenJava") { groupId = "io.github.footaku" artifactId = "erai" - version = "0.0.3" + version = "0.0.4" pom { name.set("erai") diff --git a/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java b/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java index 432d2f2..9ade619 100644 --- a/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java +++ b/src/main/java/io/github/footaku/erai/rule/ShouldBeIndicateReturnValueNullability.java @@ -28,6 +28,7 @@ public void execute(String packagePath, ScopePathProvider scopePathProvider, Col .that(isNotExcludedClass) .and(hasReturnValue) .and(isReturnBoxingType) + .and(isNotEnumBasicMethod) .and(isNotGeneratedCode) .and(isNotOverrideBasicMethod) .should(beAnnotatedWith) @@ -63,6 +64,20 @@ public boolean test(JavaMethod input) { } }; + DescribedPredicate isNotEnumBasicMethod = + new DescribedPredicate<>("is not Enum basic methods") { + private final static List BASIC_METHODS = List.of("$values", "values", "valueOf"); + + @Override + public boolean test(JavaMethod input) { + if (!BASIC_METHODS.contains(input.getName())) { + return true; + } + + return !input.getOwner().isEnum(); + } + }; + DescribedPredicate isNotGeneratedCode = new DescribedPredicate<>("is not generated code") { private final static List GENERATED_ANNOTATION_NAMES = List.of( diff --git a/src/test/java/com/example/footaku/EnumClass.java b/src/test/java/com/example/footaku/EnumClass.java new file mode 100644 index 0000000..3f0cb47 --- /dev/null +++ b/src/test/java/com/example/footaku/EnumClass.java @@ -0,0 +1,24 @@ +package com.example.footaku; + +import java.util.Arrays; + +public enum EnumClass { + NONE(0), + ONE(1), + TWO(2); + + private final int id; + + EnumClass(int id) { + this.id = id; + } + + public int id() { + return id; + } + + @lombok.NonNull + public static EnumClass from(int id) { + return Arrays.stream(EnumClass.values()).filter(v -> v.id == id).findFirst().orElseThrow(); + } +}