From a6afcac49f4a427492ba22745f501c1b36ca1fa2 Mon Sep 17 00:00:00 2001 From: mnhock Date: Sat, 31 Aug 2024 21:16:44 +0200 Subject: [PATCH] Remove duplicated clazz methods for annotation types --- .../enofex/taikai/java/JavaConfigurer.java | 44 ++++--------------- .../enofex/taikai/java/NamingConfigurer.java | 33 ++------------ 2 files changed, 11 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/enofex/taikai/java/JavaConfigurer.java b/src/main/java/com/enofex/taikai/java/JavaConfigurer.java index fff9682..d3b0f56 100644 --- a/src/main/java/com/enofex/taikai/java/JavaConfigurer.java +++ b/src/main/java/com/enofex/taikai/java/JavaConfigurer.java @@ -116,46 +116,28 @@ public JavaConfigurer classesShouldResideOutsidePackage(String regex, String pac public JavaConfigurer classesShouldBeAnnotatedWith(String regex, Class annotationType) { - return classesShouldBeAnnotatedWith(regex, annotationType, + return classesShouldBeAnnotatedWith(regex, annotationType.getName(), Configuration.defaultConfiguration()); } - public JavaConfigurer classesShouldBeAnnotatedWith(String regex, - Class 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 annotationType) { - return classesShouldNotBeAnnotatedWith(regex, annotationType, + return classesShouldNotBeAnnotatedWith(regex, annotationType.getName(), Configuration.defaultConfiguration()); } - public JavaConfigurer classesShouldNotBeAnnotatedWith(String regex, - Class 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) { @@ -174,20 +156,10 @@ public JavaConfigurer classesShouldNotBeAnnotatedWith(String regex, String annot public JavaConfigurer classesAnnotatedWithShouldResideInPackage( Class annotationType, String packageIdentifier) { - return classesAnnotatedWithShouldResideInPackage(annotationType, packageIdentifier, + return classesAnnotatedWithShouldResideInPackage(annotationType.getName(), packageIdentifier, Configuration.defaultConfiguration()); } - public JavaConfigurer classesAnnotatedWithShouldResideInPackage( - Class 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, diff --git a/src/main/java/com/enofex/taikai/java/NamingConfigurer.java b/src/main/java/com/enofex/taikai/java/NamingConfigurer.java index f34379c..f138d91 100644 --- a/src/main/java/com/enofex/taikai/java/NamingConfigurer.java +++ b/src/main/java/com/enofex/taikai/java/NamingConfigurer.java @@ -47,19 +47,10 @@ public NamingConfigurer classesShouldNotMatch(String regex, Configuration config public NamingConfigurer classesAnnotatedWithShouldMatch( Class annotationType, String regex) { - return classesAnnotatedWithShouldMatch(annotationType, regex, + return classesAnnotatedWithShouldMatch(annotationType.getName(), regex, Configuration.defaultConfiguration()); } - public NamingConfigurer classesAnnotatedWithShouldMatch( - Class 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()); @@ -76,19 +67,10 @@ public NamingConfigurer classesAnnotatedWithShouldMatch(String annotationType, S public NamingConfigurer methodsAnnotatedWithShouldMatch( Class annotationType, String regex) { - return methodsAnnotatedWithShouldMatch(annotationType, regex, + return methodsAnnotatedWithShouldMatch(annotationType.getName(), regex, Configuration.defaultConfiguration()); } - public NamingConfigurer methodsAnnotatedWithShouldMatch( - Class 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, @@ -116,19 +98,10 @@ public NamingConfigurer methodsShouldNotMatch(String regex, Configuration config public NamingConfigurer fieldsAnnotatedWithShouldMatch( Class annotationType, String regex) { - return fieldsAnnotatedWithShouldMatch(annotationType, regex, + return fieldsAnnotatedWithShouldMatch(annotationType.getName(), regex, Configuration.defaultConfiguration()); } - public NamingConfigurer fieldsAnnotatedWithShouldMatch( - Class 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());