Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make NodeList NOT a Node. * Update branch and fix bad PR #527
- Loading branch information
Showing
15 changed files
with
443 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.github.javaparser; | ||
|
||
import com.github.javaparser.ast.Node; | ||
import com.github.javaparser.ast.NodeList; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* An object that has a parent node. | ||
*/ | ||
public interface HasParentNode<T> { | ||
// TODO nullable | ||
Node getParentNode(); | ||
|
||
T setParentNode(Node parentNode); | ||
|
||
/** | ||
* "this" for everything except NodeLists. NodeLists use their parent as their childrens parent. | ||
*/ | ||
Node getParentNodeForChildren(); | ||
|
||
@SuppressWarnings("unchecked") | ||
default <N> N getParentNodeOfType(Class<N> classType) { | ||
Node parent = getParentNode(); | ||
while (parent != null) { | ||
if (classType.isAssignableFrom(parent.getClass())) | ||
return (N) parent; | ||
parent = parent.getParentNode(); | ||
} | ||
return null; | ||
} | ||
|
||
// TODO should become protected once Java lets us | ||
default void setAsParentNodeOf(List<? extends Node> childNodes) { | ||
if (childNodes != null) { | ||
for (HasParentNode current : childNodes) { | ||
current.setParentNode(getParentNodeForChildren()); | ||
} | ||
} | ||
} | ||
|
||
// TODO should become protected once Java lets us | ||
default void setAsParentNodeOf(Node childNode) { | ||
if (childNode != null) { | ||
childNode.setParentNode(getParentNodeForChildren()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.