org.simpleflatmapper.reflect.meta.PassThroughPropertyFinder Maven / Gradle / Ivy
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;
public PassThroughPropertyFinder(PassThroughClassMeta passThroughClassMeta, boolean selfScoreFullName) {
super(selfScoreFullName);
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){
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);
}
@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();
}
}