public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(TokenSet filter, ArrayFactory<Psi> f) {
   T stub = myStub;
   if (stub != null) {
     //noinspection unchecked
     return (Psi[]) stub.getChildrenByType(filter, f);
   } else {
     final ASTNode[] nodes = getNode().getChildren(filter);
     Psi[] psiElements = f.create(nodes.length);
     for (int i = 0; i < nodes.length; i++) {
       psiElements[i] = (Psi) nodes[i].getPsi();
     }
     return psiElements;
   }
 }
 public <Stub extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(
     final IStubElementType<Stub, Psi> elementType, ArrayFactory<Psi> f) {
   T stub = myStub;
   if (stub != null) {
     //noinspection unchecked
     return (Psi[]) stub.getChildrenByType(elementType, f);
   } else {
     final ASTNode[] nodes = SharedImplUtil.getChildrenOfType(getNode(), elementType);
     Psi[] psiElements = f.create(nodes.length);
     for (int i = 0; i < nodes.length; i++) {
       psiElements[i] = (Psi) nodes[i].getPsi();
     }
     return psiElements;
   }
 }
 public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(TokenSet filter, Psi[] array) {
   T stub = myStub;
   if (stub != null) {
     //noinspection unchecked
     return (Psi[]) stub.getChildrenByType(filter, array);
   } else {
     final ASTNode[] nodes = getNode().getChildren(filter);
     Psi[] psiElements =
         (Psi[]) Array.newInstance(array.getClass().getComponentType(), nodes.length);
     for (int i = 0; i < nodes.length; i++) {
       psiElements[i] = (Psi) nodes[i].getPsi();
     }
     return psiElements;
   }
 }
 public <Stub extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(
     final IStubElementType<Stub, Psi> elementType, Psi[] array) {
   T stub = myStub;
   if (stub != null) {
     //noinspection unchecked
     return (Psi[]) stub.getChildrenByType(elementType, array);
   } else {
     final ASTNode[] nodes = SharedImplUtil.getChildrenOfType(getNode(), elementType);
     Psi[] psiElements =
         (Psi[]) Array.newInstance(array.getClass().getComponentType(), nodes.length);
     for (int i = 0; i < nodes.length; i++) {
       psiElements[i] = (Psi) nodes[i].getPsi();
     }
     return psiElements;
   }
 }