NestedClassSelector (String line, int nestedClassIdx) { String enclosingClass = line.substring(0, nestedClassIdx); String nestedClassName = line.substring(nestedClassIdx + 1); DiscoverySelector enclosingClassSelector = createClassSelector(enclosingClass); Class<?> klass = enclosingClassSelector instanceof NestedClassSelector ? ((NestedClassSelector)enclosingClassSelector).getNestedClass() : ((ClassSelector)enclosingClassSelector).getJavaClass(); Class<?> superclass = klass.getSuperclass(); while (superclass != null) { for (Class<?> nested : superclass.getDeclaredClasses()) { if (nested.getSimpleName().equals(nestedClassName)) { List<Class<?>> enclosingClasses; if (enclosingClassSelector instanceof NestedClassSelector) { enclosingClasses = new ArrayList<>(((NestedClassSelector)enclosingClassSelector).getEnclosingClasses()); enclosingClasses.add(klass); } else { enclosingClasses = Collections.singletonList(klass); } return DiscoverySelectors.selectNestedClass(enclosingClasses, nested); } } superclass = superclass.getSuperclass(); } return null; }