org.simpleflatmapper.reflect.meta.PassThroughPropertyFinder Maven / Gradle / Ivy
Show all versions of sfm-reflect Show documentation
package org.simpleflatmapper.reflect.meta;
import org.simpleflatmapper.reflect.InstantiatorDefinition;
import org.simpleflatmapper.util.Predicate;
import java.lang.reflect.Type;
import java.util.List;
public class PassThroughPropertyFinder extends PropertyFinder {
private final PassThroughClassMeta passThroughClassMeta;
private final PropertyFinder propertyFinder;
private final ClassMeta innerMeta;
@Deprecated
public PassThroughPropertyFinder(PassThroughClassMeta passThroughClassMeta, boolean selfScoreFullName) {
this(passThroughClassMeta);
}
public PassThroughPropertyFinder(PassThroughClassMeta passThroughClassMeta) {
super();
this.passThroughClassMeta = passThroughClassMeta;
innerMeta = passThroughClassMeta.getInnerMeta();
this.propertyFinder = innerMeta != null ? innerMeta.newPropertyFinder() : null;
}
@SuppressWarnings("unchecked")
@Override
public void lookForProperties(
PropertyNameMatcher propertyNameMatcher,
Object[] properties, final FoundProperty matchingProperties,
PropertyMatchingScore score, boolean allowSelfReference, PropertyFinderTransformer propertyFinderTransformer, TypeAffinityScorer typeAffinityScorer, PropertyFilter propertyFilter, ShortCircuiter shortCircuiter) {
propertyFinderTransformer.apply(propertyFinder).lookForProperties(propertyNameMatcher, properties, new FoundProperty() {
@Override
public > void found(P propertyMeta, Runnable selectionCallback, PropertyMatchingScore score, TypeAffinityScorer typeAffinityScorer) {
matchingProperties.found(getSubPropertyMeta(propertyMeta), selectionCallback, score, typeAffinityScorer);
}
}, score, allowSelfReference, propertyFinderTransformer, typeAffinityScorer, propertyFilter, shortCircuiter);
}
@SuppressWarnings("unchecked")
private PropertyMeta getSubPropertyMeta(PropertyMeta property) {
return new SubPropertyMeta(
passThroughClassMeta.getReflectionService(),
(PropertyMeta) passThroughClassMeta.getProperty(),
(PropertyMeta)property);
}
@Override
public List getEligibleInstantiatorDefinitions() {
return passThroughClassMeta.getInstantiatorDefinitions();
}
@Override
public PropertyFinder> getSubPropertyFinder(PropertyMeta, ?> owner) {
if (owner.equals(passThroughClassMeta.getProperty())) {
return propertyFinder;
}
throw new IllegalArgumentException("Unexpected owner " + owner);
}
@Override
public PropertyFinder> getOrCreateSubPropertyFinder(SubPropertyMeta, ?, ?> subPropertyMeta) {
return getSubPropertyFinder(subPropertyMeta.getOwnerProperty());
}
@Override
public Type getOwnerType() {
return passThroughClassMeta.getType();
}
}