private <T extends StubBasedPsiElement<? extends StubElement<T>>> T @NotNull [] getClassChildren(@NotNull TokenSet elementTypes,
                                                                                                   @NotNull Class<T> childrenClass,
                                                                                                   @NotNull ArrayFactory<? extends T> factory) {
    final List<T> result = new ArrayList<>();
    processClassLevelDeclarations(new PsiScopeProcessor() {
      @Override
      public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
        if (childrenClass.isInstance(element) && elementTypes.contains(((StubBasedPsiElement<?>)element).getElementType())) {
          result.add(childrenClass.cast(element));
        }
        return true;
      }
    });
    return ContainerUtil.toArray(result, factory);
  }
private <T extends StubBasedPsiElement<? extends StubElement<T>>> T @NotNull [] getClassChildren(@NotNull TokenSet elementTypes,
                                                                                                   @NotNull Class<T> childrenClass,
                                                                                                   @NotNull ArrayFactory<? extends T> factory)