public static @Nullable PsiFile findFile(PsiReference...references) {
    for (int i = references.length - 1; i >= 0; i--) {
      PsiReference ref = references[i];
      if (ref instanceof FileReferenceOwner && !(ref instanceof PsiFileReference)) {
        ref = ((FileReferenceOwner)ref).getLastFileReference();
      }
      if (ref instanceof PsiFileReference) {
        PsiElement file = references[i].resolve();
        if(file instanceof PsiFile ) return (PsiFile)file;
      }
    }
    return null;
  }
public static @Nullable PsiFile findFile(PsiReference...references)