@NotNull
  public List<? extends LocalQuickFix> registerFixes(final FileReference reference) {
    final PsiElement element = reference.getElement();
    if (!(reference instanceof JSFlexFileReference)
        || !(element instanceof JSAttributeNameValuePair)) return Collections.emptyList();

    final PsiElement parent = element.getParent();
    if (!(parent instanceof JSAttribute)
        || !FlexAnnotationNames.EMBED.equals(((JSAttribute) parent).getName())) {
      return Collections.emptyList();
    }

    final String value = ((JSAttributeNameValuePair) element).getSimpleValue();
    if (value.startsWith("/")) return Collections.emptyList();

    final Module module = ModuleUtil.findModuleForPsiElement(element);
    if (module == null) return Collections.emptyList();

    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    final boolean testSourceRoot =
        virtualFile != null && rootManager.getFileIndex().isInTestSourceContent(virtualFile);

    for (VirtualFile sourceRoot : rootManager.getSourceRoots(testSourceRoot)) {
      if (sourceRoot.findFileByRelativePath(value) != null) {
        return Collections.singletonList(
            new AddLeadingSlashFix((JSAttributeNameValuePair) element));
      }
    }

    return Collections.emptyList();
  }
  public static void createSourceRootIfNotExist(
      @NotNull final String path, @NotNull final Module module) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    final File rootFile = new File(path);
    final boolean created;
    if (!rootFile.exists()) {
      if (!rootFile.mkdirs()) return;
      created = true;
    } else {
      created = false;
    }

    final Project project = module.getProject();
    Module genModule = module;

    final AndroidFacet facet = AndroidFacet.getInstance(genModule);

    if (facet != null && facet.getConfiguration().LIBRARY_PROJECT) {
      removeGenModule(module);
    }

    if (project.isDisposed() || genModule.isDisposed()) {
      return;
    }

    final VirtualFile root;
    if (created) {
      root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(rootFile);
    } else {
      root = LocalFileSystem.getInstance().findFileByIoFile(rootFile);
    }
    if (root != null) {
      final ModuleRootManager manager = ModuleRootManager.getInstance(genModule);
      unexcludeRootIfNeccessary(root, manager);
      for (VirtualFile existingRoot : manager.getSourceRoots()) {
        if (existingRoot == root) return;
      }
      ApplicationManager.getApplication()
          .runWriteAction(
              new Runnable() {
                public void run() {
                  addSourceRoot(manager, root);
                }
              });
    }
  }
  @Override
  public void moduleCreated(@NotNull final Module module) {

    ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    final VirtualFile sourceRoots[] = moduleRootManager.getSourceRoots();
    final String projectName = module.getProject().getName();

    if (sourceRoots.length != 1) {
      return;
    }

    final PsiDirectory directory =
        PsiManager.getInstance(module.getProject()).findDirectory(sourceRoots[0]);

    if (directory == null || directory.getParentDirectory() == null) {
      return;
    }

    final PsiDirectory baseDir = directory.getParentDirectory();

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              @Override
              public void run() {
                try {
                  baseDir.createSubdirectory("bin");
                  baseDir.createSubdirectory("pkg");

                  // Create package folder under src and add main.go
                  PsiDirectory mainPackage = directory.createSubdirectory("main");
                  mainPackage.checkCreateFile(projectName.concat(".go"));
                  GoTemplatesFactory.createFromTemplate(
                      mainPackage,
                      "main",
                      projectName.concat(".go"),
                      GoTemplatesFactory.Template.GoAppMain);
                } catch (IncorrectOperationException ignored) {
                } catch (Exception e) {
                  LOG.error(e.getMessage());
                }
              }
            });
  }
 protected PsiDirectory[] getSelectedDirectoriesInAmbiguousCase(
     @NotNull final DefaultMutableTreeNode node) {
   final Object userObject = node.getUserObject();
   if (userObject instanceof AbstractModuleNode) {
     final Module module = ((AbstractModuleNode) userObject).getValue();
     if (module != null) {
       final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
       final VirtualFile[] sourceRoots = moduleRootManager.getSourceRoots();
       List<PsiDirectory> dirs = new ArrayList<PsiDirectory>(sourceRoots.length);
       final PsiManager psiManager = PsiManager.getInstance(myProject);
       for (final VirtualFile sourceRoot : sourceRoots) {
         final PsiDirectory directory = psiManager.findDirectory(sourceRoot);
         if (directory != null) {
           dirs.add(directory);
         }
       }
       return dirs.toArray(new PsiDirectory[dirs.size()]);
     }
   }
   return PsiDirectory.EMPTY_ARRAY;
 }