com.ui4j.bytebuddy.matcher.VisibilityMatcher Maven / Gradle / Ivy
The newest version!
package com.ui4j.bytebuddy.matcher;
import com.ui4j.bytebuddy.instrumentation.ByteCodeElement;
import com.ui4j.bytebuddy.instrumentation.type.TypeDescription;
/**
* An element matcher that validates that a given byte code element is visible to a given type.
*
* @param The type of the matched entity.
*/
public class VisibilityMatcher extends ElementMatcher.Junction.AbstractBase {
/**
* The type that is to be checked for its viewing rights.
*/
private final TypeDescription typeDescription;
/**
* Creates a matcher that validates that a byte code element can be seen by a given type.
*
* @param typeDescription The type that is to be checked for its viewing rights.
*/
public VisibilityMatcher(TypeDescription typeDescription) {
this.typeDescription = typeDescription;
}
@Override
public boolean matches(T target) {
return target.isVisibleTo(typeDescription);
}
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& typeDescription.equals(((VisibilityMatcher) other).typeDescription);
}
@Override
public int hashCode() {
return typeDescription.hashCode();
}
@Override
public String toString() {
return "isVisibleTo(" + typeDescription + ")";
}
}