Skip to content

Commit

Permalink
Added matcher for super type property.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jun 1, 2016
1 parent 38f02a1 commit f02f26a
Show file tree
Hide file tree
Showing 23 changed files with 328 additions and 157 deletions.
Expand Up @@ -13,35 +13,35 @@ public class AnnotationTypeMatcher<T extends AnnotationDescription> extends Elem
/**
* The type matcher to apply to an annotation's type.
*/
private final ElementMatcher<? super TypeDescription> typeMatcher;
private final ElementMatcher<? super TypeDescription> matcher;

/**
* Creates a new matcher for an annotation description's type.
*
* @param typeMatcher The type matcher to apply to an annotation's type.
*/
public AnnotationTypeMatcher(ElementMatcher<? super TypeDescription> typeMatcher) {
this.typeMatcher = typeMatcher;
public AnnotationTypeMatcher(ElementMatcher<? super TypeDescription> matcher) {
this.matcher = matcher;
}

@Override
public boolean matches(T target) {
return typeMatcher.matches(target.getAnnotationType());
return matcher.matches(target.getAnnotationType());
}

@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& typeMatcher.equals(((AnnotationTypeMatcher<?>) other).typeMatcher);
&& matcher.equals(((AnnotationTypeMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return typeMatcher.hashCode();
return matcher.hashCode();
}

@Override
public String toString() {
return "ofAnnotationType(" + typeMatcher + ')';
return "ofAnnotationType(" + matcher + ')';
}
}
Expand Up @@ -11,42 +11,42 @@ public class ClassLoaderHierarchyMatcher<T extends ClassLoader> implements Eleme
/**
* The matcher to apply on each class loader in the hierarchy.
*/
private final ElementMatcher<? super ClassLoader> classLoaderMatcher;
private final ElementMatcher<? super ClassLoader> matcher;

/**
* Creates a new class loader hierarchy matcher.
*
* @param classLoaderMatcher The matcher to apply on each class loader in the hierarchy.
* @param matcher The matcher to apply on each class loader in the hierarchy.
*/
public ClassLoaderHierarchyMatcher(ElementMatcher<? super ClassLoader> classLoaderMatcher) {
this.classLoaderMatcher = classLoaderMatcher;
public ClassLoaderHierarchyMatcher(ElementMatcher<? super ClassLoader> matcher) {
this.matcher = matcher;
}

@Override
public boolean matches(T target) {
ClassLoader current = target;
while (current != null) {
if (classLoaderMatcher.matches(current)) {
if (matcher.matches(current)) {
return true;
}
current = current.getParent();
}
return classLoaderMatcher.matches(null);
return matcher.matches(null);
}

@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& classLoaderMatcher.equals(((ClassLoaderHierarchyMatcher<?>) other).classLoaderMatcher);
&& matcher.equals(((ClassLoaderHierarchyMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return classLoaderMatcher.hashCode();
return matcher.hashCode();
}

@Override
public String toString() {
return "hasChild(" + classLoaderMatcher + ')';
return "hasChild(" + matcher + ')';
}
}
Expand Up @@ -18,17 +18,17 @@ public class CollectionElementMatcher<T> extends ElementMatcher.Junction.Abstrac
/**
* The matcher for the given element, if it exists.
*/
private final ElementMatcher<? super T> elementMatcher;
private final ElementMatcher<? super T> matcher;

/**
* Creates a new matcher for an element in a collection.
*
* @param index The index of the matched element.
* @param elementMatcher The matcher for the given element, if it exists.
* @param matcher The matcher for the given element, if it exists.
*/
public CollectionElementMatcher(int index, ElementMatcher<? super T> elementMatcher) {
public CollectionElementMatcher(int index, ElementMatcher<? super T> matcher) {
this.index = index;
this.elementMatcher = elementMatcher;
this.matcher = matcher;
}

@Override
Expand All @@ -41,23 +41,23 @@ public boolean matches(Iterable<? extends T> target) {
return false;
}
}
return iterator.hasNext() && elementMatcher.matches(iterator.next());
return iterator.hasNext() && matcher.matches(iterator.next());
}

@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& index == ((CollectionElementMatcher<?>) other).index
&& elementMatcher.equals(((CollectionElementMatcher<?>) other).elementMatcher);
&& matcher.equals(((CollectionElementMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return elementMatcher.hashCode() + 31 * index;
return matcher.hashCode() + 31 * index;
}

@Override
public String toString() {
return "with(" + index + " matches " + elementMatcher + ")";
return "with(" + index + " matches " + matcher + ")";
}
}
Expand Up @@ -11,21 +11,21 @@ public class CollectionItemMatcher<T> extends ElementMatcher.Junction.AbstractBa
/**
* The element matcher to apply to each element of a collection.
*/
private final ElementMatcher<? super T> elementMatcher;
private final ElementMatcher<? super T> matcher;

/**
* Creates a new matcher that applies another matcher to each element of a matched iterable collection.
*
* @param elementMatcher The element matcher to apply to each element of a iterable collection.
* @param matcher The element matcher to apply to each element of a iterable collection.
*/
public CollectionItemMatcher(ElementMatcher<? super T> elementMatcher) {
this.elementMatcher = elementMatcher;
public CollectionItemMatcher(ElementMatcher<? super T> matcher) {
this.matcher = matcher;
}

@Override
public boolean matches(Iterable<? extends T> target) {
for (T value : target) {
if (elementMatcher.matches(value)) {
if (matcher.matches(value)) {
return true;
}
}
Expand All @@ -35,16 +35,16 @@ public boolean matches(Iterable<? extends T> target) {
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& elementMatcher.equals(((CollectionItemMatcher<?>) other).elementMatcher);
&& matcher.equals(((CollectionItemMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return elementMatcher.hashCode();
return matcher.hashCode();
}

@Override
public String toString() {
return "whereOne(" + elementMatcher + ")";
return "whereOne(" + matcher + ")";
}
}
Expand Up @@ -17,24 +17,24 @@ public class CollectionOneToOneMatcher<T> extends ElementMatcher.Junction.Abstra
/**
* The list of element matchers to match any elements of the matched iterable collection against.
*/
private final List<? extends ElementMatcher<? super T>> elementMatchers;
private final List<? extends ElementMatcher<? super T>> matchers;

/**
* Creates a new matcher that compares a matched iterable collection against a list of element matchers.
*
* @param elementMatchers The list of element matchers to match any elements of the matched iterable collection
* @param matchers The list of element matchers to match any elements of the matched iterable collection
* against.
*/
public CollectionOneToOneMatcher(List<? extends ElementMatcher<? super T>> elementMatchers) {
this.elementMatchers = elementMatchers;
public CollectionOneToOneMatcher(List<? extends ElementMatcher<? super T>> matchers) {
this.matchers = matchers;
}

@Override
public boolean matches(Iterable<? extends T> target) {
if ((target instanceof Collection) && ((Collection<?>) target).size() != elementMatchers.size()) {
if ((target instanceof Collection) && ((Collection<?>) target).size() != matchers.size()) {
return false;
}
Iterator<? extends ElementMatcher<? super T>> iterator = elementMatchers.iterator();
Iterator<? extends ElementMatcher<? super T>> iterator = matchers.iterator();
for (T value : target) {
if (!iterator.hasNext() || !iterator.next().matches(value)) {
return false;
Expand All @@ -46,19 +46,19 @@ public boolean matches(Iterable<? extends T> target) {
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& elementMatchers.equals(((CollectionOneToOneMatcher<?>) other).elementMatchers);
&& matchers.equals(((CollectionOneToOneMatcher<?>) other).matchers);
}

@Override
public int hashCode() {
return elementMatchers.hashCode();
return matchers.hashCode();
}

@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder("containing(");
boolean first = true;
for (Object value : elementMatchers) {
for (Object value : matchers) {
if (first) {
first = false;
} else {
Expand Down
Expand Up @@ -13,35 +13,35 @@ public class DeclaringAnnotationMatcher<T extends AnnotatedCodeElement> extends
/**
* The matcher to be applied to the provided annotation list.
*/
private final ElementMatcher<? super AnnotationList> annotationMatcher;
private final ElementMatcher<? super AnnotationList> matcher;

/**
* Creates a new matcher for the annotations of an annotated element.
*
* @param annotationMatcher The matcher to be applied to the provided annotation list.
* @param matcher The matcher to be applied to the provided annotation list.
*/
public DeclaringAnnotationMatcher(ElementMatcher<? super AnnotationList> annotationMatcher) {
this.annotationMatcher = annotationMatcher;
public DeclaringAnnotationMatcher(ElementMatcher<? super AnnotationList> matcher) {
this.matcher = matcher;
}

@Override
public boolean matches(T target) {
return annotationMatcher.matches(target.getDeclaredAnnotations());
return matcher.matches(target.getDeclaredAnnotations());
}

@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& annotationMatcher.equals(((DeclaringAnnotationMatcher<?>) other).annotationMatcher);
&& matcher.equals(((DeclaringAnnotationMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return annotationMatcher.hashCode();
return matcher.hashCode();
}

@Override
public String toString() {
return "declaresAnnotations(" + annotationMatcher + ")";
return "declaresAnnotations(" + matcher + ")";
}
}
Expand Up @@ -14,35 +14,35 @@ public class DeclaringFieldMatcher<T extends TypeDefinition> extends ElementMatc
/**
* The field matcher to apply to the declared fields of the matched type description.
*/
private final ElementMatcher<? super FieldList<?>> fieldMatcher;
private final ElementMatcher<? super FieldList<?>> matcher;

/**
* Creates a new matcher for a type's declared fields.
*
* @param fieldMatcher The field matcher to apply to the declared fields of the matched type description.
* @param matcher The field matcher to apply to the declared fields of the matched type description.
*/
public DeclaringFieldMatcher(ElementMatcher<? super FieldList<? extends FieldDescription>> fieldMatcher) {
this.fieldMatcher = fieldMatcher;
public DeclaringFieldMatcher(ElementMatcher<? super FieldList<? extends FieldDescription>> matcher) {
this.matcher = matcher;
}

@Override
public boolean matches(T target) {
return fieldMatcher.matches(target.getDeclaredFields());
return matcher.matches(target.getDeclaredFields());
}

@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& fieldMatcher.equals(((DeclaringFieldMatcher<?>) other).fieldMatcher);
&& matcher.equals(((DeclaringFieldMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return fieldMatcher.hashCode();
return matcher.hashCode();
}

@Override
public String toString() {
return "declaresFields(" + fieldMatcher + ")";
return "declaresFields(" + matcher + ")";
}
}
Expand Up @@ -14,35 +14,35 @@ public class DeclaringMethodMatcher<T extends TypeDefinition> extends ElementMat
/**
* The field matcher to apply to the declared fields of the matched type description.
*/
private final ElementMatcher<? super MethodList<?>> methodMatcher;
private final ElementMatcher<? super MethodList<?>> matcher;

/**
* Creates a new matcher for a type's declared methods.
*
* @param methodMatcher The method matcher to apply to the declared methods of the matched type description.
* @param matcher The method matcher to apply to the declared methods of the matched type description.
*/
public DeclaringMethodMatcher(ElementMatcher<? super MethodList<? extends MethodDescription>> methodMatcher) {
this.methodMatcher = methodMatcher;
public DeclaringMethodMatcher(ElementMatcher<? super MethodList<? extends MethodDescription>> matcher) {
this.matcher = matcher;
}

@Override
public boolean matches(T target) {
return methodMatcher.matches(target.getDeclaredMethods());
return matcher.matches(target.getDeclaredMethods());
}

@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& methodMatcher.equals(((DeclaringMethodMatcher<?>) other).methodMatcher);
&& matcher.equals(((DeclaringMethodMatcher<?>) other).matcher);
}

@Override
public int hashCode() {
return methodMatcher.hashCode();
return matcher.hashCode();
}

@Override
public String toString() {
return "declaresMethods(" + methodMatcher + ")";
return "declaresMethods(" + matcher + ")";
}
}

0 comments on commit f02f26a

Please sign in to comment.