From 904caf2ff7979253c3d8f444db79b5c5a6ac0208 Mon Sep 17 00:00:00 2001 From: Tobias Stamann Date: Fri, 23 Feb 2018 01:19:14 +0100 Subject: [PATCH] [#18] Added javadocs and did some polishing for 1.0.0 --- .../generators/AbstractSimpleWriter.java | 29 +- .../generators/FileObjectUtils.java | 14 + .../generators/SimpleJavaWriter.java | 3 + .../generators/package-info.java | 4 + .../tools/ElementUtils.java | 14 +- .../{internal => tools}/Utilities.java | 2 +- .../tools/corematcher/CoreMatchers.java | 14 +- .../ExclusiveCharacteristicCoreMatcher.java | 40 --- ...CharacteristicElementBasedCoreMatcher.java | 37 --- .../ExclusiveCriteriaCoreMatcher.java | 58 ++++ ...lusiveCriteriaElementBasedCoreMatcher.java | 57 ++++ .../corematcher/ImplicitCoreMatcher.java | 20 ++ .../ImplicitElementBasedCoreMatcher.java | 21 +- .../InclusiveCharacteristicCoreMatcher.java | 39 --- ...CharacteristicElementBasedCoreMatcher.java | 41 ++- .../InclusiveCriteriaCoreMatcher.java | 59 ++++ .../tools/corematcher/IsCoreMatcher.java | 22 +- .../IsElementBasedCoreMatcher.java | 20 ++ .../tools/corematcher/package-info.java | 14 + ...ExclusiveCharacteristicsElementFilter.java | 80 ----- .../ExclusiveCriteriaElementFilter.java | 83 +++++ .../tools/filter/Filters.java | 84 ----- .../tools/filter/ImplicitFilter.java | 8 +- ...InclusiveCharacteristicsElementFilter.java | 103 +++--- .../CharacteristicsElementFilterImpl.java | 132 -------- .../impl/CriteriaElementFilterImpl.java | 132 ++++++++ .../tools/filter/package-info.java | 4 + .../fluentfilter/FluentElementFilter.java | 295 ++++++++++++++---- .../tools/fluentfilter/package-info.java | 4 + .../FluentElementValidator.java | 37 ++- .../impl/FluentValidatorMessage.java | 9 +- .../fluentvalidator/impl/package-info.java | 4 + .../tools/fluentvalidator/package-info.java | 4 + .../tools/generics/package-info.java | 4 + .../tools/matcher/CharacteristicsMatcher.java | 27 -- .../tools/matcher/CriteriaMatcher.java | 27 ++ .../tools/matcher/Matchers.java | 91 ------ .../matcher/impl/ByAnnotationMatcher.java | 4 +- .../matcher/impl/ByElementKindMatcher.java | 4 +- .../matcher/impl/ByGenericTypeMatcher.java | 4 +- .../tools/matcher/impl/ByModifierMatcher.java | 4 +- .../tools/matcher/impl/ByNameMatcher.java | 4 +- .../matcher/impl/ByNameRegexMatcher.java | 4 +- .../impl/ByParameterTypeFqnMatcher.java | 4 +- .../matcher/impl/ByParameterTypeMatcher.java | 4 +- .../tools/matcher/impl/ByRawTypeMatcher.java | 4 +- .../matcher/impl/IsAssignableToMatcher.java | 4 +- .../tools/matcher/impl/package-info.java | 4 + ...lusiveCharacteristicsElementValidator.java | 53 ---- .../ExclusiveCriteriaElementValidator.java | 53 ++++ .../tools/validator/ImplicitValidator.java | 2 +- ...lusiveCharacteristicsElementValidator.java | 77 ----- .../InclusiveCriteriaElementValidator.java | 77 +++++ .../tools/validator/Validators.java | 83 ----- .../CharacteristicsElementValidatorImpl.java | 219 ------------- .../impl/CriteriaElementValidatorImpl.java | 219 +++++++++++++ .../generators/SimpleResourceWriterTest.java | 7 - .../internal/UtilitiesTest.java | 1 + .../tools/ElementUtilsTest.java | 39 ++- ...ementUtils_AccessEnclosedElementsTest.java | 1 - ...ementUtils_CheckModifierOfElementTest.java | 1 - ...lusiveCharacteristicElementFilterTest.java | 5 +- .../impl/ByGenericTypeMatcherTest.java | 15 +- .../impl/ByParameterTypeMatcherTest.java | 12 +- .../impl/ParameterTypeFqnMatcherTest.java | 12 +- .../validator/AnnotationValidatorTest.java | 44 +-- .../tools/validator/GenericMatcherTest.java | 4 +- .../validator/ModifierValidatorTest.java | 42 +-- .../tools/validator/ValidatorTest.java | 110 ------- 69 files changed, 1410 insertions(+), 1346 deletions(-) create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/package-info.java rename annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/{internal => tools}/Utilities.java (97%) delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicCoreMatcher.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicElementBasedCoreMatcher.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaCoreMatcher.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaElementBasedCoreMatcher.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicCoreMatcher.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCriteriaCoreMatcher.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/package-info.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCharacteristicsElementFilter.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCriteriaElementFilter.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/Filters.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CharacteristicsElementFilterImpl.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CriteriaElementFilterImpl.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/package-info.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/package-info.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/package-info.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/package-info.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/generics/package-info.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CharacteristicsMatcher.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CriteriaMatcher.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matchers.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/package-info.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCharacteristicsElementValidator.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCriteriaElementValidator.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCharacteristicsElementValidator.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCriteriaElementValidator.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/Validators.java delete mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CharacteristicsElementValidatorImpl.java create mode 100644 annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CriteriaElementValidatorImpl.java delete mode 100644 annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleResourceWriterTest.java delete mode 100644 annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ValidatorTest.java diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/AbstractSimpleWriter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/AbstractSimpleWriter.java index 76e3ff22..0c17b404 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/AbstractSimpleWriter.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/AbstractSimpleWriter.java @@ -8,7 +8,9 @@ import java.util.Map; /** - * Created by tobiasstamann on 24.08.17. + * Abstract base class for writers of java code and resources. + * + */ public class AbstractSimpleWriter { @@ -21,16 +23,32 @@ public AbstractSimpleWriter(T fileObject) throws IOException { this.foWriter = fileObject.openWriter(); } + /** + * Appends string content to the writer. + * @param content the content to append + * @throws IOException is thrown if content can't be written + */ public void append(String content) throws IOException { foWriter.append(content); foWriter.flush(); } + /** + * Write char array content to the writer. + * @param buffer the buffer to append + * @throws IOException is thrown if buffer can't be written + */ public void write(char[] buffer) throws IOException { foWriter.write(buffer); foWriter.flush(); } + /** + * Write a template based content. + * @param templateFileName the template resource file to use + * @param values the values to be used with template + * @throws IOException is thrown if content can't be written + */ public void writeTemplate( String templateFileName, Map values) throws IOException { String processedTemplate = TemplateProcessor.processTemplateResourceFile(templateFileName, values); @@ -40,11 +58,20 @@ public void writeTemplate( String templateFileName, Map values) } + /** + * Write string based content to the writer. + * @param content the content to write + * @throws IOException is thrown if content can't be written + */ public void write(String content) throws IOException { foWriter.write(content); foWriter.flush(); } + /** + * Closes encapsulated writer. + * @throws IOException is thrown if writer can't be closed + */ public void close() throws IOException { foWriter.flush(); foWriter.close(); diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/FileObjectUtils.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/FileObjectUtils.java index 918a5a26..341d83b6 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/FileObjectUtils.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/FileObjectUtils.java @@ -94,10 +94,24 @@ public SimpleResourceWriter createResource(String fileName) throws IOException { } + /** + * Creates a class file writer. + * @param fileName the filename to use + * @param originatingElements the element which originates the creation of the class file + * @return a SimpleJavaWriter that can be used to write java classes + * @throws IOException is thrown if writer can't be created + */ public SimpleJavaWriter createClassFile(String fileName, Element... originatingElements) throws IOException { return new SimpleJavaWriter(ToolingProvider.getTooling().getFiler().createClassFile(fileName, originatingElements)); } + /** + * Creates a source file writer. + * @param fileName the filename to use + * @param originatingElements the element which originates the creation of the source file + * @return a SimpleJavaWriter that can be used to write java source code + * @throws IOException is thrown if writer can't be created + */ public SimpleJavaWriter createSourceFile(String fileName, Element... originatingElements) throws IOException { return new SimpleJavaWriter(ToolingProvider.getTooling().getFiler().createSourceFile(fileName, originatingElements)); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleJavaWriter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleJavaWriter.java index 92e5c58a..aa04cb8a 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleJavaWriter.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleJavaWriter.java @@ -4,6 +4,9 @@ import java.io.IOException; +/** + * A Simple java writer. + */ public class SimpleJavaWriter extends AbstractSimpleWriter { diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/package-info.java new file mode 100644 index 00000000..9295b664 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/generators/package-info.java @@ -0,0 +1,4 @@ +/** + * This package contains utility classes to create resource and java code files. + */ +package io.toolisticon.annotationprocessortoolkit.generators; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils.java index 545c160d..965ff7e8 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils.java @@ -1,8 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; -import io.toolisticon.annotationprocessortoolkit.tools.filter.Filters; -import io.toolisticon.annotationprocessortoolkit.tools.validator.Validators; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -485,7 +483,7 @@ public static boolean hasStrictfpModifier(Element e) { * @return true if passed element has modifier, otherwise false */ private static boolean hasModifier(Element e, Modifier modifier) { - return Validators.MODIFIER_VALIDATOR.hasAllOf(e, modifier); + return CoreMatchers.BY_MODIFIER.getValidator().hasAllOf(e, modifier); } } @@ -657,7 +655,7 @@ public static List getEnclosedElementsByName(Element element, return new ArrayList(); } - return Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), name); + return CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), name); } @@ -712,7 +710,7 @@ public static List getEnclosedElementsOfKind(Element element, return new ArrayList(); } - return Filters.ELEMENT_KIND_FILTER.filterByOneOf(element.getEnclosedElements(), kind); + return CoreMatchers.BY_ELEMENT_KIND.getFilter().filterByOneOf(element.getEnclosedElements(), kind); } @@ -730,7 +728,7 @@ public static List getEnclosedElementsWithAllAnnotationsOf(El return new ArrayList(); } - return Filters.ANNOTATION_FILTER.filterByAllOf(element.getEnclosedElements(), annotations); + return CoreMatchers.BY_ANNOTATION.getFilter().filterByAllOf(element.getEnclosedElements(), annotations); } @@ -747,7 +745,7 @@ public static List getEnclosedElementsWithAtLeastOneAnnotatio return new ArrayList(); } - return Filters.ANNOTATION_FILTER.filterByAtLeastOneOf(element.getEnclosedElements(), annotations); + return CoreMatchers.BY_ANNOTATION.getFilter().filterByAtLeastOneOf(element.getEnclosedElements(), annotations); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/internal/Utilities.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java similarity index 97% rename from annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/internal/Utilities.java rename to annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java index 123d170b..671d3594 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/internal/Utilities.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/Utilities.java @@ -1,4 +1,4 @@ -package io.toolisticon.annotationprocessortoolkit.internal; +package io.toolisticon.annotationprocessortoolkit.tools; import java.util.ArrayList; import java.util.Arrays; diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java index 1eeeae72..eccfc210 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/CoreMatchers.java @@ -54,7 +54,7 @@ private CoreMatchers() { /** * Matcher to check if an Element has a specific name. */ - public final static ExclusiveCharacteristicElementBasedCoreMatcher BY_NAME = new ExclusiveCharacteristicElementBasedCoreMatcher(new ByNameMatcher(), CoreMatcherValidationMessages.BY_NAME); + public final static ExclusiveCriteriaElementBasedCoreMatcher BY_NAME = new ExclusiveCriteriaElementBasedCoreMatcher(new ByNameMatcher(), CoreMatcherValidationMessages.BY_NAME); /** * Matcher to check if an Element name matches a specific regular expression. @@ -70,7 +70,7 @@ private CoreMatchers() { /** * Matcher to check if an Element is of a specific ElementKind. */ - public final static ExclusiveCharacteristicElementBasedCoreMatcher BY_ELEMENT_KIND = new ExclusiveCharacteristicElementBasedCoreMatcher(new ByElementKindMatcher(), CoreMatcherValidationMessages.BY_ELEMENT_KIND); + public final static ExclusiveCriteriaElementBasedCoreMatcher BY_ELEMENT_KIND = new ExclusiveCriteriaElementBasedCoreMatcher(new ByElementKindMatcher(), CoreMatcherValidationMessages.BY_ELEMENT_KIND); /** * Matcher to check if an Element has a specific Modifier. @@ -81,28 +81,28 @@ private CoreMatchers() { /** * Matcher to check if an TypeElement matches a specific generic type. */ - public final static ExclusiveCharacteristicElementBasedCoreMatcher BY_GENERIC_TYPE = new ExclusiveCharacteristicElementBasedCoreMatcher(new ByGenericTypeMatcher(), CoreMatcherValidationMessages.BY_GENERIC_TYPE); + public final static ExclusiveCriteriaElementBasedCoreMatcher BY_GENERIC_TYPE = new ExclusiveCriteriaElementBasedCoreMatcher(new ByGenericTypeMatcher(), CoreMatcherValidationMessages.BY_GENERIC_TYPE); /** * Matcher to check if an TypeElement matches a specific generic type. */ - public final static ExclusiveCharacteristicCoreMatcher BY_RAW_TYPE = new ExclusiveCharacteristicCoreMatcher(new ByRawTypeMatcher(), CoreMatcherValidationMessages.BY_RAW_TYPE); + public final static ExclusiveCriteriaCoreMatcher BY_RAW_TYPE = new ExclusiveCriteriaCoreMatcher(new ByRawTypeMatcher(), CoreMatcherValidationMessages.BY_RAW_TYPE); /** * Matcher to check if an ExecutableElement has specific parameter types */ - public final static ExclusiveCharacteristicCoreMatcher BY_PARAMETER_TYPE_FQN = new ExclusiveCharacteristicCoreMatcher(new ByParameterTypeFqnMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE_FQN); + public final static ExclusiveCriteriaCoreMatcher BY_PARAMETER_TYPE_FQN = new ExclusiveCriteriaCoreMatcher(new ByParameterTypeFqnMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE_FQN); /** * Matcher to check if an ExecutableElement has specific parameter types */ - public final static ExclusiveCharacteristicCoreMatcher BY_PARAMETER_TYPE = new ExclusiveCharacteristicCoreMatcher(new ByParameterTypeMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE); + public final static ExclusiveCriteriaCoreMatcher BY_PARAMETER_TYPE = new ExclusiveCriteriaCoreMatcher(new ByParameterTypeMatcher(), CoreMatcherValidationMessages.BY_PARAMETER_TYPE); /** * Matcher to check if an Element is assignable to a specific type */ - public final static ExclusiveCharacteristicElementBasedCoreMatcher IS_ASSIGNABLE_TO = new ExclusiveCharacteristicElementBasedCoreMatcher(new IsAssignableToMatcher(), CoreMatcherValidationMessages.IS_ASSIGNABLE_TO); + public final static ExclusiveCriteriaElementBasedCoreMatcher IS_ASSIGNABLE_TO = new ExclusiveCriteriaElementBasedCoreMatcher(new IsAssignableToMatcher(), CoreMatcherValidationMessages.IS_ASSIGNABLE_TO); // --------------------------------------------------------------------------------- diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicCoreMatcher.java deleted file mode 100644 index 68277a77..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicCoreMatcher.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.corematcher; - -import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCharacteristicsElementFilter; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCharacteristicsElementValidator; - -import javax.lang.model.element.Element; - - -/** - * Convenience class to use just one class which can be used in Fluent validators and filters. - */ -public class ExclusiveCharacteristicCoreMatcher< - ELEMENT extends Element, - CHARACTERISTIC - > extends AbstractBaseCoreMatcher{ - - - private final CharacteristicsMatcher matcher; - - - public ExclusiveCharacteristicCoreMatcher(CharacteristicsMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { - super(defaultValidatorMessage); - this.matcher = matcher; - } - - public CharacteristicsMatcher getMatcher() { - return matcher; - } - - public ExclusiveCharacteristicsElementValidator> getValidator() { - return new ExclusiveCharacteristicsElementValidator>(matcher, getDefaultValidatorMessage()); - } - - public ExclusiveCharacteristicsElementFilter>> getFilter() { - return new ExclusiveCharacteristicsElementFilter>>(getValidator()); - } - - -} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicElementBasedCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicElementBasedCoreMatcher.java deleted file mode 100644 index 8ae9ffba..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCharacteristicElementBasedCoreMatcher.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.corematcher; - -import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCharacteristicsElementFilter; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCharacteristicsElementValidator; - -import javax.lang.model.element.Element; - -/** - * Convenience class to use just one class which can be used in Fluent validators and filters. - */ -public class ExclusiveCharacteristicElementBasedCoreMatcher< - CHARACTERISTIC - > extends AbstractBaseCoreMatcher{ - - - private final CharacteristicsMatcher matcher; - - public ExclusiveCharacteristicElementBasedCoreMatcher(CharacteristicsMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { - super(defaultValidatorMessage); - this.matcher = matcher; - } - - public CharacteristicsMatcher getMatcher() { - return matcher; - } - - public ExclusiveCharacteristicsElementValidator> getValidator() { - return new ExclusiveCharacteristicsElementValidator>(matcher, this.getDefaultValidatorMessage()); - } - - public ExclusiveCharacteristicsElementFilter>> getFilter() { - return new ExclusiveCharacteristicsElementFilter>>(getValidator()); - } - - -} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaCoreMatcher.java new file mode 100644 index 00000000..154d7736 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaCoreMatcher.java @@ -0,0 +1,58 @@ +package io.toolisticon.annotationprocessortoolkit.tools.corematcher; + +import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCriteriaElementFilter; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCriteriaElementValidator; + +import javax.lang.model.element.Element; + + +/** + * Convenience class to use just one class which can be used in Fluent validators and filters. + */ +public class ExclusiveCriteriaCoreMatcher< + ELEMENT extends Element, + CHARACTERISTIC + > extends AbstractBaseCoreMatcher{ + + /** + * The wrapped criteria matcher. + */ + private final CriteriaMatcher matcher; + + /** + * The constructor. + * @param matcher the criteria matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ + public ExclusiveCriteriaCoreMatcher(CriteriaMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { + super(defaultValidatorMessage); + this.matcher = matcher; + } + + /** + * Gets the wrapped criteria matcher. + * @return the wrapped criteria matcher + */ + public CriteriaMatcher getMatcher() { + return matcher; + } + + /** + * Gets the validator for the wrapped criteria matcher. + * @return the criteria validator instance + */ + public ExclusiveCriteriaElementValidator> getValidator() { + return new ExclusiveCriteriaElementValidator>(matcher, getDefaultValidatorMessage()); + } + + /** + * Gets the filter for the wrapped criteria matcher. + * @return the criteria filter instance + */ + public ExclusiveCriteriaElementFilter>> getFilter() { + return new ExclusiveCriteriaElementFilter>>(getValidator()); + } + + +} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaElementBasedCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaElementBasedCoreMatcher.java new file mode 100644 index 00000000..2fe207b8 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ExclusiveCriteriaElementBasedCoreMatcher.java @@ -0,0 +1,57 @@ +package io.toolisticon.annotationprocessortoolkit.tools.corematcher; + +import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCriteriaElementFilter; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCriteriaElementValidator; + +import javax.lang.model.element.Element; + +/** + * Convenience class to use just one class which can be used in Fluent validators and filters. + */ +public class ExclusiveCriteriaElementBasedCoreMatcher< + CRITERIA + > extends AbstractBaseCoreMatcher{ + + + /** + * The wrapped criteria matcher. + */ + private final CriteriaMatcher matcher; + + /** + * The constructor. + * @param matcher the criteria matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ + public ExclusiveCriteriaElementBasedCoreMatcher(CriteriaMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { + super(defaultValidatorMessage); + this.matcher = matcher; + } + + /** + * Gets the wrapped criteria matcher. + * @return the wrapped criteria matcher + */ + public CriteriaMatcher getMatcher() { + return matcher; + } + + /** + * Gets the validator for the wrapped criteria matcher. + * @return the criteria validator instance + */ + public ExclusiveCriteriaElementValidator> getValidator() { + return new ExclusiveCriteriaElementValidator>(matcher, this.getDefaultValidatorMessage()); + } + + /** + * Gets the filter for the wrapped criteria matcher. + * @return the criteria filter instance + */ + public ExclusiveCriteriaElementFilter>> getFilter() { + return new ExclusiveCriteriaElementFilter>>(getValidator()); + } + + +} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitCoreMatcher.java index 5e411d90..0c3c6d15 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitCoreMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitCoreMatcher.java @@ -14,21 +14,41 @@ public class ImplicitCoreMatcher< > extends AbstractBaseCoreMatcher{ + /** + * The wrapped implicit matcher. + */ private final ImplicitMatcher matcher; + /** + * The constructor. + * @param matcher the implicit matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ public ImplicitCoreMatcher(ImplicitMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { super(defaultValidatorMessage); this.matcher = matcher; } + /** + * Gets the wrapped implicit matcher. + * @return the wrapped implicit matcher + */ public ImplicitMatcher getMatcher() { return matcher; } + /** + * Gets the validator for the wrapped implicit matcher. + * @return the implicit validator instance + */ public ImplicitValidator> getValidator() { return new ImplicitValidator>(matcher, this.getDefaultValidatorMessage()); } + /** + * Gets the filter for the wrapped implicit matcher. + * @return the criteria filter instance + */ public ImplicitFilter>> getFilter() { return new ImplicitFilter>>(getValidator()); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitElementBasedCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitElementBasedCoreMatcher.java index dc88ff46..b47c29d7 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitElementBasedCoreMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/ImplicitElementBasedCoreMatcher.java @@ -12,22 +12,41 @@ */ public class ImplicitElementBasedCoreMatcher extends AbstractBaseCoreMatcher{ - + /** + * The wrapped implicit matcher. + */ private final ImplicitMatcher matcher; + /** + * The constructor. + * @param matcher the implicit matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ public ImplicitElementBasedCoreMatcher(ImplicitMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { super(defaultValidatorMessage); this.matcher = matcher; } + /** + * Gets the wrapped implicit matcher. + * @return the wrapped implicit matcher + */ public ImplicitMatcher getMatcher() { return matcher; } + /** + * Gets the validator for the wrapped implicit matcher. + * @return the implicit validator instance + */ public ImplicitValidator> getValidator() { return new ImplicitValidator>(matcher,this.getDefaultValidatorMessage()); } + /** + * Gets the filter for the wrapped implicit matcher. + * @return the criteria filter instance + */ public ImplicitFilter>> getFilter() { return new ImplicitFilter>>(getValidator()); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicCoreMatcher.java deleted file mode 100644 index 66a47ed1..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicCoreMatcher.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.corematcher; - -import io.toolisticon.annotationprocessortoolkit.tools.filter.InclusiveCharacteristicsElementFilter; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCharacteristicsElementValidator; - -import javax.lang.model.element.Element; - - -/** - * Convenience class to use just one class which can be used in Fluent validators and filters. - */ -public class InclusiveCharacteristicCoreMatcher< - ELEMENT extends Element, - CHARACTERISTIC - > extends AbstractBaseCoreMatcher{ - - - private final CharacteristicsMatcher matcher; - - public InclusiveCharacteristicCoreMatcher(CharacteristicsMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { - super(defaultValidatorMessage); - this.matcher = matcher; - } - - public CharacteristicsMatcher getMatcher() { - return matcher; - } - - public InclusiveCharacteristicsElementValidator> getValidator() { - return new InclusiveCharacteristicsElementValidator>(matcher, this.getDefaultValidatorMessage()); - } - - public InclusiveCharacteristicsElementFilter>> getFilter() { - return new InclusiveCharacteristicsElementFilter>>(getValidator()); - } - - -} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicElementBasedCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicElementBasedCoreMatcher.java index a6131fa1..e45f38d2 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicElementBasedCoreMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCharacteristicElementBasedCoreMatcher.java @@ -1,8 +1,8 @@ package io.toolisticon.annotationprocessortoolkit.tools.corematcher; import io.toolisticon.annotationprocessortoolkit.tools.filter.InclusiveCharacteristicsElementFilter; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCharacteristicsElementValidator; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCriteriaElementValidator; import javax.lang.model.element.Element; @@ -14,24 +14,43 @@ public class InclusiveCharacteristicElementBasedCoreMatcher< CHARACTERISTIC > extends AbstractBaseCoreMatcher{ - - private final CharacteristicsMatcher matcher; - - public InclusiveCharacteristicElementBasedCoreMatcher(CharacteristicsMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { + /** + * The wrapped criteria matcher. + */ + private final CriteriaMatcher matcher; + + /** + * The constructor. + * @param matcher the criteria matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ + public InclusiveCharacteristicElementBasedCoreMatcher(CriteriaMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { super(defaultValidatorMessage); this.matcher = matcher; } - public CharacteristicsMatcher getMatcher() { + /** + * Gets the wrapped criteria matcher. + * @return the wrapped criteria matcher + */ + public CriteriaMatcher getMatcher() { return matcher; } - public InclusiveCharacteristicsElementValidator> getValidator() { - return new InclusiveCharacteristicsElementValidator>(matcher, this.getDefaultValidatorMessage()); + /** + * Gets the validator for the wrapped criteria matcher. + * @return the criteria validator instance + */ + public InclusiveCriteriaElementValidator> getValidator() { + return new InclusiveCriteriaElementValidator>(matcher, this.getDefaultValidatorMessage()); } - public InclusiveCharacteristicsElementFilter>> getFilter() { - return new InclusiveCharacteristicsElementFilter>>(getValidator()); + /** + * Gets the filter for the wrapped criteria matcher. + * @return the criteria filter instance + */ + public InclusiveCharacteristicsElementFilter>> getFilter() { + return new InclusiveCharacteristicsElementFilter>>(getValidator()); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCriteriaCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCriteriaCoreMatcher.java new file mode 100644 index 00000000..0e72d98b --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/InclusiveCriteriaCoreMatcher.java @@ -0,0 +1,59 @@ +package io.toolisticon.annotationprocessortoolkit.tools.corematcher; + +import io.toolisticon.annotationprocessortoolkit.tools.filter.InclusiveCharacteristicsElementFilter; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCriteriaElementValidator; + +import javax.lang.model.element.Element; + + +/** + * Convenience class to use just one class which can be used in Fluent validators and filters. + */ +public class InclusiveCriteriaCoreMatcher< + ELEMENT extends Element, + CHARACTERISTIC + > extends AbstractBaseCoreMatcher { + + /** + * The wrapped criteria matcher. + */ + private final CriteriaMatcher matcher; + + /** + * The constructor. + * @param matcher the criteria matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ + public InclusiveCriteriaCoreMatcher(CriteriaMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { + super(defaultValidatorMessage); + this.matcher = matcher; + } + + /** + * Gets the wrapped criteria matcher. + * + * @return the wrapped criteria matcher + */ + public CriteriaMatcher getMatcher() { + return matcher; + } + + /** + * Gets the validator for the wrapped criteria matcher. + * @return the criteria validator instance + */ + public InclusiveCriteriaElementValidator> getValidator() { + return new InclusiveCriteriaElementValidator>(matcher, this.getDefaultValidatorMessage()); + } + + /** + * Gets the filter for the wrapped criteria matcher. + * @return the criteria filter instance + */ + public InclusiveCharacteristicsElementFilter>> getFilter() { + return new InclusiveCharacteristicsElementFilter>>(getValidator()); + } + + +} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsCoreMatcher.java index a9836a25..47f2e7ff 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsCoreMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsCoreMatcher.java @@ -14,24 +14,42 @@ public class IsCoreMatcher< TARGET_ELEMENT extends Element > extends AbstractBaseCoreMatcher { - + /** + * The wrapped implicit matcher. + */ private final ImplicitMatcher matcher; - + /** + * The constructor. + * @param matcher the implicit matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ public IsCoreMatcher(ImplicitMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { super(defaultValidatorMessage); this.matcher = matcher; } + /** + * Gets the wrapped implicit matcher. + * @return the wrapped implicit matcher + */ public ImplicitMatcher getMatcher() { return matcher; } + /** + * Gets the validator for the wrapped implicit matcher. + * @return the implicit validator instance + */ public ImplicitValidator> getValidator() { return new ImplicitValidator>(matcher, this.getDefaultValidatorMessage()); } + /** + * Gets the filter for the wrapped implicit matcher. + * @return the criteria filter instance + */ public ImplicitFilter>> getFilter() { return new ImplicitFilter>>(getValidator()); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsElementBasedCoreMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsElementBasedCoreMatcher.java index e2ed3fed..88b4edbd 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsElementBasedCoreMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/IsElementBasedCoreMatcher.java @@ -11,21 +11,41 @@ */ public class IsElementBasedCoreMatcher extends AbstractBaseCoreMatcher{ + /** + * The wrapped implicit matcher. + */ private final ImplicitMatcher matcher; + /** + * The constructor. + * @param matcher the implicit matcher to use + * @param defaultValidatorMessage the default message to use with validator + */ public IsElementBasedCoreMatcher(ImplicitMatcher matcher, CoreMatcherValidationMessages defaultValidatorMessage) { super(defaultValidatorMessage); this.matcher = matcher; } + /** + * Gets the wrapped implicit matcher. + * @return the wrapped implicit matcher + */ public ImplicitMatcher getMatcher() { return matcher; } + /** + * Gets the validator for the wrapped implicit matcher. + * @return the implicit validator instance + */ public ImplicitValidator> getValidator() { return new ImplicitValidator>(matcher,this.getDefaultValidatorMessage()); } + /** + * Gets the filter for the wrapped implicit matcher. + * @return the criteria filter instance + */ public ImplicitFilter>> getFilter() { return new ImplicitFilter>>(getValidator()); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/package-info.java new file mode 100644 index 00000000..5908050d --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/corematcher/package-info.java @@ -0,0 +1,14 @@ +/** + * This package contains the implementation classes for the different kinds of CoreMatchers. + * + * Currently there are the following CoreMatcher types: + * + * - Implicit matchers (no arguments) + * - Is matcher (no arguments like implicit matcher, but changes element type) + * - Characteristic matchers + * --> Inclusive matchers (Matcher none, one, at least one or all characteristics) + * --> Exclusive matchers (Matches none or one characteristic) + * + * + */ +package io.toolisticon.annotationprocessortoolkit.tools.corematcher; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCharacteristicsElementFilter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCharacteristicsElementFilter.java deleted file mode 100644 index 154e0958..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCharacteristicsElementFilter.java +++ /dev/null @@ -1,80 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.filter; - -import io.toolisticon.annotationprocessortoolkit.tools.filter.impl.CharacteristicsElementFilterImpl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCharacteristicsElementValidator; - -import javax.lang.model.element.Element; -import java.util.List; - - -/** - * Exclusive characteristic filter based on exclusive characteristic validator. - */ -public class ExclusiveCharacteristicsElementFilter>> { - - private final VALIDATOR validator; - - public ExclusiveCharacteristicsElementFilter(VALIDATOR validator) { - this.validator = validator; - } - - /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. - * - * @param elements the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public List filterByOneOf(List elements, CHARACTERISTIC... characteristicsToCheck) { - - return filterByOneOf(elements,false,characteristicsToCheck); - - } - - - /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. - * - * @param elements the element to check - * @param invertFilter - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public List filterByOneOf(List elements, boolean invertFilter, CHARACTERISTIC... characteristicsToCheck) { - - return CharacteristicsElementFilterImpl.filterByOneOf((CharacteristicsMatcher) validator.getMatcher(), invertFilter, elements, characteristicsToCheck); - - } - - - - /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. - * - * @param elements the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public List filterByNoneOf(List elements, CHARACTERISTIC... characteristicsToCheck) { - - return filterByNoneOf(elements,false,characteristicsToCheck); - - } - - - /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. - * - * @param elements the element to check - * @param invertFilter - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public List filterByNoneOf(List elements, boolean invertFilter, CHARACTERISTIC... characteristicsToCheck) { - - return CharacteristicsElementFilterImpl.filterByNoneOf((CharacteristicsMatcher) validator.getMatcher(), invertFilter, elements, characteristicsToCheck); - - } - -} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCriteriaElementFilter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCriteriaElementFilter.java new file mode 100644 index 00000000..b5841453 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ExclusiveCriteriaElementFilter.java @@ -0,0 +1,83 @@ +package io.toolisticon.annotationprocessortoolkit.tools.filter; + +import io.toolisticon.annotationprocessortoolkit.tools.filter.impl.CriteriaElementFilterImpl; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCriteriaElementValidator; + +import javax.lang.model.element.Element; +import java.util.List; + + +/** + * Exclusive criteria filter based on exclusive criteria validator. + * + * @param The Element type the filter can be applied to + * @param The criteria type + * @param The validator type to use + */ +public class ExclusiveCriteriaElementFilter>> { + + private final VALIDATOR validator; + + public ExclusiveCriteriaElementFilter(VALIDATOR validator) { + this.validator = validator; + } + + /** + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. + * + * @param elements the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public List filterByOneOf(List elements, CRITERIA... criteriaToCheck) { + + return filterByOneOf(elements, false, criteriaToCheck); + + } + + + /** + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. + * + * @param elements the element to check + * @param invertFilter invert filter or not + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public List filterByOneOf(List elements, boolean invertFilter, CRITERIA... criteriaToCheck) { + + return CriteriaElementFilterImpl.filterByOneOf((CriteriaMatcher) validator.getMatcher(), invertFilter, elements, criteriaToCheck); + + } + + + /** + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. + * + * @param elements the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public List filterByNoneOf(List elements, CRITERIA... criteriaToCheck) { + + return filterByNoneOf(elements, false, criteriaToCheck); + + } + + + /** + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. + * + * @param elements the element to check + * @param invertFilter invert filter or not + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public List filterByNoneOf(List elements, boolean invertFilter, CRITERIA... criteriaToCheck) { + + return CriteriaElementFilterImpl.filterByNoneOf((CriteriaMatcher) validator.getMatcher(), invertFilter, elements, criteriaToCheck); + + } + +} \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/Filters.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/Filters.java deleted file mode 100644 index b1c6d5a1..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/Filters.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.filter; - -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; -import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericType; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCharacteristicsElementValidator; -import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCharacteristicsElementValidator; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import java.lang.annotation.Annotation; - -/** - * Core Filters. - * Convenience class that internally uses the {@link CoreMatchers} class to get the filters. - * This might be a good candidate for code generation. - */ -public class Filters { - - /** - * Hidden constructor. - */ - private Filters() { - - } - - /** - * Validator to check if . - */ - //public final static ImplicitFilter>> VALID_JAVA_PROPERTY_FILTER = CoreMatchers.VALID_JAVA_PROPERTY.new ImplicitFilter>>(Validators.VALID_JAVA_PROPERTY_VALIDATOR); - - /** - * Validator to check if an Element matches one or none of the specific names. - */ - public final static ExclusiveCharacteristicsElementFilter>> NAME_FILTER = CoreMatchers.BY_NAME.getFilter(); - - /** - * Validator to check if an Element name matches regular expressions. - */ - public final static InclusiveCharacteristicsElementFilter>> REGEX_NAME_FILTER = CoreMatchers.BY_REGEX_NAME.getFilter(); - - /** - * Validator to check if an Element has annotations. - */ - public final static InclusiveCharacteristicsElementFilter, InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>> ANNOTATION_FILTER = CoreMatchers.BY_ANNOTATION.getFilter(); - - - /** - * Validator to check if an Element has annotations. - */ - public final static ExclusiveCharacteristicsElementFilter>> ELEMENT_KIND_FILTER = CoreMatchers.BY_ELEMENT_KIND.getFilter(); - - /** - * Validator to check if an Element has Modifiers. - */ - public final static InclusiveCharacteristicsElementFilter>> MODIFIER_FILTER = CoreMatchers.BY_MODIFIER.getFilter(); - - - /** - * Validator to check if a TypeElement has a generic type. - */ - public final static ExclusiveCharacteristicsElementFilter>> GENERIC_TYPE_FILTER = CoreMatchers.BY_GENERIC_TYPE.getFilter(); - - /** - * Validator to check if a TypeElement has a generic type. - */ - public final static ExclusiveCharacteristicsElementFilter>> RAW_TYPE_FILTER = CoreMatchers.BY_RAW_TYPE.getFilter(); - - - /** - * Validator to check if an ExecutableElement has specific parameter types - */ - public final static ExclusiveCharacteristicsElementFilter>> PARAMETER_TYPE_FQN_FILTER = CoreMatchers.BY_PARAMETER_TYPE_FQN.getFilter(); - - /** - * Validator to check if an ExecutableElement has specific parameter types - */ - public final static ExclusiveCharacteristicsElementFilter>> PARAMETER_TYPE_FILTER = CoreMatchers.BY_PARAMETER_TYPE.getFilter(); - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilter.java index 864e8873..3ec23b98 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilter.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/ImplicitFilter.java @@ -9,6 +9,8 @@ /** * Implicit filter based on Implicit validator. + * @param The Element type the filter can be applied to + * @param The validator type to use */ public class ImplicitFilter>> { @@ -20,6 +22,7 @@ public ImplicitFilter(VALIDATOR validator) { /** * Filters list of elements by the implicit criteria. + * * @param toFilter the element list to filter * @return the filtered list or an empty list if either validator or element list are null */ @@ -29,7 +32,8 @@ public List filter(List toFilter) { /** * Filters list of elements by the implicit criteria. Allows to do an inverted filtering. - * @param toFilter the element list to filter + * + * @param toFilter the element list to filter * @param invertFilter do invert filtering or not * @return the filtered list or an empty list if either validator or element list are null */ @@ -41,7 +45,7 @@ public List filter(List toFilter, boolean invertFilter) { for (ELEMENT element : toFilter) { - if ((!invertFilter && validator.validate(element)) || (invertFilter && !validator.validate(element)) ){ + if ((!invertFilter && validator.validate(element)) || (invertFilter && !validator.validate(element))) { result.add(element); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicsElementFilter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicsElementFilter.java index 43f0adaf..9ec758e2 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicsElementFilter.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicsElementFilter.java @@ -1,16 +1,20 @@ package io.toolisticon.annotationprocessortoolkit.tools.filter; -import io.toolisticon.annotationprocessortoolkit.tools.filter.impl.CharacteristicsElementFilterImpl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCharacteristicsElementValidator; +import io.toolisticon.annotationprocessortoolkit.tools.filter.impl.CriteriaElementFilterImpl; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCriteriaElementValidator; import javax.lang.model.element.Element; import java.util.List; /** - * Inclusive characteristic filter based on inclusive characteristic validator. + * Inclusive criteria filter based on inclusive criteria validator. + * + * @param The Element type the filter can be applied to + * @param The criteria type + * @param The validator type to use */ -public class InclusiveCharacteristicsElementFilter>> { +public class InclusiveCharacteristicsElementFilter>> { private final VALIDATOR validator; @@ -19,117 +23,116 @@ public InclusiveCharacteristicsElementFilter(VALIDATOR validator) { } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByOneOf(List elements, CHARACTERISTIC... characteristicsToCheck) { + public List filterByOneOf(List elements, CRITERIA... criteriaToCheck) { - return filterByOneOf(elements,false,characteristicsToCheck); + return filterByOneOf(elements, false, criteriaToCheck); } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param invertFilter - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param invertFilter invert filter or not + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByOneOf(List elements, boolean invertFilter, CHARACTERISTIC... characteristicsToCheck) { + public List filterByOneOf(List elements, boolean invertFilter, CRITERIA... criteriaToCheck) { - return CharacteristicsElementFilterImpl.filterByOneOf((CharacteristicsMatcher) validator.getMatcher(), invertFilter, elements, characteristicsToCheck); + return CriteriaElementFilterImpl.filterByOneOf((CriteriaMatcher) validator.getMatcher(), invertFilter, elements, criteriaToCheck); } - /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByNoneOf(List elements, CHARACTERISTIC... characteristicsToCheck) { + public List filterByNoneOf(List elements, CRITERIA... criteriaToCheck) { - return filterByNoneOf(elements,false,characteristicsToCheck); + return filterByNoneOf(elements, false, criteriaToCheck); } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param invertFilter - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param invertFilter invert filter or not + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByNoneOf(List elements, boolean invertFilter, CHARACTERISTIC... characteristicsToCheck) { + public List filterByNoneOf(List elements, boolean invertFilter, CRITERIA... criteriaToCheck) { - return CharacteristicsElementFilterImpl.filterByNoneOf((CharacteristicsMatcher) validator.getMatcher(), invertFilter, elements, characteristicsToCheck); + return CriteriaElementFilterImpl.filterByNoneOf((CriteriaMatcher) validator.getMatcher(), invertFilter, elements, criteriaToCheck); } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByAtLeastOneOf(List elements, CHARACTERISTIC... characteristicsToCheck) { + public List filterByAtLeastOneOf(List elements, CRITERIA... criteriaToCheck) { - return filterByAtLeastOneOf(elements, false, characteristicsToCheck); + return filterByAtLeastOneOf(elements, false, criteriaToCheck); } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param invertFilter - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param invertFilter invert filter or not + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByAtLeastOneOf(List elements, boolean invertFilter, CHARACTERISTIC... characteristicsToCheck) { + public List filterByAtLeastOneOf(List elements, boolean invertFilter, CRITERIA... criteriaToCheck) { - return CharacteristicsElementFilterImpl.filterByAtLeastOneOf((CharacteristicsMatcher) validator.getMatcher(), invertFilter, elements, characteristicsToCheck); + return CriteriaElementFilterImpl.filterByAtLeastOneOf((CriteriaMatcher) validator.getMatcher(), invertFilter, elements, criteriaToCheck); } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByAllOf(List elements, CHARACTERISTIC... characteristicsToCheck) { + public List filterByAllOf(List elements, CRITERIA... criteriaToCheck) { - return filterByAllOf(elements, false, characteristicsToCheck); + return filterByAllOf(elements, false, criteriaToCheck); } /** - * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed characteristics. + * Filters passed element list. Checks if passed element is annotated with EXACTLY one of the passed criteria. * - * @param elements the element to check - * @param invertFilter - * @param characteristicsToCheck the annotation types to check for + * @param elements the element to check + * @param invertFilter invert filter or not + * @param criteriaToCheck the annotation types to check for * @return true if all passed annotationTypes are present */ - public List filterByAllOf(List elements, boolean invertFilter, CHARACTERISTIC... characteristicsToCheck) { + public List filterByAllOf(List elements, boolean invertFilter, CRITERIA... criteriaToCheck) { - return CharacteristicsElementFilterImpl.filterByAllOf((CharacteristicsMatcher) validator.getMatcher(), invertFilter, elements, characteristicsToCheck); + return CriteriaElementFilterImpl.filterByAllOf((CriteriaMatcher) validator.getMatcher(), invertFilter, elements, criteriaToCheck); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CharacteristicsElementFilterImpl.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CharacteristicsElementFilterImpl.java deleted file mode 100644 index 2dc5a8c1..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CharacteristicsElementFilterImpl.java +++ /dev/null @@ -1,132 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.filter.impl; - -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.impl.CharacteristicsElementValidatorImpl; - -import javax.lang.model.element.Element; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * Implementation class for characteristic filters. - */ -public class CharacteristicsElementFilterImpl { - - /** - * Validator to check if passed Element matches exactly one of the passed characteristcs. - * - * @param matcher The matcher to use - * @param invert invert filter - * @param elements The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches exactly one of the passedcharacteristics, otherwise false. - */ - private static > List filterByValidatorKind(CharacteristicsElementValidatorImpl.ValidatorKind validatorKind, MATCHER matcher, boolean invert, List elements, CHARACTERISTIC... characteristicsToCheck) { - if (elements == null || matcher == null) { - return new ArrayList(); - } - - // always return true for null valued characteristics - if (characteristicsToCheck == null || characteristicsToCheck.length == 0) { - if (!invert) { - return elements; - } else { - return new ArrayList(); - } - - } - - // always return true for empty or null valued characteristicsToCheck - Set characteristicsToCheckSet = Utilities.convertArrayToSet(characteristicsToCheck); - if (characteristicsToCheckSet.size() == 0) { - return elements; - } - - - List result = new ArrayList(); - - for (ELEMENT element : elements) { - - boolean validatorResult = CharacteristicsElementValidatorImpl.validateByValidatorKind(validatorKind, matcher, element, characteristicsToCheck); - if ((!invert && validatorResult) || (invert && !validatorResult)) { - result.add(element); - } - - - } - - return result; - } - - - /** - * Validator to check if passed Element matches exactly one of the passed characteristcs. - * - * @param matcher The matcher to use - * @param invert invert filter - * @param elements The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches exactly one of the passedcharacteristics, otherwise false. - */ - public static > List filterByOneOf(MATCHER matcher, boolean invert, List elements, CHARACTERISTIC... characteristicsToCheck) { - return filterByValidatorKind(CharacteristicsElementValidatorImpl.ValidatorKind.HAS_ONE_OF, matcher, invert, elements, characteristicsToCheck); - } - - /** - * Validator to check if passed Element matches none of the passed characteristcs. - * - * @param matcher The matcher to use - * @param invert invert filter - * @param elements The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches none of the passedcharacteristics, otherwise false. - */ - public static > List filterByNoneOf(MATCHER matcher, boolean invert, List elements, CHARACTERISTIC... characteristicsToCheck) { - return filterByValidatorKind(CharacteristicsElementValidatorImpl.ValidatorKind.HAS_NONE_OF, matcher, invert, elements, characteristicsToCheck); - } - - /** - * Validator to check if passed Element matches all of the passed characteristcs. - * - * @param matcher The matcher to use - * @param invert invert filter - * @param elements The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches all of the passedcharacteristics, otherwise false. - */ - public static > List filterByAllOf(MATCHER matcher, boolean invert, List elements, CHARACTERISTIC... characteristicsToCheck) { - return filterByValidatorKind(CharacteristicsElementValidatorImpl.ValidatorKind.HAS_ALL_OF, matcher, invert, elements, characteristicsToCheck); - } - - /** - * Validator to check if passed Element matches at least one of the passed characteristcs. - * - * @param matcher The matcher to use - * @param invert invert filter - * @param elements The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches at least one of the passedcharacteristics, otherwise false. - */ - public static > List filterByAtLeastOneOf(MATCHER matcher, boolean invert, List elements, CHARACTERISTIC... characteristicsToCheck) { - return filterByValidatorKind(CharacteristicsElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, matcher, invert, elements, characteristicsToCheck); - } - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CriteriaElementFilterImpl.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CriteriaElementFilterImpl.java new file mode 100644 index 00000000..85e1f2dc --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/impl/CriteriaElementFilterImpl.java @@ -0,0 +1,132 @@ +package io.toolisticon.annotationprocessortoolkit.tools.filter.impl; + +import io.toolisticon.annotationprocessortoolkit.tools.Utilities; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.impl.CriteriaElementValidatorImpl; + +import javax.lang.model.element.Element; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Implementation class for criteria filters. + */ +public class CriteriaElementFilterImpl { + + /** + * Validator to check if passed Element matches exactly one of the passed criteria. + * + * @param matcher The matcher to use + * @param invert invert filter + * @param elements The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches exactly one of the passed criteria, otherwise false. + */ + private static > List filterByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind validatorKind, MATCHER matcher, boolean invert, List elements, CRITERIA... criteriaToCheck) { + if (elements == null || matcher == null) { + return new ArrayList(); + } + + // always return true for null valued characteristics + if (criteriaToCheck == null || criteriaToCheck.length == 0) { + if (!invert) { + return elements; + } else { + return new ArrayList(); + } + + } + + // always return true for empty or null valued criteriaToCheck + Set criteriaToCheckSet = Utilities.convertArrayToSet(criteriaToCheck); + if (criteriaToCheckSet.size() == 0) { + return elements; + } + + + List result = new ArrayList(); + + for (ELEMENT element : elements) { + + boolean validatorResult = CriteriaElementValidatorImpl.validateByValidatorKind(validatorKind, matcher, element, criteriaToCheck); + if ((!invert && validatorResult) || (invert && !validatorResult)) { + result.add(element); + } + + + } + + return result; + } + + + /** + * Validator to check if passed Element matches exactly one of the passed criteria. + * + * @param matcher The matcher to use + * @param invert invert filter + * @param elements The element to be validated + * @param criteriaToCheck the characteristics to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches exactly one of the passed criteria, otherwise false. + */ + public static > List filterByOneOf(MATCHER matcher, boolean invert, List elements, CRITERIA... criteriaToCheck) { + return filterByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ONE_OF, matcher, invert, elements, criteriaToCheck); + } + + /** + * Validator to check if passed Element matches none of the passed criteria. + * + * @param matcher The matcher to use + * @param invert invert filter + * @param elements The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches none of the passed criteria, otherwise false. + */ + public static > List filterByNoneOf(MATCHER matcher, boolean invert, List elements, CRITERIA... criteriaToCheck) { + return filterByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_NONE_OF, matcher, invert, elements, criteriaToCheck); + } + + /** + * Validator to check if passed Element matches all of the passed criteria. + * + * @param matcher The matcher to use + * @param invert invert filter + * @param elements The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches all of the passed criteria, otherwise false. + */ + public static > List filterByAllOf(MATCHER matcher, boolean invert, List elements, CRITERIA... criteriaToCheck) { + return filterByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_ALL_OF, matcher, invert, elements, criteriaToCheck); + } + + /** + * Validator to check if passed Element matches at least one of the passed criteria. + * + * @param matcher The matcher to use + * @param invert invert filter + * @param elements The element to be validated + * @param characteristicsToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches at least one of the passed criteria, otherwise false. + */ + public static > List filterByAtLeastOneOf(MATCHER matcher, boolean invert, List elements, CRITERIA... characteristicsToCheck) { + return filterByValidatorKind(CriteriaElementValidatorImpl.ValidatorKind.HAS_AT_LEAST_ONE_OF, matcher, invert, elements, characteristicsToCheck); + } + + +} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/package-info.java new file mode 100644 index 00000000..259378f0 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/filter/package-info.java @@ -0,0 +1,4 @@ +/** + * Filter related implementation classes. + */ +package io.toolisticon.annotationprocessortoolkit.tools.filter; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/FluentElementFilter.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/FluentElementFilter.java index 864300e7..a86ec247 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/FluentElementFilter.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/FluentElementFilter.java @@ -1,16 +1,18 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentfilter; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCharacteristicCoreMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCharacteristicElementBasedCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCriteriaCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCriteriaElementBasedCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ImplicitCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ImplicitElementBasedCoreMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.InclusiveCharacteristicCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.InclusiveCharacteristicElementBasedCoreMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCharacteristicsElementFilter; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.InclusiveCriteriaCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.IsCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.IsElementBasedCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.filter.ExclusiveCriteriaElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.filter.InclusiveCharacteristicsElementFilter; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCharacteristicsElementValidator; -import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCharacteristicsElementValidator; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCriteriaElementValidator; +import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCriteriaElementValidator; import javax.lang.model.element.Element; import java.util.List; @@ -21,37 +23,59 @@ public class FluentElementFilter { + /** + * The element list to filter. + */ private List elements; + /** + * Constructor to be called from inside the static builder function. + * + * @param elements the element list to filter + */ private FluentElementFilter(List elements) { this.elements = elements; } /** - * Validator step for exlusive characteristics validators. + * Validator step for exclusive criteria validators. * - * @param - * @param + * @param the filters element type + * @param the criteria type */ - public class ExclusiveCharacteristicFluentFilter { + public class ExclusiveCharacteristicFluentFilter { private final boolean inverted; - private final ExclusiveCharacteristicsElementFilter>> filter; + private final ExclusiveCriteriaElementFilter>> filter; - private ExclusiveCharacteristicFluentFilter(ExclusiveCharacteristicsElementFilter>> filter, boolean inverted) { + private ExclusiveCharacteristicFluentFilter(ExclusiveCriteriaElementFilter>> filter, boolean inverted) { this.filter = filter; this.inverted = inverted; } - public FluentElementFilter filterByOneOf(CHARACTERISTIC... params) { - elements = (List) filter.filterByOneOf((List) elements, inverted, params); + /** + * Filters by one of the passed criteria. + * elements won't be discarded if element matches exactly one of the passed criteria. + * + * @param criteria the criteria to be used for filtering + * @return the FluentElementFilter instance + */ + public FluentElementFilter filterByOneOf(CRITERIA... criteria) { + elements = (List) filter.filterByOneOf((List) elements, inverted, criteria); return FluentElementFilter.this; } - public FluentElementFilter filterByNoneOf(CHARACTERISTIC... params) { - elements = (List) filter.filterByNoneOf((List) elements, inverted, params); + /** + * Filters by none of the passed criteria. + * elements won't be discarded if element matches none of the passed criteria. + * + * @param criteria the criteria to be used for filtering + * @return the FluentElementFilter instance + */ + public FluentElementFilter filterByNoneOf(CRITERIA... criteria) { + elements = (List) filter.filterByNoneOf((List) elements, inverted, criteria); return FluentElementFilter.this; } @@ -64,33 +88,61 @@ public FluentElementFilter filterByNoneOf(CHARACTERISTIC... params) { * @param * @param */ - public class InclusiveCharacteristicFluentFilter { + public class InclusiveCriteriaFluentFilter { private final boolean inverted; - private final InclusiveCharacteristicsElementFilter>> filter; + private final InclusiveCharacteristicsElementFilter>> filter; - private InclusiveCharacteristicFluentFilter(InclusiveCharacteristicsElementFilter>> filter, boolean inverted) { + private InclusiveCriteriaFluentFilter(InclusiveCharacteristicsElementFilter>> filter, boolean inverted) { this.filter = filter; this.inverted = inverted; } - public FluentElementFilter filterByOneOf(CHARACTERISTIC... params) { - elements = (List) filter.filterByOneOf((List) elements, inverted, params); + /** + * Filters by one of the passed criteria. + * elements won't be discarded if element matches exactly one of the passed criteria. + * + * @param criteria the criteria to be used for filtering + * @return the FluentElementFilter instance + */ + public FluentElementFilter filterByOneOf(CHARACTERISTIC... criteria) { + elements = (List) filter.filterByOneOf((List) elements, inverted, criteria); return FluentElementFilter.this; } - public FluentElementFilter filterByNoneOf(CHARACTERISTIC... params) { - elements = (List) filter.filterByNoneOf((List) elements, inverted, params); + /** + * Filters by none of the passed criteria. + * elements won't be discarded if element matches none of the passed criteria. + * + * @param criteria the criteria to be used for filtering + * @return the FluentElementFilter instance + */ + public FluentElementFilter filterByNoneOf(CHARACTERISTIC... criteria) { + elements = (List) filter.filterByNoneOf((List) elements, inverted, criteria); return FluentElementFilter.this; } - public FluentElementFilter filterByAtLeastOneOf(CHARACTERISTIC... params) { - elements = (List) filter.filterByAtLeastOneOf((List) elements, inverted, params); + /** + * Filters by at least one of the passed criteria. + * elements won't be discarded if element matches at least one of the passed criteria. + * + * @param criteria the criteria to be used for filtering + * @return the FluentElementFilter instance + */ + public FluentElementFilter filterByAtLeastOneOf(CHARACTERISTIC... criteria) { + elements = (List) filter.filterByAtLeastOneOf((List) elements, inverted, criteria); return FluentElementFilter.this; } - public FluentElementFilter filterByAllOf(CHARACTERISTIC... params) { - elements = (List) filter.filterByAllOf((List) elements, inverted, params); + /** + * Filters by all of the passed criteria. + * elements won't be discarded if element matches all of the passed criteria. + * + * @param criteria the criteria to be used for filtering + * @return the FluentElementFilter instance + */ + public FluentElementFilter filterByAllOf(CHARACTERISTIC... criteria) { + elements = (List) filter.filterByAllOf((List) elements, inverted, criteria); return FluentElementFilter.this; } @@ -98,18 +150,86 @@ public FluentElementFilter filterByAllOf(CHARACTERISTIC... params) { } // ----------------------------------------------- - // -- IMPLICIT FILTERS + // -- IS FILTERS // ----------------------------------------------- - // apply implicit filter - public FluentElementFilter applyFilter(ImplicitCoreMatcher coreMatcher) { + /** + * Applies is filter. + * Changes generic type of fluent filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public FluentElementFilter applyFilter(IsCoreMatcher coreMatcher) { + + elements = coreMatcher.getFilter().filter(elements); + return new FluentElementFilter((List) elements); + + } + + /** + * Applies inverted is filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public FluentElementFilter applyInvertedFilter(IsCoreMatcher coreMatcher) { + + elements = coreMatcher.getFilter().filter(elements, true); + return FluentElementFilter.this; + + } + + /** + * Applies is element based filter. + * Changes generic type of fluent filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public FluentElementFilter applyFilter(IsElementBasedCoreMatcher coreMatcher) { elements = (List) coreMatcher.getFilter().filter((List) elements); + return new FluentElementFilter((List) elements); + + } + + /** + * Applies inverted implicit element based filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public FluentElementFilter applyInvertedFilter(IsElementBasedCoreMatcher coreMatcher) { + + elements = (List) coreMatcher.getFilter().filter((List) elements, true); return FluentElementFilter.this; } - // apply inverted implicit filter + // ----------------------------------------------- + // -- IMPLICIT FILTERS + // ----------------------------------------------- + + /** + * Applies implicit filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public FluentElementFilter applyFilter(ImplicitCoreMatcher coreMatcher) { + + elements = coreMatcher.getFilter().filter(elements); + return FluentElementFilter.this; + + } + + /** + * Applies inverted implicit filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ public FluentElementFilter applyInvertedFilter(ImplicitCoreMatcher coreMatcher) { elements = coreMatcher.getFilter().filter(elements, true); @@ -117,7 +237,12 @@ public FluentElementFilter applyInvertedFilter(ImplicitCoreMatcher applyFilter(ImplicitElementBasedCoreMatcher coreMatcher) { elements = (List) coreMatcher.getFilter().filter((List) elements); @@ -125,7 +250,12 @@ public FluentElementFilter applyFilter(ImplicitElementBasedCoreMatcher } - // apply implicit element based filter + /** + * Applies inverted implicit element based filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ public FluentElementFilter applyInvertedFilter(ImplicitElementBasedCoreMatcher coreMatcher) { elements = (List) coreMatcher.getFilter().filter((List) elements, true); @@ -134,35 +264,55 @@ public FluentElementFilter applyInvertedFilter(ImplicitElementBasedCore } // ----------------------------------------------- - // -- INCLUSIVE CHARACTERISTIC FILTERS + // -- INCLUSIVE CRITERIA FILTERS // ----------------------------------------------- - // apply implicit filter - public InclusiveCharacteristicFluentFilter applyFilter(InclusiveCharacteristicCoreMatcher coreMatcher) { + /** + * Applies inclusive criteria filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public InclusiveCriteriaFluentFilter applyFilter(InclusiveCriteriaCoreMatcher coreMatcher) { - return new InclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), false); + return new InclusiveCriteriaFluentFilter(coreMatcher.getFilter(), false); } - // apply inverted implicit filter - public InclusiveCharacteristicFluentFilter applyInvertedFilter(InclusiveCharacteristicCoreMatcher coreMatcher) { + /** + * Applies inverted inclusive criteria filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public InclusiveCriteriaFluentFilter applyInvertedFilter(InclusiveCriteriaCoreMatcher coreMatcher) { - return new InclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), true); + return new InclusiveCriteriaFluentFilter(coreMatcher.getFilter(), true); } - // apply implicit element based filter - public InclusiveCharacteristicFluentFilter applyFilter(InclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { + /** + * Applies inclusive criteria element based filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public InclusiveCriteriaFluentFilter applyFilter(InclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { - return new InclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), false); + return new InclusiveCriteriaFluentFilter(coreMatcher.getFilter(), false); } - // apply implicit element based filter - public InclusiveCharacteristicFluentFilter applyInvertedFilter(InclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { + /** + * Applies inverted inclusive element based criteria filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public InclusiveCriteriaFluentFilter applyInvertedFilter(InclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { - return new InclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), true); + return new InclusiveCriteriaFluentFilter(coreMatcher.getFilter(), true); } @@ -170,35 +320,63 @@ public InclusiveCharacteristicFluentFilter ExclusiveCharacteristicFluentFilter applyFilter(ExclusiveCharacteristicCoreMatcher coreMatcher) { + /** + * Applies exclusive criteria filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public ExclusiveCharacteristicFluentFilter applyFilter(ExclusiveCriteriaCoreMatcher coreMatcher) { return new ExclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), false); } - // apply inverted implicit filter - public ExclusiveCharacteristicFluentFilter applyInvertedFilter(ExclusiveCharacteristicCoreMatcher coreMatcher) { + /** + * Applies inverted exclusive criteria filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public ExclusiveCharacteristicFluentFilter applyInvertedFilter(ExclusiveCriteriaCoreMatcher coreMatcher) { return new ExclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), true); } - // apply implicit element based filter - public ExclusiveCharacteristicFluentFilter applyFilter(ExclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { + /** + * Applies exclusive criteria element based filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public ExclusiveCharacteristicFluentFilter applyFilter(ExclusiveCriteriaElementBasedCoreMatcher coreMatcher) { return new ExclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), false); } - // apply implicit element based filter - public ExclusiveCharacteristicFluentFilter applyInvertedFilter(ExclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { + /** + * Applies inverted exclusive element based criteria filter. + * + * @param coreMatcher the implicit core matcher to use + * @return the FluentElementFilter instance + */ + public ExclusiveCharacteristicFluentFilter applyInvertedFilter(ExclusiveCriteriaElementBasedCoreMatcher coreMatcher) { return new ExclusiveCharacteristicFluentFilter(coreMatcher.getFilter(), true); } + // ------------------------------------------------------------- + // ------------------------------------------------------------- + + /** + * Gets the filter result. + * + * @return the filtered List + */ public List getResult() { return elements; @@ -252,6 +430,13 @@ public int getResultSize() { } + /** + * Factory method to create FluentElementFilter instance. + * + * @param elements the element list to filter + * @param The element type + * @return the FluentElementFilter instance + */ public static FluentElementFilter createFluentElementFilter(List elements) { return new FluentElementFilter(elements); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/package-info.java new file mode 100644 index 00000000..a3b73345 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentfilter/package-info.java @@ -0,0 +1,4 @@ +/** + * Package for fluent element filter. + */ +package io.toolisticon.annotationprocessortoolkit.tools.fluentfilter; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidator.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidator.java index d71eb328..e67affe0 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidator.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/FluentElementValidator.java @@ -1,20 +1,20 @@ package io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator; import io.toolisticon.annotationprocessortoolkit.tools.MessagerUtils; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCharacteristicCoreMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCharacteristicElementBasedCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCriteriaCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ExclusiveCriteriaElementBasedCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ImplicitCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.ImplicitElementBasedCoreMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.InclusiveCharacteristicCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.InclusiveCharacteristicElementBasedCoreMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.InclusiveCriteriaCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.IsCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.corematcher.IsElementBasedCoreMatcher; import io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator.impl.FluentValidatorState; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.ImplicitMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCharacteristicsElementValidator; +import io.toolisticon.annotationprocessortoolkit.tools.validator.ExclusiveCriteriaElementValidator; import io.toolisticon.annotationprocessortoolkit.tools.validator.ImplicitValidator; -import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCharacteristicsElementValidator; +import io.toolisticon.annotationprocessortoolkit.tools.validator.InclusiveCriteriaElementValidator; import javax.lang.model.element.Element; import javax.tools.Diagnostic; @@ -25,8 +25,15 @@ public class FluentElementValidator { + /** + * The element under validation. + */ private ELEMENT element; + /** + * The validations state. + * Maybe passed over to other FluentElementValidator instance. + */ private final FluentValidatorState fluentValidatorState; /** @@ -171,9 +178,9 @@ protected IsFluentValidator self() { */ public class ExclusiveCharacteristicFluentValidator extends AbstractFluentValidatorBase> { - private final ExclusiveCharacteristicsElementValidator> validator; + private final ExclusiveCriteriaElementValidator> validator; - private ExclusiveCharacteristicFluentValidator(ExclusiveCharacteristicsElementValidator> validator) { + private ExclusiveCharacteristicFluentValidator(ExclusiveCriteriaElementValidator> validator) { this.validator = validator; } @@ -207,9 +214,9 @@ protected ExclusiveCharacteristicFluentValidator extends AbstractFluentValidatorBase> { - private final InclusiveCharacteristicsElementValidator> validator; + private final InclusiveCriteriaElementValidator> validator; - private InclusiveCharacteristicFluentValidator(InclusiveCharacteristicsElementValidator> validator) { + private InclusiveCharacteristicFluentValidator(InclusiveCriteriaElementValidator> validator) { this.validator = validator; } @@ -273,7 +280,7 @@ public ImplicitFluentValidator applyValidator(ImplicitElementBasedCoreM } // apply inclusive characteristics validators - public InclusiveCharacteristicFluentValidator applyValidator(InclusiveCharacteristicCoreMatcher coreMatcher) { + public InclusiveCharacteristicFluentValidator applyValidator(InclusiveCriteriaCoreMatcher coreMatcher) { return new InclusiveCharacteristicFluentValidator(coreMatcher.getValidator()); } @@ -282,20 +289,20 @@ public InclusiveCharacteristicFluentValidator ExclusiveCharacteristicFluentValidator applyValidator(ExclusiveCharacteristicCoreMatcher coreMatcher) { + public ExclusiveCharacteristicFluentValidator applyValidator(ExclusiveCriteriaCoreMatcher coreMatcher) { return new ExclusiveCharacteristicFluentValidator(coreMatcher.getValidator()); } - public ExclusiveCharacteristicFluentValidator applyValidator(ExclusiveCharacteristicElementBasedCoreMatcher coreMatcher) { + public ExclusiveCharacteristicFluentValidator applyValidator(ExclusiveCriteriaElementBasedCoreMatcher coreMatcher) { return new ExclusiveCharacteristicFluentValidator(coreMatcher.getValidator()); } // apply is validators - public FluentElementValidator is(IsCoreMatcher coreMatcher) { + public FluentElementValidator is(IsCoreMatcher coreMatcher) { return new IsFluentValidator(coreMatcher.getValidator()).apply(); } - public FluentElementValidator is(IsElementBasedCoreMatcher< TARGET_ELEMENT> coreMatcher) { + public FluentElementValidator is(IsElementBasedCoreMatcher coreMatcher) { return new IsFluentValidator(coreMatcher.getValidator()).apply(); } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessage.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessage.java index 75266325..b1aaf4f3 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessage.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/FluentValidatorMessage.java @@ -39,14 +39,17 @@ public FluentValidatorMessage(final Element element, final AnnotationMirror anno } + /** + * Issues stored compiler message. + */ public void issueMessage() { if (annotationMirror != null && annotationValue != null) { - MessagerUtils.getMessagerUtils().printMessage(element,annotationMirror,annotationValue,kind,message,args); + MessagerUtils.getMessagerUtils().printMessage(element, annotationMirror, annotationValue, kind, message, args); } else if (annotationMirror != null) { - MessagerUtils.getMessagerUtils().printMessage(element,annotationMirror,kind,message,args); + MessagerUtils.getMessagerUtils().printMessage(element, annotationMirror, kind, message, args); } else { - MessagerUtils.getMessagerUtils().printMessage(element,kind,message,args); + MessagerUtils.getMessagerUtils().printMessage(element, kind, message, args); } } diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/package-info.java new file mode 100644 index 00000000..d8724c56 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/impl/package-info.java @@ -0,0 +1,4 @@ +/** + * Internal implementation classes for fluent validator. + */ +package io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator.impl; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/package-info.java new file mode 100644 index 00000000..2af5da54 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/fluentvalidator/package-info.java @@ -0,0 +1,4 @@ +/** + * Package for fluent element validator. + */ +package io.toolisticon.annotationprocessortoolkit.tools.fluentvalidator; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/generics/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/generics/package-info.java new file mode 100644 index 00000000..c32b5c93 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/generics/package-info.java @@ -0,0 +1,4 @@ +/** + * This package contains classes to support generic type checks. + */ +package io.toolisticon.annotationprocessortoolkit.tools.generics; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CharacteristicsMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CharacteristicsMatcher.java deleted file mode 100644 index fcf574f2..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CharacteristicsMatcher.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.matcher; - -import javax.lang.model.element.Element; - -/** - * Matcher that checks if passed characteristic is fulfilled - */ -public interface CharacteristicsMatcher extends BaseMatcher{ - - /** - * Applies matcher to element to determine if element matches a characteristic or not. - * - * @param element the element to check - * @param toCheckFor the characteristic to check for - * @return true if the element matches the passed characteristic, otherwise false - */ - boolean checkForMatchingCharacteristic(E element, T toCheckFor); - - /** - * Creates a string representation for the passed characteristic. - * - * @param toGetStringRepresentationFor the characteristic to get a string representation for. - * @return the string representation - */ - String getStringRepresentationOfPassedCharacteristic(T toGetStringRepresentationFor); - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CriteriaMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CriteriaMatcher.java new file mode 100644 index 00000000..48f6ef1c --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/CriteriaMatcher.java @@ -0,0 +1,27 @@ +package io.toolisticon.annotationprocessortoolkit.tools.matcher; + +import javax.lang.model.element.Element; + +/** + * Matcher that checks if passed criteria is fulfilled + */ +public interface CriteriaMatcher extends BaseMatcher{ + + /** + * Applies matcher to element to determine if element matches a criteria or not. + * + * @param element the element to check + * @param toCheckFor the criteria to check for + * @return true if the element matches the passed criteria, otherwise false + */ + boolean checkForMatchingCharacteristic(E element, T toCheckFor); + + /** + * Creates a string representation for the passed criteria. + * + * @param toGetStringRepresentationFor the criteria to get a string representation for. + * @return the string representation + */ + String getStringRepresentationOfPassedCharacteristic(T toGetStringRepresentationFor); + +} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matchers.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matchers.java deleted file mode 100644 index dee71997..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/Matchers.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.matcher; - -import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericType; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByAnnotationMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByElementKindMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByGenericTypeMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByParameterTypeFqnMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.IsExecutableElementMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByModifierMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByNameMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByParameterTypeMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByRawTypeMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByNameRegexMatcher; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import java.lang.annotation.Annotation; - -/** - * Core matchers provided by the toolkit. - */ -public final class Matchers { - - private Matchers() { - - } - - /** - * Matcher to check if an Element has a specific name. - */ - public final static CharacteristicsMatcher NAME_MATCHER = new ByNameMatcher(); - - /** - * Matcher to check if an Element name matches a specific regular expression. - */ - public final static CharacteristicsMatcher REGEX_NAME_MATCHER = new ByNameRegexMatcher(); - - - /** - * Matcher to check if an Element is annotated with a specific annotation. - */ - public final static CharacteristicsMatcher> ANNOTATION_MATCHER = new ByAnnotationMatcher(); - - /** - * Matcher to check if an Element is of a specific ElementKind. - */ - public final static CharacteristicsMatcher ELEMENT_KIND_MATCHER = new ByElementKindMatcher(); - - /** - * Matcher to check if an Element has a specific Modifier. - */ - public final static CharacteristicsMatcher MODIFIER_MATCHER = new ByModifierMatcher(); - - - /** - * Matcher to check if an TypeElement matches a specific generic type. - */ - public final static CharacteristicsMatcher GENERIC_TYPE_MATCHER = new ByGenericTypeMatcher(); - - /** - * Matcher to check if an TypeElement matches a specific generic type. - */ - public final static CharacteristicsMatcher RAW_TYPE_MATCHER = new ByRawTypeMatcher(); - - - /** - * Matcher to check if an ExecutableElement has specific parameter types. - */ - public final static CharacteristicsMatcher PARAMETER_TYPE_FQN_MATCHER = new ByParameterTypeFqnMatcher(); - - /** - * Matcher to check if an ExecutableElement has specific parameter types. - */ - public final static CharacteristicsMatcher PARAMETER_TYPE_MATCHER = new ByParameterTypeMatcher(); - - - // --------------------------------------------------------------------------------- - // -- IS MATCHER - // --------------------------------------------------------------------------------- - - - /** - * Matcher to check if passed Element is an ExecutableElement. - */ - public final static ImplicitMatcher IS_EXECUTABLE_ELEMENT = new IsExecutableElementMatcher(); - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByAnnotationMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByAnnotationMatcher.java index bb07fd03..ef91c2be 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByAnnotationMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByAnnotationMatcher.java @@ -1,6 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; import java.lang.annotation.Annotation; @@ -8,7 +8,7 @@ /** * Class for checking existence of one annotation on an element. */ -public class ByAnnotationMatcher implements CharacteristicsMatcher> { +public class ByAnnotationMatcher implements CriteriaMatcher> { /** * {@inheritDoc} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByElementKindMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByElementKindMatcher.java index ad74317b..8b863e69 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByElementKindMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByElementKindMatcher.java @@ -1,6 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -8,7 +8,7 @@ /** * Class for matching {@link javax.lang.model.element.ElementKind}. */ -public class ByElementKindMatcher implements CharacteristicsMatcher { +public class ByElementKindMatcher implements CriteriaMatcher { /** * {@inheritDoc} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcher.java index 11968c7a..007fd633 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcher.java @@ -4,14 +4,14 @@ import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericType; import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericTypeParameter; import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericTypeWildcard; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; /** * A matcher for generic types. */ -public class ByGenericTypeMatcher implements CharacteristicsMatcher { +public class ByGenericTypeMatcher implements CriteriaMatcher { public ByGenericTypeMatcher() { super(); diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByModifierMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByModifierMatcher.java index 2cc31691..ef4087b1 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByModifierMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByModifierMatcher.java @@ -1,6 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; import javax.lang.model.element.Modifier; @@ -8,7 +8,7 @@ /** * Class for matching {@link Modifier}. */ -public class ByModifierMatcher implements CharacteristicsMatcher { +public class ByModifierMatcher implements CriteriaMatcher { /** * {@inheritDoc} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameMatcher.java index 76c0fdfe..35840fdc 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameMatcher.java @@ -1,13 +1,13 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; /** * Class for checking for find matching elements by name. */ -public class ByNameMatcher implements CharacteristicsMatcher { +public class ByNameMatcher implements CriteriaMatcher { /** * {@inheritDoc} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameRegexMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameRegexMatcher.java index d2d84109..ce312ec6 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameRegexMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByNameRegexMatcher.java @@ -1,6 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; import java.util.regex.Pattern; @@ -8,7 +8,7 @@ /** * Class for checking for find matching elements by name and regular expressions. */ -public class ByNameRegexMatcher implements CharacteristicsMatcher { +public class ByNameRegexMatcher implements CriteriaMatcher { /** * {@inheritDoc} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeFqnMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeFqnMatcher.java index c60dfd5a..9ff663d6 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeFqnMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeFqnMatcher.java @@ -2,7 +2,7 @@ import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeMirror; @@ -11,7 +11,7 @@ /** * Matcher to check Parameters of ExecutableElement. */ -public class ByParameterTypeFqnMatcher implements CharacteristicsMatcher { +public class ByParameterTypeFqnMatcher implements CriteriaMatcher { public ByParameterTypeFqnMatcher() { super(); diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcher.java index 8d442b55..e34306fc 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcher.java @@ -2,14 +2,14 @@ import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.ExecutableElement; /** * Matcher to check Parameters of ExecutableElement. */ -public class ByParameterTypeMatcher implements CharacteristicsMatcher { +public class ByParameterTypeMatcher implements CriteriaMatcher { public ByParameterTypeMatcher() { super(); diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByRawTypeMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByRawTypeMatcher.java index 81439272..2ac98858 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByRawTypeMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByRawTypeMatcher.java @@ -1,14 +1,14 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.TypeElement; /** * Matcher for raw types. */ -public class ByRawTypeMatcher implements CharacteristicsMatcher { +public class ByRawTypeMatcher implements CriteriaMatcher { public ByRawTypeMatcher() { super(); diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAssignableToMatcher.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAssignableToMatcher.java index a3f2e1e1..7ff0fa2e 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAssignableToMatcher.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/IsAssignableToMatcher.java @@ -1,14 +1,14 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import javax.lang.model.element.Element; /** * Matcher to check if Type Element is assignable to passed class. */ -public class IsAssignableToMatcher implements CharacteristicsMatcher { +public class IsAssignableToMatcher implements CriteriaMatcher { /** * {@inheritDoc} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/package-info.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/package-info.java new file mode 100644 index 00000000..538da095 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/package-info.java @@ -0,0 +1,4 @@ +/** + * Implementations for all supported CoreMatchers. + */ +package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; \ No newline at end of file diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCharacteristicsElementValidator.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCharacteristicsElementValidator.java deleted file mode 100644 index e271884b..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCharacteristicsElementValidator.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.validator; - -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.impl.CharacteristicsElementValidatorImpl; - -import javax.lang.model.element.Element; - -/** - * Validators for characteristics that exclude each other. - */ -public class ExclusiveCharacteristicsElementValidator> extends AbstractBaseValidator { - - private final MATCHER matcher; - - - public ExclusiveCharacteristicsElementValidator(MATCHER matcher, String message) { - super(message); - this.matcher = matcher; - } - - - /** - * Checks if passed element is annotated with EXACTLY one of the passed characteristics. - * - * @param element the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public boolean hasOneOf(ELEMENT element, CHARACTERISTIC... characteristicsToCheck){ - - return CharacteristicsElementValidatorImpl.hasOneOf(matcher,element,characteristicsToCheck); - - } - - /** - * Checks if passed element is annotated with NONE of the passed characteristics. - * - * @param element the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public boolean hasNoneOf(ELEMENT element, CHARACTERISTIC... characteristicsToCheck){ - - return CharacteristicsElementValidatorImpl.hasNoneOf(matcher,element,characteristicsToCheck); - - } - - public MATCHER getMatcher() { - return matcher; - } - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCriteriaElementValidator.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCriteriaElementValidator.java new file mode 100644 index 00000000..e5216aa1 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ExclusiveCriteriaElementValidator.java @@ -0,0 +1,53 @@ +package io.toolisticon.annotationprocessortoolkit.tools.validator; + +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.impl.CriteriaElementValidatorImpl; + +import javax.lang.model.element.Element; + +/** + * Validators for criteria that exclude each other. + */ +public class ExclusiveCriteriaElementValidator> extends AbstractBaseValidator { + + private final MATCHER matcher; + + + public ExclusiveCriteriaElementValidator(MATCHER matcher, String message) { + super(message); + this.matcher = matcher; + } + + + /** + * Checks if passed element is annotated with EXACTLY one of the passed criteria. + * + * @param element the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public boolean hasOneOf(ELEMENT element, CRITERIA... criteriaToCheck) { + + return CriteriaElementValidatorImpl.hasOneOf(matcher, element, criteriaToCheck); + + } + + /** + * Checks if passed element is annotated with NONE of the passed criteria. + * + * @param element the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public boolean hasNoneOf(ELEMENT element, CRITERIA... criteriaToCheck) { + + return CriteriaElementValidatorImpl.hasNoneOf(matcher, element, criteriaToCheck); + + } + + public MATCHER getMatcher() { + return matcher; + } + + +} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ImplicitValidator.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ImplicitValidator.java index 47e7668a..5eca0db9 100644 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ImplicitValidator.java +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ImplicitValidator.java @@ -5,7 +5,7 @@ import javax.lang.model.element.Element; /** - * Validator to check implicit characteristics. + * Validator to check implicit criteria. */ public class ImplicitValidator> extends AbstractBaseValidator { diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCharacteristicsElementValidator.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCharacteristicsElementValidator.java deleted file mode 100644 index a7ef46a3..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCharacteristicsElementValidator.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.validator; - -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; -import io.toolisticon.annotationprocessortoolkit.tools.validator.impl.CharacteristicsElementValidatorImpl; - -import javax.lang.model.element.Element; - -/** - * Interface for validators for characteristics that don't exclude each other. - */ -public class InclusiveCharacteristicsElementValidator> extends AbstractBaseValidator { - - private final MATCHER matcher; - - public InclusiveCharacteristicsElementValidator(MATCHER matcher, String message) { - super(message); - this.matcher = matcher; - } - - /** - * Checks if passed element is annotated with EXACTLY one of the passed characteristics. - * - * @param element the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public boolean hasOneOf(ELEMENT element, CHARACTERISTIC... characteristicsToCheck){ - - return CharacteristicsElementValidatorImpl.hasOneOf(matcher,element,characteristicsToCheck); - - } - - /** - * Checks if passed element is annotated with NONE of the passed characteristics. - * - * @param element the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if all passed annotationTypes are present - */ - public boolean hasNoneOf(ELEMENT element, CHARACTERISTIC... characteristicsToCheck){ - - return CharacteristicsElementValidatorImpl.hasNoneOf(matcher,element,characteristicsToCheck); - - } - - /** - * Checks if passed elements has all of the passed characteristics. - * - * @param element the element to check the characteristic for - * @param characteristicsToCheck the characteristics to check - * @return true if all passed characteristics are present, otherwise false - */ - public boolean hasAllOf(ELEMENT element, CHARACTERISTIC... characteristicsToCheck){ - - return CharacteristicsElementValidatorImpl.hasAllOf(matcher,element,characteristicsToCheck); - - } - - /** - * Checks if passed element is annotated with at least one of the passed characteristics. - * - * @param element the element to check - * @param characteristicsToCheck the annotation types to check for - * @return true if at least one of the characteristics are present - */ - public boolean hasAtLeastOneOf(ELEMENT element, CHARACTERISTIC... characteristicsToCheck){ - - return CharacteristicsElementValidatorImpl.hasAtLeastOneOf(matcher,element,characteristicsToCheck); - - } - - public MATCHER getMatcher() { - return matcher; - } - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCriteriaElementValidator.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCriteriaElementValidator.java new file mode 100644 index 00000000..bbe29d7c --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/InclusiveCriteriaElementValidator.java @@ -0,0 +1,77 @@ +package io.toolisticon.annotationprocessortoolkit.tools.validator; + +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.validator.impl.CriteriaElementValidatorImpl; + +import javax.lang.model.element.Element; + +/** + * Interface for validators for criteria that don't exclude each other. + */ +public class InclusiveCriteriaElementValidator> extends AbstractBaseValidator { + + private final MATCHER matcher; + + public InclusiveCriteriaElementValidator(MATCHER matcher, String message) { + super(message); + this.matcher = matcher; + } + + /** + * Checks if passed element is annotated with EXACTLY one of the passed criteria. + * + * @param element the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public boolean hasOneOf(ELEMENT element, CRITERIA... criteriaToCheck) { + + return CriteriaElementValidatorImpl.hasOneOf(matcher, element, criteriaToCheck); + + } + + /** + * Checks if passed element is annotated with NONE of the passed criteria. + * + * @param element the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if all passed annotationTypes are present + */ + public boolean hasNoneOf(ELEMENT element, CRITERIA... criteriaToCheck) { + + return CriteriaElementValidatorImpl.hasNoneOf(matcher, element, criteriaToCheck); + + } + + /** + * Checks if passed elements has all of the passed criteria. + * + * @param element the element to check the criteria for + * @param criteriaToCheck the criteria to check + * @return true if all passed criteria are present, otherwise false + */ + public boolean hasAllOf(ELEMENT element, CRITERIA... criteriaToCheck) { + + return CriteriaElementValidatorImpl.hasAllOf(matcher, element, criteriaToCheck); + + } + + /** + * Checks if passed element is annotated with at least one of the passed criteria. + * + * @param element the element to check + * @param criteriaToCheck the annotation types to check for + * @return true if at least one of the criteria are present + */ + public boolean hasAtLeastOneOf(ELEMENT element, CRITERIA... criteriaToCheck) { + + return CriteriaElementValidatorImpl.hasAtLeastOneOf(matcher, element, criteriaToCheck); + + } + + public MATCHER getMatcher() { + return matcher; + } + + +} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/Validators.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/Validators.java deleted file mode 100644 index 345681af..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/Validators.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.validator; - - -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; -import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericType; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; - -import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import java.lang.annotation.Annotation; - -/** - * Core Validators. - * Convenience class that internally uses the {@link CoreMatchers} class to get the validators. - * This might be a good candidate for code generation. - */ -public final class Validators { - - /** - * Hidden constructor. - */ - private Validators() { - - } - - /** - * Validator to check if . - */ - //public final static ImplicitValidator> VALID_JAVA_PROPERTY_VALIDATOR = CoreMatchers.VALID_JAVA_PROPERTY.new ImplicitValidator>(Matchers.VALID_JAVA_PROPERTY_MATCHER); - - /** - * Validator to check if an Element matches one or none of the specific names. - */ - public final static ExclusiveCharacteristicsElementValidator> NAME_VALIDATOR = CoreMatchers.BY_NAME.getValidator(); - - /** - * Validator to check if an Element name matches regular expressions. - */ - public final static InclusiveCharacteristicsElementValidator> REGEX_NAME_VALIDATOR = CoreMatchers.BY_REGEX_NAME.getValidator(); - - /** - * Validator to check if an Element has annotations. - */ - public final static InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> ANNOTATION_VALIDATOR = CoreMatchers.BY_ANNOTATION.getValidator(); - - - /** - * Validator to check if an Element has annotations. - */ - public final static ExclusiveCharacteristicsElementValidator> ELEMENT_KIND_VALIDATOR = CoreMatchers.BY_ELEMENT_KIND.getValidator(); - - /** - * Validator to check if an Element has Modifiers. - */ - public final static InclusiveCharacteristicsElementValidator> MODIFIER_VALIDATOR = CoreMatchers.BY_MODIFIER.getValidator(); - - - /** - * Validator to check if a TypeElement has a generic type. - */ - public final static ExclusiveCharacteristicsElementValidator> GENERIC_TYPE_VALIDATOR = CoreMatchers.BY_GENERIC_TYPE.getValidator(); - - /** - * Validator to check if a TypeElement has a generic type. - */ - public final static ExclusiveCharacteristicsElementValidator> RAW_TYPE_VALIDATOR = CoreMatchers.BY_RAW_TYPE.getValidator(); - - - /** - * Validator to check if an ExecutableElement has specific parameter types - */ - public final static ExclusiveCharacteristicsElementValidator> PARAMETER_TYPE_FQN_VALIDATOR = CoreMatchers.BY_PARAMETER_TYPE_FQN.getValidator(); - - /** - * Validator to check if an ExecutableElement has specific parameter types - */ - public final static ExclusiveCharacteristicsElementValidator> PARAMETER_TYPE_VALIDATOR = CoreMatchers.BY_PARAMETER_TYPE.getValidator(); - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CharacteristicsElementValidatorImpl.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CharacteristicsElementValidatorImpl.java deleted file mode 100644 index 11b9cb4e..00000000 --- a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CharacteristicsElementValidatorImpl.java +++ /dev/null @@ -1,219 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.validator.impl; - -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; - -import javax.lang.model.element.Element; -import java.util.Set; - -/** - * Implementation class for characteristic validators. - */ -public class CharacteristicsElementValidatorImpl { - - public enum ValidatorKind { - HAS_ONE_OF, - HAS_NONE_OF, - HAS_AT_LEAST_ONE_OF, - HAS_ALL_OF; - } - - /** - * Function to programatically call the different validator kinds. - * - * @param validatorKind The validator kind to use - * @param matcher The matcher to use - * @param element The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches the passed characteristics related to the passed validator kind, otherwise false. - */ - public static > boolean validateByValidatorKind(ValidatorKind validatorKind, MATCHER matcher, ELEMENT element, CHARACTERISTIC... characteristicsToCheck) { - - if (validatorKind == null) { - return false; - } - - switch (validatorKind) { - case HAS_ONE_OF: - return hasOneOf(matcher, element, characteristicsToCheck); - case HAS_NONE_OF: - return hasNoneOf(matcher, element, characteristicsToCheck); - case HAS_AT_LEAST_ONE_OF: - return hasAtLeastOneOf(matcher, element, characteristicsToCheck); - case HAS_ALL_OF: - return hasAllOf(matcher, element, characteristicsToCheck); - } - - return false; - - } - - - /** - * Validator to check if passed Element matches exactly one of the passed characteristcs. - * - * @param matcher The matcher to use - * @param element The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches exactly one of the passedcharacteristics, otherwise false. - */ - public static > boolean hasOneOf(MATCHER matcher, ELEMENT element, CHARACTERISTIC... characteristicsToCheck) { - if (element == null || matcher == null) { - return false; - } - - // always return true for null valued characteristics - if (characteristicsToCheck == null) { - return true; - } - - // always return true for empty or null valued characteristicsToCheck - Set characteristicsToCheckSet = Utilities.convertArrayToSet(characteristicsToCheck); - if (characteristicsToCheckSet.size() == 0) { - return true; - } - - - int count = 0; - // convert array to set to filter doubled elements - for (CHARACTERISTIC characteristicToCheck : Utilities.convertArrayToSet(characteristicsToCheck)) { - - if (matcher.checkForMatchingCharacteristic(element, characteristicToCheck)) { - count++; - } - - } - - return count == 1; - } - - /** - * Validator to check if passed Element matches none of the passed characteristcs. - * - * @param matcher The matcher to use - * @param element The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches none of the passedcharacteristics, otherwise false. - */ - - public static > boolean hasNoneOf(MATCHER matcher, ELEMENT element, CHARACTERISTIC... characteristicsToCheck) { - if (element == null) { - return false; - } - - // always return true for null valued characteristics - if (characteristicsToCheck == null) { - return true; - } - - // always return true for empty or null valued characteristicsToCheck - Set characteristicsToCheckSet = Utilities.convertArrayToSet(characteristicsToCheck); - if (characteristicsToCheckSet.size() == 0) { - return true; - } - - // convert array to set to filter doubled elements - for (CHARACTERISTIC characteristicToCheck : Utilities.convertArrayToSet(characteristicsToCheck)) { - - if (matcher.checkForMatchingCharacteristic(element, characteristicToCheck)) { - return false; - } - - } - - return true; - } - - /** - * Validator to check if passed Element matches all of the passed characteristcs. - * - * @param matcher The matcher to use - * @param element The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches all of the passedcharacteristics, otherwise false. - */ - - public static > boolean hasAllOf(MATCHER matcher, ELEMENT element, CHARACTERISTIC... characteristicsToCheck) { - - if (element == null) { - return false; - } - - // always return true for null valued characteristics - if (characteristicsToCheck == null) { - return true; - } - - // always return true for empty or null valued characteristicsToCheck - Set characteristicsToCheckSet = Utilities.convertArrayToSet(characteristicsToCheck); - if (characteristicsToCheckSet.size() == 0) { - return true; - } - - // convert array to set to filter doubled elements - for (CHARACTERISTIC characteristicToCheck : Utilities.convertArrayToSet(characteristicsToCheck)) { - - if (!matcher.checkForMatchingCharacteristic(element, characteristicToCheck)) { - return false; - } - - } - - return true; - } - - /** - * Validator to check if passed Element matches at least one of the passed characteristcs. - * - * @param matcher The matcher to use - * @param element The element to be validated - * @param characteristicsToCheck the characteristics to check - * @param - * @param - * @param - * @return true, if passed element matches at least one of the passedcharacteristics, otherwise false. - */ - - public static > boolean hasAtLeastOneOf(MATCHER matcher, ELEMENT element, CHARACTERISTIC... characteristicsToCheck) { - if (element == null) { - return false; - } - - // always return true for null valued characteristics - if (characteristicsToCheck == null) { - return true; - } - - // always return true for empty or null valued characteristicsToCheck - Set characteristicsToCheckSet = Utilities.convertArrayToSet(characteristicsToCheck); - if (characteristicsToCheckSet.size() == 0) { - return true; - } - - - // convert array to set to filter doubled elements - for (CHARACTERISTIC characteristicToCheck : characteristicsToCheck) { - - if (matcher.checkForMatchingCharacteristic(element, characteristicToCheck)) { - return true; - } - - } - - return false; - } - - -} diff --git a/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CriteriaElementValidatorImpl.java b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CriteriaElementValidatorImpl.java new file mode 100644 index 00000000..03ecad21 --- /dev/null +++ b/annotationprocessor/src/main/java/io/toolisticon/annotationprocessortoolkit/tools/validator/impl/CriteriaElementValidatorImpl.java @@ -0,0 +1,219 @@ +package io.toolisticon.annotationprocessortoolkit.tools.validator.impl; + +import io.toolisticon.annotationprocessortoolkit.tools.Utilities; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; + +import javax.lang.model.element.Element; +import java.util.Set; + +/** + * Implementation class for characteristic validators. + */ +public class CriteriaElementValidatorImpl { + + public enum ValidatorKind { + HAS_ONE_OF, + HAS_NONE_OF, + HAS_AT_LEAST_ONE_OF, + HAS_ALL_OF; + } + + /** + * Function to programatically call the different validator kinds. + * + * @param validatorKind The validator kind to use + * @param matcher The matcher to use + * @param element The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches the passed criteria related to the passed validator kind, otherwise false. + */ + public static > boolean validateByValidatorKind(ValidatorKind validatorKind, MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { + + if (validatorKind == null) { + return false; + } + + switch (validatorKind) { + case HAS_ONE_OF: + return hasOneOf(matcher, element, criteriaToCheck); + case HAS_NONE_OF: + return hasNoneOf(matcher, element, criteriaToCheck); + case HAS_AT_LEAST_ONE_OF: + return hasAtLeastOneOf(matcher, element, criteriaToCheck); + case HAS_ALL_OF: + return hasAllOf(matcher, element, criteriaToCheck); + } + + return false; + + } + + + /** + * Validator to check if passed Element matches exactly one of the passed criteria. + * + * @param matcher The matcher to use + * @param element The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches exactly one of the passed criteria, otherwise false. + */ + public static > boolean hasOneOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { + if (element == null || matcher == null) { + return false; + } + + // always return true for null valued criteria + if (criteriaToCheck == null) { + return true; + } + + // always return true for empty or null valued criteriaToCheck + Set criteriaToCheckSet = Utilities.convertArrayToSet(criteriaToCheck); + if (criteriaToCheckSet.size() == 0) { + return true; + } + + + int count = 0; + // convert array to set to filter doubled elements + for (CRITERIA criteria : Utilities.convertArrayToSet(criteriaToCheck)) { + + if (matcher.checkForMatchingCharacteristic(element, criteria)) { + count++; + } + + } + + return count == 1; + } + + /** + * Validator to check if passed Element matches none of the passed criteria. + * + * @param matcher The matcher to use + * @param element The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches none of the passed criteria, otherwise false. + */ + + public static > boolean hasNoneOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { + if (element == null) { + return false; + } + + // always return true for null valued criteria + if (criteriaToCheck == null) { + return true; + } + + // always return true for empty or null valued criteriaToCheck + Set criteriaToCheckSet = Utilities.convertArrayToSet(criteriaToCheck); + if (criteriaToCheckSet.size() == 0) { + return true; + } + + // convert array to set to filter doubled elements + for (CRITERIA criteria : Utilities.convertArrayToSet(criteriaToCheck)) { + + if (matcher.checkForMatchingCharacteristic(element, criteria)) { + return false; + } + + } + + return true; + } + + /** + * Validator to check if passed Element matches all of the passed criteria. + * + * @param matcher The matcher to use + * @param element The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches all of the passed criteria, otherwise false. + */ + + public static > boolean hasAllOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { + + if (element == null) { + return false; + } + + // always return true for null valued criteria + if (criteriaToCheck == null) { + return true; + } + + // always return true for empty or null valued criteriaToCheck + Set criteriaToCheckSet = Utilities.convertArrayToSet(criteriaToCheck); + if (criteriaToCheckSet.size() == 0) { + return true; + } + + // convert array to set to filter doubled elements + for (CRITERIA criteria : Utilities.convertArrayToSet(criteriaToCheck)) { + + if (!matcher.checkForMatchingCharacteristic(element, criteria)) { + return false; + } + + } + + return true; + } + + /** + * Validator to check if passed Element matches at least one of the passed criteria. + * + * @param matcher The matcher to use + * @param element The element to be validated + * @param criteriaToCheck the criteria to check + * @param The Element type + * @param The criteria type + * @param The matcher type + * @return true, if passed element matches at least one of the passed criteria, otherwise false. + */ + + public static > boolean hasAtLeastOneOf(MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { + if (element == null) { + return false; + } + + // always return true for null valued criteria + if (criteriaToCheck == null) { + return true; + } + + // always return true for empty or null valued criteriaToCheck + Set criteriaToCheckSet = Utilities.convertArrayToSet(criteriaToCheck); + if (criteriaToCheckSet.size() == 0) { + return true; + } + + + // convert array to set to filter doubled elements + for (CRITERIA criteria : criteriaToCheck) { + + if (matcher.checkForMatchingCharacteristic(element, criteria)) { + return true; + } + + } + + return false; + } + + +} diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleResourceWriterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleResourceWriterTest.java deleted file mode 100644 index 5d9b3fbb..00000000 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/generators/SimpleResourceWriterTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.generators; - -/** - * Created by tobiasstamann on 22.08.17. - */ -public class SimpleResourceWriterTest { -} diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/internal/UtilitiesTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/internal/UtilitiesTest.java index ca0033f2..23059b61 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/internal/UtilitiesTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/internal/UtilitiesTest.java @@ -1,5 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.internal; +import io.toolisticon.annotationprocessortoolkit.tools.Utilities; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java index 774c89d8..aed06e30 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtilsTest.java @@ -6,8 +6,7 @@ import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; -import io.toolisticon.annotationprocessortoolkit.tools.filter.Filters; -import io.toolisticon.annotationprocessortoolkit.tools.validator.Validators; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -103,8 +102,8 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should have public modifier", Validators.MODIFIER_VALIDATOR.hasAllOf(element, Modifier.PUBLIC)); - MatcherAssert.assertThat("Class should not have abstract modifier", !Validators.MODIFIER_VALIDATOR.hasAllOf(element, Modifier.PUBLIC, Modifier.ABSTRACT)); + MatcherAssert.assertThat("Class should have public modifier", CoreMatchers.BY_MODIFIER.getValidator().hasAllOf(element, Modifier.PUBLIC)); + MatcherAssert.assertThat("Class should not have abstract modifier", !CoreMatchers.BY_MODIFIER.getValidator().hasAllOf(element, Modifier.PUBLIC, Modifier.ABSTRACT)); } } @@ -123,7 +122,7 @@ protected void testCase(TypeElement element) { MatcherAssert.assertThat("Class should be detected to have public modifier", ElementUtils.CheckModifierOfElement.hasPublicModifier(element)); - MatcherAssert.assertThat("Class should not be detected to have public modifier", !ElementUtils.CheckModifierOfElement.hasPublicModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have public modifier", !ElementUtils.CheckModifierOfElement.hasPublicModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have public modifier", !ElementUtils.CheckModifierOfElement.hasPublicModifier(null)); } @@ -141,9 +140,9 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should be detected to have protected modifier", ElementUtils.CheckModifierOfElement.hasProtectedModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "protectedField").get(0))); + MatcherAssert.assertThat("Class should be detected to have protected modifier", ElementUtils.CheckModifierOfElement.hasProtectedModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "protectedField").get(0))); - MatcherAssert.assertThat("Class should not be detected to have protected modifier", !ElementUtils.CheckModifierOfElement.hasProtectedModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have protected modifier", !ElementUtils.CheckModifierOfElement.hasProtectedModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have protected modifier", !ElementUtils.CheckModifierOfElement.hasProtectedModifier(null)); @@ -163,9 +162,9 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should be detected to have private modifier", ElementUtils.CheckModifierOfElement.hasPrivateModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should be detected to have private modifier", ElementUtils.CheckModifierOfElement.hasPrivateModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); - MatcherAssert.assertThat("Class should not be detected to have private modifier", !ElementUtils.CheckModifierOfElement.hasPrivateModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "protectedField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have private modifier", !ElementUtils.CheckModifierOfElement.hasPrivateModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "protectedField").get(0))); MatcherAssert.assertThat("Class should not be detected to have private modifier", !ElementUtils.CheckModifierOfElement.hasPrivateModifier(null)); @@ -185,12 +184,12 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - Element abstractType = Filters.MODIFIER_FILTER.filterByAllOf(Filters.ELEMENT_KIND_FILTER.filterByOneOf(element.getEnclosedElements(), ElementKind.CLASS), Modifier.ABSTRACT).get(0); + Element abstractType = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf(CoreMatchers.BY_ELEMENT_KIND.getFilter().filterByOneOf(element.getEnclosedElements(), ElementKind.CLASS), Modifier.ABSTRACT).get(0); - MatcherAssert.assertThat("Class should be detected to have abstract modifier", ElementUtils.CheckModifierOfElement.hasAbstractModifier(Filters.NAME_FILTER.filterByOneOf(abstractType.getEnclosedElements(), "abstractMethod").get(0))) + MatcherAssert.assertThat("Class should be detected to have abstract modifier", ElementUtils.CheckModifierOfElement.hasAbstractModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(abstractType.getEnclosedElements(), "abstractMethod").get(0))) ; - MatcherAssert.assertThat("Class should not be detected to have abstract modifier", !ElementUtils.CheckModifierOfElement.hasAbstractModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have abstract modifier", !ElementUtils.CheckModifierOfElement.hasAbstractModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have abstract modifier", !ElementUtils.CheckModifierOfElement.hasAbstractModifier(null)); @@ -210,9 +209,9 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should be detected to have static modifier", ElementUtils.CheckModifierOfElement.hasStaticModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "publicStaticField").get(0))); + MatcherAssert.assertThat("Class should be detected to have static modifier", ElementUtils.CheckModifierOfElement.hasStaticModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "publicStaticField").get(0))); - MatcherAssert.assertThat("Class should not be detected to have static modifier", !ElementUtils.CheckModifierOfElement.hasStaticModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have static modifier", !ElementUtils.CheckModifierOfElement.hasStaticModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have static modifier", !ElementUtils.CheckModifierOfElement.hasStaticModifier(null)); @@ -232,9 +231,9 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should be detected to have final modifier", ElementUtils.CheckModifierOfElement.hasFinalModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "publicFinalField").get(0))); + MatcherAssert.assertThat("Class should be detected to have final modifier", ElementUtils.CheckModifierOfElement.hasFinalModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "publicFinalField").get(0))); - MatcherAssert.assertThat("Class should not be detected to have final modifier", !ElementUtils.CheckModifierOfElement.hasFinalModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have final modifier", !ElementUtils.CheckModifierOfElement.hasFinalModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have final modifier", !ElementUtils.CheckModifierOfElement.hasFinalModifier(null)); @@ -253,9 +252,9 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should be detected to have transient modifier", ElementUtils.CheckModifierOfElement.hasTransientModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "publicTransientField").get(0))); + MatcherAssert.assertThat("Class should be detected to have transient modifier", ElementUtils.CheckModifierOfElement.hasTransientModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "publicTransientField").get(0))); - MatcherAssert.assertThat("Class should not be detected to have transient modifier", !ElementUtils.CheckModifierOfElement.hasTransientModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have transient modifier", !ElementUtils.CheckModifierOfElement.hasTransientModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have transient modifier", !ElementUtils.CheckModifierOfElement.hasTransientModifier(null)); @@ -274,9 +273,9 @@ protected void testCase(TypeElement element) { @Override protected void testCase(TypeElement element) { - MatcherAssert.assertThat("Class should be detected to have synchronized modifier", ElementUtils.CheckModifierOfElement.hasSynchronizedModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "synchronizedMethod").get(0))); + MatcherAssert.assertThat("Class should be detected to have synchronized modifier", ElementUtils.CheckModifierOfElement.hasSynchronizedModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "synchronizedMethod").get(0))); - MatcherAssert.assertThat("Class should not be detected to have synchronized modifier", !ElementUtils.CheckModifierOfElement.hasSynchronizedModifier(Filters.NAME_FILTER.filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); + MatcherAssert.assertThat("Class should not be detected to have synchronized modifier", !ElementUtils.CheckModifierOfElement.hasSynchronizedModifier(CoreMatchers.BY_NAME.getFilter().filterByOneOf(element.getEnclosedElements(), "privateField").get(0))); MatcherAssert.assertThat("Class should not be detected to have synchronized modifier", !ElementUtils.CheckModifierOfElement.hasSynchronizedModifier(null)); diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessEnclosedElementsTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessEnclosedElementsTest.java index e118629e..f617371d 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessEnclosedElementsTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_AccessEnclosedElementsTest.java @@ -1,6 +1,5 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElementTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElementTest.java index afc84dea..d5ae5b3a 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElementTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/ElementUtils_CheckModifierOfElementTest.java @@ -1,6 +1,5 @@ package io.toolisticon.annotationprocessortoolkit.tools; -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.mockito.Mockito; diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicElementFilterTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicElementFilterTest.java index ce1bd574..a77f8af7 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicElementFilterTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/filter/InclusiveCharacteristicElementFilterTest.java @@ -5,6 +5,7 @@ import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -50,12 +51,12 @@ public static List data() { @Override protected void testCase(TypeElement element) { - List filteredList = Filters.MODIFIER_FILTER.filterByAllOf((List) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED); + List filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED); MatcherAssert.assertThat("Must have exactly one element'", filteredList, Matchers.hasSize(1)); MatcherAssert.assertThat("Must find one element with name 'synchronizedMethod'", filteredList.get(0).getSimpleName().toString(), Matchers.is("synchronizedMethod")); // shouldn't find anything - filteredList = Filters.MODIFIER_FILTER.filterByAllOf((List) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED, Modifier.PROTECTED); + filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List) element.getEnclosedElements(), Modifier.PUBLIC, Modifier.SYNCHRONIZED, Modifier.PROTECTED); MatcherAssert.assertThat("Must have noelement'", filteredList, Matchers.empty()); diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcherTest.java index ad63c0d5..b0b09d72 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcherTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByGenericTypeMatcherTest.java @@ -1,15 +1,14 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; import io.toolisticon.annotationprocessortoolkit.tools.TypeUtils; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import io.toolisticon.annotationprocessortoolkit.tools.fluentfilter.FluentElementFilter; import io.toolisticon.annotationprocessortoolkit.tools.generics.GenericType; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.Matchers; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.junit.runner.RunWith; @@ -68,7 +67,7 @@ protected void testCase(TypeElement element) { ); - MatcherAssert.assertThat(Matchers.GENERIC_TYPE_MATCHER.getStringRepresentationOfPassedCharacteristic(genericTypeToConvert), org.hamcrest.Matchers.is("java.util.Map>>")); + MatcherAssert.assertThat(CoreMatchers.BY_GENERIC_TYPE.getMatcher().getStringRepresentationOfPassedCharacteristic(genericTypeToConvert), org.hamcrest.Matchers.is("java.util.Map>>")); } @@ -105,7 +104,7 @@ protected void testCase(TypeElement element) { ) ); - MatcherAssert.assertThat("Should compare successful", Matchers.GENERIC_TYPE_MATCHER.checkForMatchingCharacteristic(method.getParameters().get(0), genericType)); + MatcherAssert.assertThat("Should compare successful", CoreMatchers.BY_GENERIC_TYPE.getMatcher().checkForMatchingCharacteristic(method.getParameters().get(0), genericType)); } @@ -124,7 +123,6 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { - List result = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("testGenericsOnParameter") @@ -142,7 +140,7 @@ protected void testCase(TypeElement element) { ); - MatcherAssert.assertThat("Should not compare successful", !Matchers.GENERIC_TYPE_MATCHER.checkForMatchingCharacteristic(method.getParameters().get(0), genericType)); + MatcherAssert.assertThat("Should not compare successful", !CoreMatchers.BY_GENERIC_TYPE.getMatcher().checkForMatchingCharacteristic(method.getParameters().get(0), genericType)); } @@ -162,7 +160,6 @@ protected void testCase(TypeElement element) { protected void testCase(TypeElement element) { - List result = FluentElementFilter.createFluentElementFilter(element.getEnclosedElements()) .applyFilter(CoreMatchers.BY_ELEMENT_KIND).filterByOneOf(ElementKind.METHOD) .applyFilter(CoreMatchers.BY_NAME).filterByOneOf("testGenericsOnParameter").getResult(); @@ -188,7 +185,7 @@ protected void testCase(TypeElement element) { ) ); - MatcherAssert.assertThat("Should compare successful", Matchers.GENERIC_TYPE_MATCHER.checkForMatchingCharacteristic(method.getParameters().get(1), genericType)); + MatcherAssert.assertThat("Should compare successful", CoreMatchers.BY_GENERIC_TYPE.getMatcher().checkForMatchingCharacteristic(method.getParameters().get(1), genericType)); } } @@ -235,7 +232,7 @@ protected void testCase(TypeElement element) { ) ); - MatcherAssert.assertThat("Should not compare successful", !Matchers.GENERIC_TYPE_MATCHER.checkForMatchingCharacteristic(method.getParameters().get(1), genericType)); + MatcherAssert.assertThat("Should not compare successful", !CoreMatchers.BY_GENERIC_TYPE.getMatcher().checkForMatchingCharacteristic(method.getParameters().get(1), genericType)); } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcherTest.java index a69a7d59..2d1be580 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcherTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ByParameterTypeMatcherTest.java @@ -1,12 +1,12 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.Matchers; +import io.toolisticon.annotationprocessortoolkit.tools.Utilities; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.junit.runner.RunWith; @@ -54,7 +54,7 @@ protected void testCase(TypeElement element) { MatcherAssert.assertThat("Precondition: second parameter must be of type String but is " + executableElement.getParameters().get(1).asType().toString(), executableElement.getParameters().get(1).asType().toString().equals(String.class.getCanonicalName())); - MatcherAssert.assertThat("Should have found matching parameters", Matchers.PARAMETER_TYPE_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class, String.class))); + MatcherAssert.assertThat("Should have found matching parameters", CoreMatchers.BY_PARAMETER_TYPE.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class, String.class))); } } @@ -77,9 +77,9 @@ protected void testCase(TypeElement element) { ExecutableElement executableElement = ElementUtils.CastElement.castElementList(result, ExecutableElement.class).get(0); MatcherAssert.assertThat("Precondition: method must have 2 parameters", executableElement.getParameters().size() == 2); - MatcherAssert.assertThat("Should not have found matching parameters", !Matchers.PARAMETER_TYPE_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(String.class, Boolean.class))); - MatcherAssert.assertThat("Should not have found matching parameters", !Matchers.PARAMETER_TYPE_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class))); - MatcherAssert.assertThat("Should not have found matching parameters", !Matchers.PARAMETER_TYPE_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class, String.class, String.class))); + MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_PARAMETER_TYPE.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(String.class, Boolean.class))); + MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_PARAMETER_TYPE.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class))); + MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_PARAMETER_TYPE.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class, String.class, String.class))); } } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ParameterTypeFqnMatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ParameterTypeFqnMatcherTest.java index 3ec7a301..0e23ab91 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ParameterTypeFqnMatcherTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/matcher/impl/ParameterTypeFqnMatcherTest.java @@ -1,12 +1,12 @@ package io.toolisticon.annotationprocessortoolkit.tools.matcher.impl; -import io.toolisticon.annotationprocessortoolkit.internal.Utilities; import io.toolisticon.annotationprocessortoolkit.testhelper.AbstractAnnotationProcessorUnitTest; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AbstractUnitTestAnnotationProcessorClass; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfiguration; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.AnnotationProcessorUnitTestConfigurationBuilder; import io.toolisticon.annotationprocessortoolkit.tools.ElementUtils; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.Matchers; +import io.toolisticon.annotationprocessortoolkit.tools.Utilities; +import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,7 +55,7 @@ protected void testCase(TypeElement element) { MatcherAssert.assertThat("Precondition: second parameter must be of type String but is " + executableElement.getParameters().get(1).asType().toString(), executableElement.getParameters().get(1).asType().toString().equals(String.class.getCanonicalName())); - MatcherAssert.assertThat("Should have found matching parameters", Matchers.PARAMETER_TYPE_FQN_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class.getCanonicalName(), String.class.getCanonicalName()))); + MatcherAssert.assertThat("Should have found matching parameters", CoreMatchers.BY_PARAMETER_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class.getCanonicalName(), String.class.getCanonicalName()))); } } @@ -80,9 +80,9 @@ protected void testCase(TypeElement element) { MatcherAssert.assertThat("Precondition: method must have 2 parameters", executableElement.getParameters().size() == 2); - MatcherAssert.assertThat("Should not have found matching parameters", !Matchers.PARAMETER_TYPE_FQN_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(String.class.getCanonicalName(), Boolean.class.getCanonicalName()))); - MatcherAssert.assertThat("Should not have found matching parameters", !Matchers.PARAMETER_TYPE_FQN_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class.getCanonicalName()))); - MatcherAssert.assertThat("Should not have found matching parameters", !Matchers.PARAMETER_TYPE_FQN_MATCHER.checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class.getCanonicalName(), String.class.getCanonicalName(), String.class.getCanonicalName()))); + MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_PARAMETER_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(String.class.getCanonicalName(), Boolean.class.getCanonicalName()))); + MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_PARAMETER_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class.getCanonicalName()))); + MatcherAssert.assertThat("Should not have found matching parameters", !CoreMatchers.BY_PARAMETER_TYPE_FQN.getMatcher().checkForMatchingCharacteristic(executableElement, Utilities.convertVarargsToArray(Boolean.class.getCanonicalName(), String.class.getCanonicalName(), String.class.getCanonicalName()))); } } diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/AnnotationValidatorTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/AnnotationValidatorTest.java index 473eeba2..deee8869 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/AnnotationValidatorTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/AnnotationValidatorTest.java @@ -2,7 +2,7 @@ import io.toolisticon.annotationprocessortoolkit.FilterTestAnnotation2; import io.toolisticon.annotationprocessortoolkit.testhelper.unittest.TestAnnotation; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByAnnotationMatcher; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -12,7 +12,7 @@ import java.lang.annotation.Annotation; /** - * Unit and integration test of {@link InclusiveCharacteristicsElementValidator} with {@link ByAnnotationMatcher}. + * Unit and integration test of {@link InclusiveCriteriaElementValidator} with {@link ByAnnotationMatcher}. */ public class AnnotationValidatorTest { @@ -33,7 +33,7 @@ public void test_allOf_match() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(true); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return true", unit.hasAllOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -51,7 +51,7 @@ public void test_allOf_oneMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have not found FilterTestAnnotation2 and return false", !unit.hasAllOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -68,7 +68,7 @@ public void test_allOf_nonMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have not found any match and return false", !unit.hasAllOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -80,7 +80,7 @@ public void test_allOf_nullValuedElement() { ByAnnotationMatcher byAnnotationMatcher = Mockito.mock(ByAnnotationMatcher.class); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasAllOf(null, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -98,7 +98,7 @@ public void test_allOf_missingAnnotationParameters() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasAllOf(element)); @@ -121,7 +121,7 @@ public void test_hasAtLeastOneOf_match() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(true); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return true", unit.hasAtLeastOneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); } @@ -138,7 +138,7 @@ public void test_hasAtLeastOneOf_oneMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have found TestAnnotation and return true", unit.hasAtLeastOneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -156,7 +156,7 @@ public void test_hasAtLeastOneOf_nonMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have not found any match and return false", !unit.hasAtLeastOneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -168,7 +168,7 @@ public void test_hasAtLeastOneOf_nullValuedElement() { ByAnnotationMatcher byAnnotationMatcher = Mockito.mock(ByAnnotationMatcher.class); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasAtLeastOneOf(null, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -186,7 +186,7 @@ public void test_hasAtLeastOneOf_missingAnnotationParameters() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasAtLeastOneOf(element)); MatcherAssert.assertThat("Should always return true for single null valued characteristics", unit.hasAtLeastOneOf(element, null)); MatcherAssert.assertThat("Should always return true for multiple nulll valued characteristics", unit.hasAtLeastOneOf(element, null, null)); @@ -211,7 +211,7 @@ public void test_hasOneOf_match() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(true); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return false since only one match is allowed", !unit.hasOneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); } @@ -228,7 +228,7 @@ public void test_hasOneOf_oneMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have just found TestAnnotation and return true", unit.hasOneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -246,7 +246,7 @@ public void test_hasOneOf_nonMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have not found any match and return false", !unit.hasOneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -258,7 +258,7 @@ public void test_hasOneOf_nullValuedElement() { ByAnnotationMatcher byAnnotationMatcher = Mockito.mock(ByAnnotationMatcher.class); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasOneOf(null, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -276,7 +276,7 @@ public void test_hasOneOf_missingAnnotationParameters() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasOneOf(element)); MatcherAssert.assertThat("Should always return true for single null valued characteristics", unit.hasOneOf(element, null)); MatcherAssert.assertThat("Should always return true for multiple nulll valued characteristics", unit.hasOneOf(element, null, null)); @@ -301,7 +301,7 @@ public void test_hasNoneOf_match() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(true); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return false", !unit.hasNoneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); } @@ -318,7 +318,7 @@ public void test_hasNoneOf_oneMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have found TestAnnotation and return false", !unit.hasNoneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -336,7 +336,7 @@ public void test_hasNoneOf_nonMissingMatch() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should have not found any match and return true", unit.hasNoneOf(element, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -348,7 +348,7 @@ public void test_hasNoneOf_nullValuedElement() { ByAnnotationMatcher byAnnotationMatcher = Mockito.mock(ByAnnotationMatcher.class); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasNoneOf(null, TestAnnotation.class, FilterTestAnnotation2.class)); @@ -366,7 +366,7 @@ public void test_hasNoneOf_missingAnnotationParameters() { Mockito.when(byAnnotationMatcher.checkForMatchingCharacteristic(element, FilterTestAnnotation2.class)).thenReturn(false); - InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>> unit = new InclusiveCharacteristicsElementValidator, CharacteristicsMatcher>>(byAnnotationMatcher,""); + InclusiveCriteriaElementValidator, CriteriaMatcher>> unit = new InclusiveCriteriaElementValidator, CriteriaMatcher>>(byAnnotationMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasNoneOf(element)); diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/GenericMatcherTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/GenericMatcherTest.java index b711f9a3..90410d74 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/GenericMatcherTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/GenericMatcherTest.java @@ -1,7 +1,7 @@ package io.toolisticon.annotationprocessortoolkit.tools.validator; /** - * Unit test of {@link InclusiveCharacteristicsElementValidator}. + * Unit test of {@link InclusiveCriteriaElementValidator}. */ public class GenericMatcherTest { @@ -10,7 +10,7 @@ public class GenericMatcherTest { @Test public void testHasOf_OneOf() { - InclusiveCharacteristicsElementValidator> spy = Mockito.spy(Validators.MODIFIER_VALIDATOR); + InclusiveCriteriaElementValidator> spy = Mockito.spy(Validators.MODIFIER_VALIDATOR); Element element = Mockito.mock(Element.class); spy.hasOf(ValidatorKind.ONE_OF, element, Modifier.ABSTRACT); diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ModifierValidatorTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ModifierValidatorTest.java index a7fb3393..3a9d0da2 100644 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ModifierValidatorTest.java +++ b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ModifierValidatorTest.java @@ -1,6 +1,6 @@ package io.toolisticon.annotationprocessortoolkit.tools.validator; -import io.toolisticon.annotationprocessortoolkit.tools.matcher.CharacteristicsMatcher; +import io.toolisticon.annotationprocessortoolkit.tools.matcher.CriteriaMatcher; import io.toolisticon.annotationprocessortoolkit.tools.matcher.impl.ByModifierMatcher; import org.hamcrest.MatcherAssert; import org.junit.Test; @@ -30,7 +30,7 @@ public void test_allOf_match() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(true); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return true", unit.hasAllOf(element, Modifier.FINAL, Modifier.PUBLIC)); } @@ -47,7 +47,7 @@ public void test_allOf_oneMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have not found FilterTestAnnotation2 and return false", !unit.hasAllOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -65,7 +65,7 @@ public void test_allOf_nonMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have not found any match and return false", !unit.hasAllOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -79,7 +79,7 @@ public void test_allOf_nullValuedElement() { ByModifierMatcher byModifierMatcher = Mockito.mock(ByModifierMatcher.class); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasAllOf(null, Modifier.FINAL, Modifier.PUBLIC)); @@ -97,7 +97,7 @@ public void test_allOf_missingAnnotationParameters() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasAllOf(element)); @@ -119,7 +119,7 @@ public void test_hasAtLeastOneOf_match() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.FINAL)).thenReturn(true); Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(true); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return true", unit.hasAtLeastOneOf(element, Modifier.FINAL, Modifier.PUBLIC)); } @@ -135,7 +135,7 @@ public void test_hasAtLeastOneOf_oneMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.FINAL)).thenReturn(true); Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have found TestAnnotation and return true", unit.hasAtLeastOneOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -153,7 +153,7 @@ public void test_hasAtLeastOneOf_nonMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.FINAL)).thenReturn(false); Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have not found any match and return false", !unit.hasAtLeastOneOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -167,7 +167,7 @@ public void test_hasAtLeastOneOf_nullValuedElement() { ByModifierMatcher byModifierMatcher = Mockito.mock(ByModifierMatcher.class); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasAtLeastOneOf(null, Modifier.FINAL, Modifier.PUBLIC)); @@ -183,7 +183,7 @@ public void test_hasAtLeastOneOf_missingAnnotationParameters() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.FINAL)).thenReturn(false); Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasAtLeastOneOf(element)); MatcherAssert.assertThat("Should always return true for single null valued characteristics", unit.hasAtLeastOneOf(element, null)); MatcherAssert.assertThat("Should always return true for multiple nulll valued characteristics", unit.hasAtLeastOneOf(element, null, null)); @@ -208,7 +208,7 @@ public void test_hasOneOf_match() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(true); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return false since only one match is allowed", !unit.hasOneOf(element, Modifier.FINAL, Modifier.PUBLIC)); } @@ -226,7 +226,7 @@ public void test_hasOneOf_oneMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have just found TestAnnotation and return true", unit.hasOneOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -244,7 +244,7 @@ public void test_hasOneOf_nonMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have not found any match and return false", !unit.hasOneOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -258,7 +258,7 @@ public void test_hasOneOf_nullValuedElement() { ByModifierMatcher byModifierMatcher = Mockito.mock(ByModifierMatcher.class); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasOneOf(null, Modifier.FINAL, Modifier.PUBLIC)); @@ -276,7 +276,7 @@ public void test_hasOneOf_missingAnnotationParameters() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasOneOf(element)); MatcherAssert.assertThat("Should always return true for single null valued characteristics", unit.hasOneOf(element, null)); MatcherAssert.assertThat("Should always return true for multiple nulll valued characteristics", unit.hasOneOf(element, null, null)); @@ -302,7 +302,7 @@ public void test_hasNoneOf_match() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(true); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have found all annotation and return false", !unit.hasNoneOf(element, Modifier.FINAL, Modifier.PUBLIC)); } @@ -319,7 +319,7 @@ public void test_hasNoneOf_oneMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have found TestAnnotation and return false", !unit.hasNoneOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -337,7 +337,7 @@ public void test_hasNoneOf_nonMissingMatch() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.FINAL)).thenReturn(false); Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should have not found any match and return true", unit.hasNoneOf(element, Modifier.FINAL, Modifier.PUBLIC)); @@ -349,7 +349,7 @@ public void test_hasNoneOf_nullValuedElement() { ByModifierMatcher byModifierMatcher = Mockito.mock(ByModifierMatcher.class); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return null for null valued element", !unit.hasNoneOf(null, Modifier.FINAL, Modifier.PUBLIC)); @@ -366,7 +366,7 @@ public void test_hasNoneOf_missingAnnotationParameters() { Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.FINAL)).thenReturn(false); Mockito.when(byModifierMatcher.checkForMatchingCharacteristic(element, Modifier.PUBLIC)).thenReturn(false); - InclusiveCharacteristicsElementValidator> unit = new InclusiveCharacteristicsElementValidator>(byModifierMatcher,""); + InclusiveCriteriaElementValidator> unit = new InclusiveCriteriaElementValidator>(byModifierMatcher,""); MatcherAssert.assertThat("Should always return true for non existing characteristics", unit.hasNoneOf(element)); diff --git a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ValidatorTest.java b/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ValidatorTest.java deleted file mode 100644 index 33670268..00000000 --- a/annotationprocessor/src/test/java/io/toolisticon/annotationprocessortoolkit/tools/validator/ValidatorTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package io.toolisticon.annotationprocessortoolkit.tools.validator; - -import io.toolisticon.annotationprocessortoolkit.tools.corematcher.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * unit test for {@link Validators} class. - */ -public class ValidatorTest { - - - // ------------------------------------ - // -- MODIFIER_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testModifierValidator() { - - MatcherAssert.assertThat(Validators.MODIFIER_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_MODIFIER.getMatcher())); - - } - - - // ------------------------------------ - // -- ANNOTATION_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testAnnotationValidator() { - - MatcherAssert.assertThat(Validators.ANNOTATION_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_ANNOTATION.getMatcher())); - - } - - - // ------------------------------------ - // -- NAME_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testNameValidator() { - - MatcherAssert.assertThat(Validators.NAME_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_NAME.getMatcher())); - - } - - - // ------------------------------------ - // -- REGEX_NAME_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testRegexNameValidator() { - - MatcherAssert.assertThat(Validators.REGEX_NAME_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_REGEX_NAME.getMatcher())); - - } - - - // ------------------------------------ - // -- ELEMENT_KIND_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testElementKindValidator() { - - MatcherAssert.assertThat(Validators.ELEMENT_KIND_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_ELEMENT_KIND.getMatcher())); - - } - - - // ------------------------------------ - // -- PARAMETER_TYPE_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testParameterValidator() { - - MatcherAssert.assertThat(Validators.PARAMETER_TYPE_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_PARAMETER_TYPE.getMatcher())); - - } - - - // ------------------------------------ - // -- PARAMETER_TYPE_FQN_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testParameterFQNValidator() { - - MatcherAssert.assertThat(Validators.PARAMETER_TYPE_FQN_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_PARAMETER_TYPE_FQN.getMatcher())); - - } - - - // ------------------------------------ - // -- RAW_TYPE_VALIDATOR Validator tests - // ------------------------------------ - - @Test - public void testTypeValidator() { - - MatcherAssert.assertThat(Validators.RAW_TYPE_VALIDATOR.getMatcher(), Matchers.is(CoreMatchers.BY_RAW_TYPE.getMatcher())); - - } - - -}