Skip to content

Commit

Permalink
Remove duplicated clazz methods for annotation types
Browse files Browse the repository at this point in the history
  • Loading branch information
mnhock committed Aug 31, 2024
1 parent 22ef364 commit a6afcac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 66 deletions.
44 changes: 8 additions & 36 deletions src/main/java/com/enofex/taikai/java/JavaConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,46 +116,28 @@ public JavaConfigurer classesShouldResideOutsidePackage(String regex, String pac

public JavaConfigurer classesShouldBeAnnotatedWith(String regex,
Class<? extends Annotation> annotationType) {
return classesShouldBeAnnotatedWith(regex, annotationType,
return classesShouldBeAnnotatedWith(regex, annotationType.getName(),
Configuration.defaultConfiguration());
}

public JavaConfigurer classesShouldBeAnnotatedWith(String regex,
Class<? extends Annotation> annotationType, Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().haveNameMatching(regex)
.should().beMetaAnnotatedWith(annotationType)
.as("Classes have name matching %s should be annotated with %s".formatted(
regex, annotationType.getName())), configuration));
}

public JavaConfigurer classesShouldBeAnnotatedWith(String regex, String annotationType) {
return classesShouldBeAnnotatedWith(regex, annotationType,
Configuration.defaultConfiguration());
}

public JavaConfigurer classesShouldBeAnnotatedWith(String regex, String annotationType,
Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().haveNameMatching(regex)
.should().beMetaAnnotatedWith(annotationType)
.as("Classes have name matching %s should be annotated with %s".formatted(regex,
annotationType)), configuration));
}

public JavaConfigurer classesShouldNotBeAnnotatedWith(String regex,
Class<? extends Annotation> annotationType) {
return classesShouldNotBeAnnotatedWith(regex, annotationType,
return classesShouldNotBeAnnotatedWith(regex, annotationType.getName(),
Configuration.defaultConfiguration());
}

public JavaConfigurer classesShouldNotBeAnnotatedWith(String regex,
Class<? extends Annotation> annotationType, Configuration configuration) {
public JavaConfigurer classesShouldBeAnnotatedWith(String regex, String annotationType,
Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().haveNameMatching(regex)
.should().notBeMetaAnnotatedWith(annotationType)
.as("Classes have name matching %s should not be annotated with %s".formatted(
regex, annotationType.getName())), configuration));
.should().beMetaAnnotatedWith(annotationType)
.as("Classes have name matching %s should be annotated with %s".formatted(regex,
annotationType)), configuration));
}

public JavaConfigurer classesShouldNotBeAnnotatedWith(String regex, String annotationType) {
Expand All @@ -174,20 +156,10 @@ public JavaConfigurer classesShouldNotBeAnnotatedWith(String regex, String annot

public JavaConfigurer classesAnnotatedWithShouldResideInPackage(
Class<? extends Annotation> annotationType, String packageIdentifier) {
return classesAnnotatedWithShouldResideInPackage(annotationType, packageIdentifier,
return classesAnnotatedWithShouldResideInPackage(annotationType.getName(), packageIdentifier,
Configuration.defaultConfiguration());
}

public JavaConfigurer classesAnnotatedWithShouldResideInPackage(
Class<? extends Annotation> annotationType, String packageIdentifier,
Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().areMetaAnnotatedWith(annotationType)
.should().resideInAPackage(packageIdentifier)
.as("Classes annotated with %s should reside in package %s".formatted(
annotationType.getName(), packageIdentifier)), configuration));
}

public JavaConfigurer classesAnnotatedWithShouldResideInPackage(
String annotationType, String packageIdentifier) {
return classesAnnotatedWithShouldResideInPackage(annotationType, packageIdentifier,
Expand Down
33 changes: 3 additions & 30 deletions src/main/java/com/enofex/taikai/java/NamingConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,10 @@ public NamingConfigurer classesShouldNotMatch(String regex, Configuration config

public NamingConfigurer classesAnnotatedWithShouldMatch(
Class<? extends Annotation> annotationType, String regex) {
return classesAnnotatedWithShouldMatch(annotationType, regex,
return classesAnnotatedWithShouldMatch(annotationType.getName(), regex,
Configuration.defaultConfiguration());
}

public NamingConfigurer classesAnnotatedWithShouldMatch(
Class<? extends Annotation> annotationType, String regex, Configuration configuration) {
return addRule(TaikaiRule.of(classes()
.that().areMetaAnnotatedWith(annotationType)
.should().haveNameMatching(regex)
.as("Classes annotated with %s should have names matching %s".formatted(
annotationType.getName(), regex)), configuration));
}

public NamingConfigurer classesAnnotatedWithShouldMatch(String annotationType, String regex) {
return classesAnnotatedWithShouldMatch(annotationType, regex,
Configuration.defaultConfiguration());
Expand All @@ -76,19 +67,10 @@ public NamingConfigurer classesAnnotatedWithShouldMatch(String annotationType, S

public NamingConfigurer methodsAnnotatedWithShouldMatch(
Class<? extends Annotation> annotationType, String regex) {
return methodsAnnotatedWithShouldMatch(annotationType, regex,
return methodsAnnotatedWithShouldMatch(annotationType.getName(), regex,
Configuration.defaultConfiguration());
}

public NamingConfigurer methodsAnnotatedWithShouldMatch(
Class<? extends Annotation> annotationType, String regex, Configuration configuration) {
return addRule(TaikaiRule.of(methods()
.that().areMetaAnnotatedWith(annotationType)
.should().haveNameMatching(regex)
.as("Methods annotated with %s should have names matching %s".formatted(
annotationType.getName(), regex)), configuration));
}

public NamingConfigurer methodsAnnotatedWithShouldMatch(
String annotationType, String regex) {
return methodsAnnotatedWithShouldMatch(annotationType, regex,
Expand Down Expand Up @@ -116,19 +98,10 @@ public NamingConfigurer methodsShouldNotMatch(String regex, Configuration config

public NamingConfigurer fieldsAnnotatedWithShouldMatch(
Class<? extends Annotation> annotationType, String regex) {
return fieldsAnnotatedWithShouldMatch(annotationType, regex,
return fieldsAnnotatedWithShouldMatch(annotationType.getName(), regex,
Configuration.defaultConfiguration());
}

public NamingConfigurer fieldsAnnotatedWithShouldMatch(
Class<? extends Annotation> annotationType, String regex, Configuration configuration) {
return addRule(TaikaiRule.of(fields()
.that().areMetaAnnotatedWith(annotationType)
.should().haveNameMatching(regex)
.as("Fields annotated with %s should have names matching %s".formatted(
annotationType.getName(), regex)), configuration));
}

public NamingConfigurer fieldsAnnotatedWithShouldMatch(String annotationType, String regex) {
return fieldsAnnotatedWithShouldMatch(annotationType, regex,
Configuration.defaultConfiguration());
Expand Down

0 comments on commit a6afcac

Please sign in to comment.