cdc.issues.checks.SpecializationChecker Maven / Gradle / Ivy
The newest version!
package cdc.issues.checks;
import java.io.PrintStream;
import cdc.issues.locations.Location;
import cdc.util.debug.Printables;
import cdc.util.lang.Checks;
public class SpecializationChecker extends AbstractChecker {
private final AbstractChecker delegate;
public SpecializationChecker(SnapshotManager manager,
Class objectClass,
AbstractChecker delegate) {
super(manager,
objectClass);
this.delegate = Checks.isNotNull(delegate, "delegate");
}
public AbstractChecker getDelegate() {
return delegate;
}
@Override
public final boolean isEnabled() {
return delegate.isEnabled();
}
@Override
public final boolean isCorrectlyConfigured() {
return delegate.isCorrectlyConfigured();
}
@Override
public boolean accepts(O object) {
if (object == null || delegate.getObjectClass().isInstance(object)) {
return delegate.accepts(delegate.getObjectClass().cast(object));
} else {
return false;
}
}
@Override
public CheckResult check(CheckContext context,
O object,
Location location) {
return delegate.check(context,
delegate.getObjectClass().cast(object),
location);
}
@Override
public void print(PrintStream out,
int level) {
Printables.indent(out, level);
out.println("SPECIALIZATION<" + getObjectClass().getSimpleName()
+ ", " + getDelegate().getObjectClass().getSimpleName() + ">");
delegate.print(out, level + 1);
}
}