Skip to content

Commit

Permalink
HSEARCH-4708 Pass more context to PojoModelPathWalker
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Oct 19, 2022
1 parent cf56378 commit 2415b6b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 44 deletions.
Expand Up @@ -16,7 +16,7 @@
import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoImplicitReindexingResolver;
import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoImplicitReindexingResolverImpl;
import org.hibernate.search.mapper.pojo.automaticindexing.impl.PojoImplicitReindexingResolverNode;
import org.hibernate.search.mapper.pojo.extractor.mapping.programmatic.ContainerExtractorPath;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathPropertyNode;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathValueNode;
import org.hibernate.search.mapper.pojo.model.path.binding.impl.PojoModelPathWalker;
import org.hibernate.search.mapper.pojo.model.path.impl.BoundPojoModelPath;
Expand Down Expand Up @@ -134,28 +134,29 @@ private void checkNotFrozen() {
}

static class Walker implements PojoModelPathWalker<
AbstractPojoImplicitReindexingResolverTypeNodeBuilder<?, ?>,
Void, AbstractPojoImplicitReindexingResolverTypeNodeBuilder<?, ?>,
PojoImplicitReindexingResolverPropertyNodeBuilder<?, ?>,
PojoImplicitReindexingResolverValueNodeBuilderDelegate<?>
> {
public static final Walker INSTANCE = new Walker();

@Override
public PojoImplicitReindexingResolverPropertyNodeBuilder<?, ?> property(
AbstractPojoImplicitReindexingResolverTypeNodeBuilder<?, ?> typeNode, String propertyName) {
return typeNode.property( propertyName );
Void context, AbstractPojoImplicitReindexingResolverTypeNodeBuilder<?, ?> typeNode,
PojoModelPathPropertyNode pathNode) {
return typeNode.property( pathNode.propertyName() );
}

@Override
public PojoImplicitReindexingResolverValueNodeBuilderDelegate<?> value(
PojoImplicitReindexingResolverPropertyNodeBuilder<?, ?> propertyNode,
ContainerExtractorPath extractorPath) {
return propertyNode.value( extractorPath );
Void context, PojoImplicitReindexingResolverPropertyNodeBuilder<?, ?> propertyNode,
PojoModelPathValueNode pathNode) {
return propertyNode.value( pathNode.extractorPath() );
}

@Override
public AbstractPojoImplicitReindexingResolverTypeNodeBuilder<?, ?> type(
PojoImplicitReindexingResolverValueNodeBuilderDelegate<?> valueNode) {
Void context, PojoImplicitReindexingResolverValueNodeBuilderDelegate<?> valueNode) {
return valueNode.type();
}
}
Expand Down
Expand Up @@ -7,7 +7,8 @@
package org.hibernate.search.mapper.pojo.automaticindexing.building.impl;

import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate;
import org.hibernate.search.mapper.pojo.extractor.mapping.programmatic.ContainerExtractorPath;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathPropertyNode;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathValueNode;
import org.hibernate.search.mapper.pojo.model.path.binding.impl.PojoModelPathWalker;
import org.hibernate.search.util.common.data.impl.LinkedNode;

Expand Down Expand Up @@ -60,7 +61,7 @@ private ReindexOnUpdate getStrictestReindexOnUpdate(ReindexOnUpdate left, Reinde
abstract ReindexOnUpdate reindexOnUpdate();

static class Walker implements PojoModelPathWalker<
PojoIndexingDependencyCollectorTypeNode<?>,
Void, PojoIndexingDependencyCollectorTypeNode<?>,
PojoIndexingDependencyCollectorPropertyNode<?, ?>,
AbstractPojoIndexingDependencyCollectorDirectValueNode<?, ?>
> {
Expand All @@ -72,22 +73,24 @@ static class Walker implements PojoModelPathWalker<

@Override
public PojoIndexingDependencyCollectorPropertyNode<?, ?> property(
PojoIndexingDependencyCollectorTypeNode<?> typeNode, String propertyName) {
return typeNode.property( propertyName );
Void context, PojoIndexingDependencyCollectorTypeNode<?> typeNode,
PojoModelPathPropertyNode pathNode) {
return typeNode.property( pathNode.propertyName() );
}

@Override
public AbstractPojoIndexingDependencyCollectorDirectValueNode<?, ?> value(
PojoIndexingDependencyCollectorPropertyNode<?, ?> propertyNode,
ContainerExtractorPath extractorPath) {
AbstractPojoIndexingDependencyCollectorDirectValueNode<?, ?> node = propertyNode.value( extractorPath );
Void context, PojoIndexingDependencyCollectorPropertyNode<?, ?> propertyNode,
PojoModelPathValueNode pathNode) {
AbstractPojoIndexingDependencyCollectorDirectValueNode<?, ?> node =
propertyNode.value( pathNode.extractorPath() );
node.doCollectDependency( derivedDependencyPath );
return node;
}

@Override
public PojoIndexingDependencyCollectorTypeNode<?> type(
AbstractPojoIndexingDependencyCollectorDirectValueNode<?, ?> valueNode) {
Void context, AbstractPojoIndexingDependencyCollectorDirectValueNode<?, ?> valueNode) {
return valueNode.type();
}
}
Expand Down
Expand Up @@ -6,7 +6,6 @@
*/
package org.hibernate.search.mapper.pojo.model.path.binding.impl;

import org.hibernate.search.mapper.pojo.extractor.mapping.programmatic.ContainerExtractorPath;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathPropertyNode;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathValueNode;

Expand All @@ -16,29 +15,32 @@ private PojoModelPathBinder() {
// Only static methods
}

public static <T, P, V> V bind(T typeNode, PojoModelPathValueNode unboundModelPath, PojoModelPathWalker<T, P, V> walker) {
return applyPath( typeNode, unboundModelPath, walker );
public static <T, P, V> V bind(T rootNode, PojoModelPathValueNode unboundModelPath, PojoModelPathWalker<Void, T, P, V> walker) {
return bind( null, rootNode, unboundModelPath, walker );
}

private static <T, P, V> V applyPath(T rootNode, PojoModelPathValueNode unboundPathValueNode,
PojoModelPathWalker<T, P, V> walker) {
P propertyNode = applyPath( rootNode, unboundPathValueNode.parent(), walker );
ContainerExtractorPath extractorPath = unboundPathValueNode.extractorPath();
return walker.value( propertyNode, extractorPath );
public static <C, T, P, V> V bind(C context, T rootNode, PojoModelPathValueNode unboundModelPath,
PojoModelPathWalker<C, T, P, V> walker) {
return applyPath( context, rootNode, unboundModelPath, walker );
}

private static <T, P, V> P applyPath(T rootNode, PojoModelPathPropertyNode unboundPathPropertyNode,
PojoModelPathWalker<T, P, V> walker) {
private static <C, T, P, V> V applyPath(C context, T rootNode, PojoModelPathValueNode unboundPathValueNode,
PojoModelPathWalker<C, T, P, V> walker) {
P propertyNode = applyPath( context, rootNode, unboundPathValueNode.parent(), walker );
return walker.value( context, propertyNode, unboundPathValueNode );
}

private static <C, T, P, V> P applyPath(C context, T rootNode, PojoModelPathPropertyNode unboundPathPropertyNode,
PojoModelPathWalker<C, T, P, V> walker) {
PojoModelPathValueNode unboundPathParentNode = unboundPathPropertyNode.parent();
T typeNode;
if ( unboundPathParentNode != null ) {
V valueNode = applyPath( rootNode, unboundPathParentNode, walker );
typeNode = walker.type( valueNode );
V valueNode = applyPath( context, rootNode, unboundPathParentNode, walker );
typeNode = walker.type( context, valueNode );
}
else {
typeNode = rootNode;
}
String propertyName = unboundPathPropertyNode.propertyName();
return walker.property( typeNode, propertyName );
return walker.property( context, typeNode, unboundPathPropertyNode );
}
}
Expand Up @@ -6,14 +6,15 @@
*/
package org.hibernate.search.mapper.pojo.model.path.binding.impl;

import org.hibernate.search.mapper.pojo.extractor.mapping.programmatic.ContainerExtractorPath;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathPropertyNode;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathValueNode;

public interface PojoModelPathWalker<T, P, V> {
public interface PojoModelPathWalker<C, T, P, V> {

P property(T typeNode, String propertyName);
P property(C context, T typeNode, PojoModelPathPropertyNode pathNode);

V value(P propertyNode, ContainerExtractorPath extractorPath);
V value(C context, P propertyNode, PojoModelPathValueNode pathNode);

T type(V valueNode);
T type(C context, V valueNode);

}
Expand Up @@ -10,6 +10,8 @@
import org.hibernate.search.mapper.pojo.extractor.impl.BoundContainerExtractorPath;
import org.hibernate.search.mapper.pojo.extractor.impl.ContainerExtractorBinder;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPath;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathPropertyNode;
import org.hibernate.search.mapper.pojo.model.path.PojoModelPathValueNode;
import org.hibernate.search.mapper.pojo.model.path.binding.impl.PojoModelPathWalker;
import org.hibernate.search.mapper.pojo.model.spi.PojoTypeModel;

Expand Down Expand Up @@ -77,7 +79,7 @@ final void appendPath(PojoModelPath.Builder builder) {
}

public static class Walker implements PojoModelPathWalker<
BoundPojoModelPathTypeNode<?>,
Void, BoundPojoModelPathTypeNode<?>,
BoundPojoModelPathPropertyNode<?, ?>,
BoundPojoModelPathValueNode<?, ?, ?>
> {
Expand All @@ -89,23 +91,23 @@ private Walker(ContainerExtractorBinder containerExtractorBinder) {
}

@Override
public BoundPojoModelPathPropertyNode<?, ?> property(BoundPojoModelPathTypeNode<?> typeNode,
String propertyName) {
return typeNode.property( propertyName );
public BoundPojoModelPathPropertyNode<?, ?> property(Void context, BoundPojoModelPathTypeNode<?> typeNode,
PojoModelPathPropertyNode pathNode) {
return typeNode.property( pathNode.propertyName() );
}

@Override
public BoundPojoModelPathValueNode<?, ?, ?> value(BoundPojoModelPathPropertyNode<?, ?> propertyNode,
ContainerExtractorPath extractorPath) {
return doValue( propertyNode, extractorPath );
public BoundPojoModelPathValueNode<?, ?, ?> value(Void context, BoundPojoModelPathPropertyNode<?, ?> propertyNode,
PojoModelPathValueNode pathNode) {
return value( propertyNode, pathNode.extractorPath() );
}

@Override
public BoundPojoModelPathTypeNode<?> type(BoundPojoModelPathValueNode<?, ?, ?> valueNode) {
public BoundPojoModelPathTypeNode<?> type(Void context, BoundPojoModelPathValueNode<?, ?, ?> valueNode) {
return valueNode.type();
}

private <P> BoundPojoModelPathValueNode<?, P, ?> doValue(BoundPojoModelPathPropertyNode<?, P> propertyNode,
public <P> BoundPojoModelPathValueNode<?, P, ?> value(BoundPojoModelPathPropertyNode<?, P> propertyNode,
ContainerExtractorPath extractorPath) {
BoundContainerExtractorPath<P, ?> boundExtractorPath = containerExtractorBinder
.bindPath( propertyNode.getPropertyModel().typeModel(), extractorPath );
Expand Down

0 comments on commit 2415b6b

Please sign in to comment.