Skip to content

Commit

Permalink
Loosen bound contract of PathNode.getParentOfType
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Mar 15, 2024
1 parent 5246f53 commit f5100ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public interface PathNode<V> extends Comparable<PathNode<?>> {
*/
@Nullable
@SuppressWarnings("unchecked")
default <T, I extends PathNode<T>> I getParentOfType(@Nonnull Class<T> type) {
default <T, I extends PathNode<? extends T>> I getParentOfType(@Nonnull Class<T> type) {
if (type.isAssignableFrom(getValueType()))
return (I) this;
PathNode<?> parent = getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static void setup() throws IOException {
class Value {
@Test
void getValueOfTypeForParentTypes() {
// We should be able to get the current value by any of its interfaces.
ClassInfo v1 = p1.getValueOfType(ClassInfo.class);
Accessed v2 = p1.getValueOfType(Accessed.class);
Annotated v3 = p1.getValueOfType(Annotated.class);
Expand All @@ -105,23 +106,12 @@ void getValueOfTypeForParentTypes() {
}

@Test
void getValueOfTypeForParentTypes2() {
// Same test as the prior
void getParentOfTypeForParentTypes() {
// Same test as the prior, but it gets the PathNode<T> and coming from a child path node.
ClassMemberPathNode memberPath = p1.child(primaryClassInfo.getMethods().get(0));

ClassPathNode v1 = memberPath.getParentOfType(ClassInfo.class); // intended
Accessed v2 = memberPath.getParentOfType(ClassInfo.class); // intended
CharSequence v3 = memberPath.getParentOfType(ClassInfo.class); // runtime error








// String v2 = memberPath.getParentOfType(Accessed.class);
// Annotated v3 = memberPath.getParentOfType(Annotated.class);
ClassPathNode v1 = memberPath.getParentOfType(ClassInfo.class);
ClassPathNode v2 = memberPath.getParentOfType(Accessed.class);
ClassPathNode v3 = memberPath.getParentOfType(Annotated.class);
assertSame(v1, v2);
assertSame(v2, v3);
}
Expand Down

0 comments on commit f5100ea

Please sign in to comment.