Skip to content

Commit

Permalink
Add forceExpand for specific TypeDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
seongahjo committed Dec 21, 2024
1 parent b02f511 commit d1ee867
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,27 @@ public void forceExpand() {
this.expandedTypeDefinition = resolvedTypeDefinition;
}

@Override
public void forceExpand(TypeDefinition typeDefinition) {
List<TraverseNode> children;
if (this.getTreeProperty().isContainer()) {
children = this.expandContainerNode(
typeDefinition,
traverseContext.withParentProperties()
).collect(Collectors.toList());
} else {
children = this.generateChildrenNodes(
typeDefinition.getResolvedProperty(),
typeDefinition.getPropertyGenerator()
.generateChildProperties(typeDefinition.getResolvedProperty()),
this.nullInject,
traverseContext.withParentProperties()
);
}
this.children = children;
this.expandedTypeDefinition = typeDefinition;
}

@Override
public TraverseNodeMetadata getMetadata() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ public interface TraverseNode {
*/
void forceExpand();

/**
* expands the {@link TraverseNode} forcibly. In result, it always generates the child {@link TraverseNode}s.
* It generates the child {@link TraverseNode}s by given {@link TypeDefinition}.
* {@code Force} means that it expands as if it were a root node, even if it is not.
* Unlike {@link #expand()}, it expands without metadata generated on expanding of the parent {@link TraverseNode}.
* <p>
* It will always append the {@link TraverseNode} nodes,
* not remove already created nodes unless it is not a container.
* The container's element nodes will shrink when the node is set by the fixed container object.
* <p>
* The leaf {@link TraverseNode} may generate child {@link TraverseNode}s.
* For example, the {@link TraverseNode} with a self-reference.
*
* @param typeDefinition the {@link TypeDefinition} to expand forcibly
*/
void forceExpand(TypeDefinition typeDefinition);

/**
* retrieves the metadata to traverse the tree. Some of its properties can be mutated during traversal.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void forceExpand() {
);
}

@Override
public void forceExpand(TypeDefinition typeDefinition) {
this.traverseNode.forceExpand(typeDefinition);
this.setChildren(
nullSafe(this.traverseNode.getChildren()).asList().stream()
.map(it -> new ObjectNode(it, generateFixtureContext.newChildNodeContext()))
.collect(Collectors.toList())
);
}

@Override
public TraverseNodeMetadata getMetadata() {
return traverseNode.getMetadata();
Expand Down

0 comments on commit d1ee867

Please sign in to comment.