package com.cedricziel.idea.typo3.util;

import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FilesystemUtil {
    @Nullable
    public static PsiDirectory findParentExtensionDirectory(@NotNull PsiDirectory directory) {

        VirtualFile extensionRootFolder = findExtensionRootFolder(directory.getVirtualFile());
        if (extensionRootFolder == null) {
            return null;
        }

        PsiFile file = PsiManager.getInstance(directory.getProject()).findFile(extensionRootFolder);
        if (file == null || !file.isDirectory()) {
            return null;
        }

        return (PsiDirectory) file;
    }

    @Nullable
    public static VirtualFile findExtensionRootFolder(@NotNull VirtualFile file) {
        if (file.isDirectory()) {
            VirtualFile child = file.findChild("ext_emconf.php");

            if (child != null) {
                return file;
            }
        }

        // dragons ahead.
        if (file.getParent() != null) {
            return findExtensionRootFolder(file.getParent());
        }

        return null;
    }
}

@@ -121,41 +121,8 @@
 ry;%0A
-import com.intellij.psi.PsiFile;%0A
 impo
@@ -565,22 +565,14 @@
     
-PsiFile file =
+return
  Psi
@@ -619,20 +619,25 @@
 ()).find
-File
+Directory
 (extensi
@@ -655,131 +655,8 @@
 r);%0A
-        if (file == null %7C%7C !file.isDirectory()) %7B%0A            return null;%0A        %7D%0A%0A        return (PsiDirectory) file;%0A
     

Simplify return fo findExtensionRootDirectory