Skip to content

Commit

Permalink
Merge pull request #4 from footaku/exclude-enum-methods
Browse files Browse the repository at this point in the history
Exclude enum methods
  • Loading branch information
footaku authored Oct 30, 2023
2 parents 5d0af01 + ec6919f commit 5d0b24e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
dependencies {
...
archUnitExtraLib('io.github.footaku:erai:0.0.3')
archUnitExtraLib('io.github.footaku:erai:0.0.4')
...
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "io.github.footaku"
version = "0.0.3"
version = "0.0.4"

repositories {
mavenLocal()
Expand Down Expand Up @@ -73,7 +73,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "io.github.footaku"
artifactId = "erai"
version = "0.0.3"
version = "0.0.4"

pom {
name.set("erai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -63,6 +64,20 @@ public boolean test(JavaMethod input) {
}
};

DescribedPredicate<JavaMethod> isNotEnumBasicMethod =
new DescribedPredicate<>("is not Enum basic methods") {
private final static List<String> 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<JavaMethod> isNotGeneratedCode =
new DescribedPredicate<>("is not generated code") {
private final static List<String> GENERATED_ANNOTATION_NAMES = List.of(
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/example/footaku/EnumClass.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 5d0b24e

Please sign in to comment.