Skip to content

Commit

Permalink
Stop using nulls for empty element content templates
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Nov 18, 2024
1 parent 0aa738c commit f177e51
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ng.appserver.elements;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -148,10 +147,10 @@ public List<NGElement> children() {
private static List<NGElement> childrenFromTemplate( final NGElement contentTemplate ) {

// Null represents an empty container tag (i.e. no children).
// FIXME: Eliminate this check. The rendering engine should be using an empty list
if( contentTemplate == null ) {
return Collections.emptyList();
}
// FIXME: Eliminate this check. The rendering engine should be using an empty list. Disabled on 2024-11-18 // Hugi
// if( contentTemplate == null ) {
// return Collections.emptyList();
// }

// If the contained template is another DynamicGroup, "unwrap it", i.e. just steal it's kids.
if( contentTemplate.getClass().equals( NGDynamicGroup.class ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class NGDynamicHTMLTag {
/**
* Children of this tag. This list contains a mix of (java) strings and PNodes
*/
private List<Object> _children;
private List<Object> _children = new ArrayList<>();

public NGDynamicHTMLTag() {
_parent = null;
Expand All @@ -50,30 +50,21 @@ public NGDynamicHTMLTag parent() {
*/
@Deprecated
public List<PNode> childrenWithStringsProcessedAndCombined() {

if( _children == null ) {
return null;
}

return combineAndWrapBareStrings( _children );
}

public void addChild( final Object stringOrElement ) {
Objects.requireNonNull( stringOrElement );

if( _children == null ) {
_children = new ArrayList<>();
}

_children.add( stringOrElement );
}

/**
* @return true if the given tag is the root of the element tree.
*
* FIXME:
* The implementation of this kind of sucks. The only tag in the tree without a declaration is currently the root tag
* We should probably introduce another specific marker for the root tage, or give it a different type. Just anything else than a null check, that's just a consequence of an implementation detail.
* The only tag in the tree without a declaration is currently assumed to be the root tag, which kind of sucks.
* We should probably introduce a specific marker for the root tag or give it a different type.
* Just anything else than checking for a null that's only the consequence of an implementation detail.
* // Hugi 2024-10-20
*/
public boolean isRoot() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ private static Map<String, NGAssociation> toAssociations( final Map<String, NGBi
*/
private static NGElement toTemplate( final List<PNode> nodes ) {

// FIXME: Shouldn't really ever be null. Still hesitant to replace it with an empty list though, since in my mind that represents an empty container tag. Food for thought... // Hugi 2024-11-15
if( nodes == null ) {
return null;
}

final List<NGElement> elements = new ArrayList<>();

for( final PNode pNode : nodes ) {
Expand Down

0 comments on commit f177e51

Please sign in to comment.