Skip to content

Commit

Permalink
[Java] Fix lookup of types ancestor for PR #904.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Sep 28, 2022
1 parent a52aef5 commit ff5158e
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,26 @@ public static String getAttributeValue(final Node elementNode, final String attr
}

/**
* To be used with child elements of {@code <types>} elements. Returns the package attribute as
* defined on the parent {@code <types>} element
* To be used with descendant elements of {@code <types>} elements. Returns the package attribute value as
* defined on the ancestor {@code <types>} element.
*
* @param elementNode the node inside the types element
* @return the package name, or null if not defined
* @param elementNode the node inside the {@code <types>} element.
* @return the package name, or null if not defined.
*/
public static String getTypesPackageAttribute(final Node elementNode)
{
return getAttributeValue(elementNode.getParentNode(), "package", null);
Node parentNode = elementNode.getParentNode();
while (null != parentNode)
{
if ("types".equals(parentNode.getLocalName()) || "types".equals(parentNode.getNodeName()))
{
return getAttributeValue(parentNode, "package", null);
}

parentNode = parentNode.getParentNode();
}

return null;
}

/**
Expand Down

0 comments on commit ff5158e

Please sign in to comment.