Getting untyped nodes

This is using Aspose Words for Java.

I am working on a table inside of a Word document. As part of the recommended path here I am getting a bookmark and then finding it’s Table ancestor. However, as part of that I am forced to cast the returned Node to a Table, even though I am calling the method that explicitly asks for a Table:

Bookmark tableBookmark = doc.getRange().getBookmarks().get("bookmarkName");
return (Table) tableBookmark.getBookmarkStart().getAncestor(Table.class);

This casting is not best practice, can affect type safety, and it also makes it more difficult to write Unit Tests, as my mocked objects fail when being cast.

It would be helpful if the getAncestor(Class ancestorType) method used Java’s type system to provide a Node of the correct type. So the signature would look something like

public <N extends CompositeNode> N getAncestor(Class<N> ancestorType);

and I could then omit the casting.

Thank you,

Dylan Gulick
Jama Software

@dgulick

We have logged this feature request as WORDSNET-19465 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.