org.reflections.scanners.AbstractScanner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-all Show documentation
Show all versions of swagger-all Show documentation
swagger-all is a rebundled verison of Swagger as one OSGi bundle.
The newest version!
package org.reflections.scanners;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Multimap;
import org.reflections.Configuration;
import org.reflections.ReflectionsException;
import org.reflections.adapters.MetadataAdapter;
import org.reflections.vfs.Vfs;
import static org.reflections.Reflections.log;
/**
*
*/
@SuppressWarnings({"RawUseOfParameterizedType", "unchecked"})
public abstract class AbstractScanner implements Scanner {
private Configuration configuration;
private Multimap store;
private Predicate resultFilter = Predicates.alwaysTrue(); //accept all by default
public boolean acceptsInput(String file) {
return getMetadataAdapter().acceptsInput(file);
}
public Object scan(Vfs.File file, Object classObject) {
if (classObject == null) {
try {
classObject = configuration.getMetadataAdapter().getOfCreateClassObject(file);
} catch (Exception e) {
throw new ReflectionsException("could not create class object from file " + file.getRelativePath());
}
}
scan(classObject);
return classObject;
}
public abstract void scan(Object cls);
//
public Configuration getConfiguration() {
return configuration;
}
public void setConfiguration(final Configuration configuration) {
this.configuration = configuration;
}
public Multimap getStore() {
return store;
}
public void setStore(final Multimap store) {
this.store = store;
}
public Predicate getResultFilter() {
return resultFilter;
}
public void setResultFilter(Predicate resultFilter) {
this.resultFilter = resultFilter;
}
public Scanner filterResultsBy(Predicate filter) {
this.setResultFilter(filter); return this;
}
//
public boolean acceptResult(final String fqn) {
return fqn != null && resultFilter.apply(fqn);
}
protected MetadataAdapter getMetadataAdapter() {
return configuration.getMetadataAdapter();
}
//
@Override public boolean equals(Object o) {
return this == o || o != null && getClass() == o.getClass();
}
@Override public int hashCode() {
return getClass().hashCode();
}
}