// Path: src/org/idea/processing/plugin/project_creation/RunnableActionUtils.java
// public class RunnableActionUtils {
//     public static void runWhenInitialized(final Project project, final Runnable r) {
//         if (project.isDisposed()) return;
// 
//         if (isNoBackgroundMode()) {
//             r.run();
//             return;
//         }
// 
//         if (!project.isInitialized()) {
//             StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project));
//             return;
//         }
// 
//         runDumbAware(project, r);
//     }
// 
//     public static void runDumbAware(final Project project, final Runnable r) {
//         if (DumbService.isDumbAware(r)) {
//             r.run();
//         }
//         else {
//             DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(r, project));
//         }
//     }
// 
//     public static boolean isNoBackgroundMode() {
//         return (ApplicationManager.getApplication().isUnitTestMode()
//                 || ApplicationManager.getApplication().isHeadlessEnvironment());
//     }
// 
// }


import java.util.*;
import com.intellij.ide.util.PackageUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.idea.processing.plugin.project_creation.RunnableActionUtils;
            ImportDialogs.NO_MAIN_SKETCH_CLASS.getDialog().show();
        }*/

        PsiFile selectedMainSketchFile;
        PsiClass selectedMainSketchClass;
        PsiImportList correspondingImportList;

        // At this point, a short-list of potential main classes has been established. Select one for the purposes of import.
        Iterator<Map.Entry<Pair<PsiFile, PsiClass>, PsiImportList>> classesIterator = mainSketchClasses.entrySet().iterator();

        Map.Entry<Pair<PsiFile, PsiClass>, PsiImportList> entry = classesIterator.next();

        selectedMainSketchFile = entry.getKey().getFirst();
        selectedMainSketchClass = entry.getKey().getSecond();
        correspondingImportList = entry.getValue();

        if (selectedMainSketchFile == null || selectedMainSketchClass == null || correspondingImportList == null) {
            throw new IllegalStateException("The selected main sketch class is null, or the corresponding import list to the class is null.");
        }

        PsiFile postProcessedMainSketchFile = MigrationActions.postProcessSelectedMainSketchClass(project, selectedMainSketchClass, correspondingImportList);

        importableSketchFiles.remove(selectedMainSketchFile);
        importableSketchFiles.add(postProcessedMainSketchFile);

        // Write all of the imported sketch files to disk.
        final VirtualFile sketchResourcesRoot = importBuilder.getParameters().resourceDirectoryPath;

        logger.info("Preparing to import sketch resources from '" + sketchResourcesRoot + "'.");

// Path: src/org/idea/processing/plugin/project_creation/RunnableActionUtils.java
// public class RunnableActionUtils {
//     public static void runWhenInitialized(final Project project, final Runnable r) {
//         if (project.isDisposed()) return;
// 
//         if (isNoBackgroundMode()) {
//             r.run();
//             return;
//         }
// 
//         if (!project.isInitialized()) {
//             StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project));
//             return;
//         }
// 
//         runDumbAware(project, r);
//     }
// 
//     public static void runDumbAware(final Project project, final Runnable r) {
//         if (DumbService.isDumbAware(r)) {
//             r.run();
//         }
//         else {
//             DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(r, project));
//         }
//     }
// 
//     public static boolean isNoBackgroundMode() {
//         return (ApplicationManager.getApplication().isUnitTestMode()
//                 || ApplicationManager.getApplication().isHeadlessEnvironment());
//     }
// 
// }


// Path: src/org/idea/processing/plugin/pde_import/ImportSketchClasses.java
import java.util.*;
import com.intellij.ide.util.PackageUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.idea.processing.plugin.project_creation.RunnableActionUtils;

            ImportDialogs.NO_MAIN_SKETCH_CLASS.getDialog().show();
        }*/

        PsiFile selectedMainSketchFile;
        PsiClass selectedMainSketchClass;
        PsiImportList correspondingImportList;

        // At this point, a short-list of potential main classes has been established. Select one for the purposes of import.
        Iterator<Map.Entry<Pair<PsiFile, PsiClass>, PsiImportList>> classesIterator = mainSketchClasses.entrySet().iterator();

        Map.Entry<Pair<PsiFile, PsiClass>, PsiImportList> entry = classesIterator.next();

        selectedMainSketchFile = entry.getKey().getFirst();
        selectedMainSketchClass = entry.getKey().getSecond();
        correspondingImportList = entry.getValue();

        if (selectedMainSketchFile == null || selectedMainSketchClass == null || correspondingImportList == null) {
            throw new IllegalStateException("The selected main sketch class is null, or the corresponding import list to the class is null.");
        }

        PsiFile postProcessedMainSketchFile = MigrationActions.postProcessSelectedMainSketchClass(project, selectedMainSketchClass, correspondingImportList);

        importableSketchFiles.remove(selectedMainSketchFile);
        importableSketchFiles.add(postProcessedMainSketchFile);

        // Write all of the imported sketch files to disk.
        final VirtualFile sketchResourcesRoot = importBuilder.getParameters().resourceDirectoryPath;

        logger.info("Preparing to import sketch resources from '" + sketchResourcesRoot + "'.");

        RunnableActionUtils.runWhenInitialized(project, () -> {