Skip to content

Commit e9ca20a

Browse files
committed
#30 - Methods to walk supers
1 parent 1ae1a41 commit e9ca20a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main/java/org/hibernate/models/spi/ClassDetails.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,31 @@ default Kind getKind() {
9797
*/
9898
List<TypeVariableDetails> getTypeParameters();
9999

100+
@FunctionalInterface
101+
interface ClassDetailsConsumer extends java.util.function.Consumer<ClassDetails> {
102+
@Override
103+
void accept(ClassDetails classDetails);
104+
}
105+
106+
/**
107+
* Walk our super-classes passing each to the {@code consumer}
108+
*/
109+
default void forEachSuper(ClassDetailsConsumer consumer) {
110+
ClassDetails check = getSuperClass();
111+
while ( check != null && check != OBJECT_CLASS_DETAILS ) {
112+
consumer.accept( check );
113+
check = check.getSuperClass();
114+
}
115+
}
116+
117+
/**
118+
* Pass ourselves into the {@code consumer} and then the same {@linkplain #forEachSuper for each super class}
119+
*/
120+
default void forSelfAndEachSuper(ClassDetailsConsumer consumer) {
121+
consumer.accept( this );
122+
forEachSuper( consumer );
123+
}
124+
100125
@Override
101126
default TypeDetails resolveTypeVariable(String identifier) {
102127
final TypeVariableDetails local = TypeDetailsHelper.findTypeVariableDetails(

0 commit comments

Comments
 (0)