Java Code Examples for com.intellij.openapi.module.Module

The following examples show how to use com.intellij.openapi.module.Module. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: arma-intellij-plugin   Source File: ArmaPlugin.java    License: MIT License 6 votes vote down vote up
/**
 * @return the path to Arma IntelliJ Plugin's temp directory for the given module,
 * or null if the .iml directory couldn't be located
 */
@Nullable
public static String getPathToTempDirectory(@NotNull Module module) {
	final String tempFolder = "/armaplugin-temp";

	//find a place to save parse data
	VirtualFile imlVirtFile = module.getModuleFile();
	if (imlVirtFile == null) {
		String projectBasePath = module.getProject().getBasePath();
		if (projectBasePath == null) {
			return null;
		}
		return projectBasePath + tempFolder;
	}
	VirtualFile imlDir = imlVirtFile.getParent();
	if (imlDir == null) {
		return null;
	}
	return imlDir.getPath() + tempFolder;
}
 
Example 2
@NotNull
public Collection<PsiFileSystemItem> getRoots(@Nullable final Module module, ProtoPsiFileRoot psiFileRoot) {
    if (module == null) {
        return Collections.emptyList();
    }

    Set<PsiFileSystemItem> result = ContainerUtil.newLinkedHashSet();
    PsiManager psiManager = PsiManager.getInstance(module.getProject());

    for (SourceRootsProvider sourceRootsProvider : sourceRootsProviders) {
        VirtualFile[] sourceRoots = sourceRootsProvider.getSourceRoots(module, psiFileRoot);
        for (VirtualFile root : sourceRoots) {
            if (root != null) {
                final PsiDirectory directory = psiManager.findDirectory(root);
                if (directory != null) {
                    result.add(directory);
                }
            }
        }
    }
    return result;
}
 
Example 3
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (!FlutterUtils.isFlutteryFile(file)) return null;

  final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
  if (psiFile == null) return null;

  if (psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (module == null) return null;

  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final Version minimumVersion = DartPlugin.getInstance().getMinimumVersion();
  final Version dartVersion = DartPlugin.getInstance().getVersion();
  if (dartVersion.minor == 0 && dartVersion.bugfix == 0) {
    return null; // Running from sources.
  }
  return dartVersion.compareTo(minimumVersion) < 0 ? createUpdateDartPanel(myProject, module, dartVersion.toCompactString(),
                                                                           getPrintableRequiredDartVersion()) : null;
}
 
Example 4
/**
 * adds run configuration dynamically
 * @param module
 * @param mainClass
 * @param boardName
 */
public static void addProjectConfiguration(final Module module, final String mainClass, final String boardName) {
    final Runnable r = new Runnable() {
        @Override
        public void run() {
            final RunManager runManager = RunManager.getInstance(module.getProject());
            final RunnerAndConfigurationSettings settings = runManager.
                    createRunConfiguration(module.getName(), EmbeddedLinuxJVMConfigurationType.getInstance().getFactory());
            final EmbeddedLinuxJVMRunConfiguration configuration = (EmbeddedLinuxJVMRunConfiguration) settings.getConfiguration();

            configuration.setName(EmbeddedLinuxJVMBundle.message("runner.name", boardName));
            configuration.getRunnerParameters().setRunAsRoot(true);
            configuration.getRunnerParameters().setMainclass(mainClass);

            runManager.addConfiguration(settings, false);
            runManager.setSelectedConfiguration(settings);

            final Notification notification = new Notification(
                    Notifications.GROUPDISPLAY_ID,
                    EmbeddedLinuxJVMBundle.getString("pi.connection.required"), EmbeddedLinuxJVMBundle.message("pi.connection.notsetup", boardName),
                    NotificationType.INFORMATION);
            com.intellij.notification.Notifications.Bus.notify(notification);
        }
    };
    r.run();
}
 
Example 5
public DocCommentProcessor(PsiFile file) {
    this.file = file;
    if ( file == null ) {
        project = null;
        markdownOptions = null;
        psiElementFactory = null;
    }
    else {
        project = file.getProject();
        psiElementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
        ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        Module module = fileIndex.getModuleForFile(file.getVirtualFile());
        if ( module == null ) {
            markdownOptions = null;
        }
        else if ( !fileIndex.isInSourceContent(file.getVirtualFile()) ) {
            markdownOptions = null;
        }
        else if ( !Plugin.moduleConfiguration(module).isMarkdownEnabled() ) {
            markdownOptions = null;
        }
        else {
            markdownOptions = Plugin.moduleConfiguration(module).getRenderingOptions();
        }
    }
}
 
Example 6
static void runWhenNonModalIfModuleNotDisposed(@NotNull final Runnable runnable, @NotNull final Module module) {
    StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(new Runnable() {
        @Override
        public void run() {
            if (ApplicationManager.getApplication().getCurrentModalityState() == ModalityState.NON_MODAL) {
                runnable.run();
            } else {
                ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL, new Condition() {
                    @Override
                    public boolean value(final Object o) {
                        return module.isDisposed();
                    }
                });
            }
        }
    });
}
 
Example 7
Source Project: consulo   Source File: CompileContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean isGenerated(VirtualFile file) {
  if (myGeneratedSources.contains(FileBasedIndex.getFileId(file))) {
    return true;
  }
  if (isUnderRoots(myRootToModuleMap.keySet(), file)) {
    return true;
  }
  final Module module = getModuleByFile(file);
  if (module != null) {
    for (AdditionalOutputDirectoriesProvider provider : AdditionalOutputDirectoriesProvider.EP_NAME.getExtensionList()) {
      for (String path : provider.getOutputDirectories(getProject(), module)) {
        if (path != null && VfsUtilCore.isAncestor(new File(path), new File(file.getPath()), true)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
Example 8
Source Project: intellij-xquery   Source File: XQueryRunProfileState.java    License: Apache License 2.0 6 votes vote down vote up
private void configureConfiguration(SimpleJavaParameters parameters, XQueryRunConfiguration configuration) {
    ProgramParametersUtil.configureConfiguration(parameters, configuration);

    Project project = configuration.getProject();
    Module module = getModule(configuration);
    ;

    String alternativeJrePath = configuration.getAlternativeJrePath();
    if (alternativeJrePath != null) {
        configuration.setAlternativeJrePath(expandPath(alternativeJrePath, null, project));
    }

    String vmParameters = configuration.getVMParameters();
    if (vmParameters != null) {
        vmParameters = expandPath(vmParameters, module, project);

        for (Map.Entry<String, String> each : parameters.getEnv().entrySet()) {
            vmParameters = StringUtil.replace(vmParameters, "$" + each.getKey() + "$", each.getValue(), false);
        }
    }

    parameters.getVMParametersList().addParametersString(vmParameters);
}
 
Example 9
@Override
public void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context,
                    @NotNull CompletionResultSet resultSet, @NotNull String[] query) {
    PsiElement element = parameters.getPosition();
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    if (module == null) {
        return;
    }

    List<LookupElement> results = findResults(element, getQueryAtPosition(query));
    if (!results.isEmpty()) {
        resultSet
            .withRelevanceSorter(CompletionSorter.emptySorter())
            .addAllElements(results);
        resultSet.stopHere();
    }
}
 
Example 10
Source Project: consulo   Source File: ProjectViewImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void detachLibrary(@Nonnull final LibraryOrderEntry orderEntry, @Nonnull Project project) {
  final Module module = orderEntry.getOwnerModule();
  String message = IdeBundle.message("detach.library.from.module", orderEntry.getPresentableName(), module.getName());
  String title = IdeBundle.message("detach.library");
  int ret = Messages.showOkCancelDialog(project, message, title, Messages.getQuestionIcon());
  if (ret != Messages.OK) return;
  CommandProcessor.getInstance().executeCommand(module.getProject(), () -> {
    final Runnable action = () -> {
      ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
      OrderEntry[] orderEntries = rootManager.getOrderEntries();
      ModifiableRootModel model = rootManager.getModifiableModel();
      OrderEntry[] modifiableEntries = model.getOrderEntries();
      for (int i = 0; i < orderEntries.length; i++) {
        OrderEntry entry = orderEntries[i];
        if (entry instanceof LibraryOrderEntry && ((LibraryOrderEntry)entry).getLibrary() == orderEntry.getLibrary()) {
          model.removeOrderEntry(modifiableEntries[i]);
        }
      }
      model.commit();
    };
    ApplicationManager.getApplication().runWriteAction(action);
  }, title, null);
}
 
Example 11
@Nullable
public static Module findFlutterGradleModule(@NotNull Project project) {
  String moduleName = AndroidUtils.FLUTTER_MODULE_NAME;
  Module module = findModuleNamed(project, moduleName);
  if (module == null) {
    moduleName = flutterGradleModuleName(project);
    module = findModuleNamed(project, moduleName);
    if (module == null) {
      return null;
    }
  }
  VirtualFile file = locateModuleRoot(module);
  if (file == null) {
    return null;
  }
  file = file.getParent().getParent();
  VirtualFile meta = file.findChild(".metadata");
  if (meta == null) {
    return null;
  }
  VirtualFile android = getFlutterManagedAndroidDir(meta.getParent());
  if (android != null && android.getName().equals(".android")) {
    return module; // Only true for Flutter modules.
  }
  return null;
}
 
Example 12
Source Project: camel-idea-plugin   Source File: BeanUtils.java    License: Apache License 2.0 6 votes vote down vote up
private List<ReferenceableBeanId> findReferenceableIds(@NotNull Module module, Predicate<String> idCondition, boolean stopOnMatch) {
    List<ReferenceableBeanId> results = new ArrayList<>();
    IdeaUtils.getService().iterateXmlDocumentRoots(module, root -> {
        if (isPartOfBeanContainer(root)) {
            IdeaUtils.getService().iterateXmlNodes(root, XmlTag.class, tag -> Optional.of(tag)
                    .filter(this::isPartOfBeanContainer)
                    .map(contextTag -> findAttributeValue(contextTag, "id").orElse(null))
                    .filter(id -> idCondition.test(id.getValue()))
                    .map(id -> createReferenceableId(tag, id))
                    .map(ref -> {
                        results.add(ref);
                        return !stopOnMatch;
                    })
                    .orElse(true));
        }
    });
    return results;
}
 
Example 13
@Override
public boolean postProcess(Module module) {
  // TODO: Find a way to use GradleModuleBuilder instead of GradleProjectImportBuilder when adding a child module to the parent
  Project project = module.getProject();
  VirtualFile gradleFile = findFileUnderRootInModule(module, "build.gradle");
  if (gradleFile == null) { // not a gradle project
    return true;
  } else {
    ProjectDataManager projectDataManager = getService(ProjectDataManager.class);
    GradleProjectImportBuilder importBuilder = new GradleProjectImportBuilder(projectDataManager);
    GradleProjectImportProvider importProvider = new GradleProjectImportProvider(importBuilder);
    AddModuleWizard addModuleWizard =
        new AddModuleWizard(project, gradleFile.getPath(), importProvider);
    if (addModuleWizard.getStepCount() > 0 && !addModuleWizard
        .showAndGet()) { // user has cancelled import project prompt
      return true;
    } else { // user chose to import via the gradle import prompt
      importBuilder.commit(project, null, null);
      return false;
    }
  }
}
 
Example 14
Source Project: BashSupport   Source File: AddReplAction.java    License: Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    Module module = getModule(e);

    if (module != null) {
        try {
            Project project = module.getProject();
            VirtualFile baseDir = project.getBaseDir();

            if (baseDir != null) {
                consoleRunner = new BashConsoleRunner(project, baseDir.getPath());
                consoleRunner.initAndRun();
            }
        } catch (com.intellij.execution.ExecutionException ex) {
            log.warn("Error running bash repl", ex);
        }
    }
}
 
Example 15
Source Project: consulo   Source File: PackageNodeUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PsiPackage[] getSubpackages(@Nonnull PsiPackage aPackage,
                                              @Nullable Module module,
                                              @Nonnull Project project,
                                              final boolean searchInLibraries) {
  final PsiDirectory[] dirs = getDirectories(aPackage, project, module, searchInLibraries);
  final Set<PsiPackage> subpackages = new HashSet<PsiPackage>();
  for (PsiDirectory dir : dirs) {
    final PsiDirectory[] subdirectories = dir.getSubdirectories();
    for (PsiDirectory subdirectory : subdirectories) {
      final PsiPackage psiPackage = PsiPackageManager.getInstance(project).findAnyPackage(subdirectory);
      if (psiPackage != null) {
        final String name = psiPackage.getName();
        // skip "default" subpackages as they should be attributed to other modules
        // this is the case when contents of one module is nested into contents of another
        if (name != null && !name.isEmpty()) {
          subpackages.add(psiPackage);
        }
      }
    }
  }
  return subpackages.toArray(new PsiPackage[subpackages.size()]);
}
 
Example 16
Source Project: Intellij-Plugin   Source File: StepAnnotatorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldAnnotateInGaugeModule() throws Exception {
    SpecStepImpl element = mock(SpecStepImpl.class);
    Module module = mock(Module.class);

    when(helper.isGaugeModule(element)).thenReturn(true);
    when(element.getTextRange()).thenReturn(textRange);
    when(helper.getModule(element)).thenReturn(module);
    when(helper.isEmpty(element)).thenReturn(false);
    when(helper.isImplemented(element, module)).thenReturn(false);
    when(holder.createErrorAnnotation(textRange, "Undefined Step")).thenReturn(new Annotation(1, 1, new HighlightSeverity("dsf", 1), "", ""));

    new StepAnnotator(helper).annotate(element, holder);

    verify(holder, times(1)).createErrorAnnotation(textRange, "Undefined Step");
}
 
Example 17
Source Project: consulo   Source File: LogicalRootsManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private synchronized  Map<Module, MultiValuesMap<LogicalRootType, LogicalRoot>> getRoots(final ModuleManager moduleManager) {
  if (myRoots == null) {
    myRoots = new THashMap<Module, MultiValuesMap<LogicalRootType, LogicalRoot>>();

    final Module[] modules = moduleManager.getModules();
    for (Module module : modules) {
      final MultiValuesMap<LogicalRootType, LogicalRoot> map = new MultiValuesMap<LogicalRootType, LogicalRoot>();
      for (Map.Entry<LogicalRootType, Collection<NotNullFunction>> entry : myProviders.entrySet()) {
        final Collection<NotNullFunction> functions = entry.getValue();
        for (NotNullFunction function : functions) {
          map.putAll(entry.getKey(), (List<LogicalRoot>) function.fun(module));
        }
      }
      myRoots.put(module, map);
    }
  }

  return myRoots;
}
 
Example 18
Source Project: consulo   Source File: ModuleStructureConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
public AsyncResult<Void> selectOrderEntry(@Nonnull final Module module, @Nullable final OrderEntry orderEntry) {
  Place p = new Place();
  p.putPath(ProjectStructureConfigurable.CATEGORY, this);
  Runnable r = null;

  final MasterDetailsComponent.MyNode node = findModuleNode(module);
  if (node != null) {
    p.putPath(TREE_OBJECT, module);
    p.putPath(ModuleEditor.SELECTED_EDITOR_NAME, ClasspathEditor.NAME);
    r = new Runnable() {
      @Override
      public void run() {
        if (orderEntry != null) {
          ModuleEditor moduleEditor = ((ModuleConfigurable)node.getConfigurable()).getModuleEditor();
          ModuleConfigurationEditor editor = moduleEditor.getEditor(ClasspathEditor.NAME);
          if (editor instanceof ClasspathEditor) {
            ((ClasspathEditor)editor).selectOrderEntry(orderEntry);
          }
        }
      }
    };
  }
  final AsyncResult<Void> result = ProjectStructureConfigurable.getInstance(myProject).navigateTo(p, true);
  return r != null ? result.doWhenDone(r) : result;
}
 
Example 19
Source Project: consulo   Source File: DefaultNavBarExtension.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean processChildren(Module module, Processor<Object> processor) {
  final PsiManager psiManager = PsiManager.getInstance(module.getProject());
  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
  VirtualFile[] roots = moduleRootManager.getContentRoots();
  for (final VirtualFile root : roots) {
    final PsiDirectory psiDirectory = ApplicationManager.getApplication().runReadAction(new Computable<PsiDirectory>() {
      @Override
      public PsiDirectory compute() {
        return psiManager.findDirectory(root);
      }
    });
    if (psiDirectory != null) {
      if (!processor.process(psiDirectory)) return false;
    }
  }
  return true;
}
 
Example 20
Source Project: consulo   Source File: PsiPackageManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredReadAction
private PsiPackage findForModule(String packageName, Module module) {
  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  for (ModuleExtension<?> moduleExtension : rootManager.getExtensions()) {
    final PsiPackage aPackage = findPackage(packageName, moduleExtension.getClass());
    if (aPackage != null) {
      return aPackage;
    }
  }
  return null;
}
 
Example 21
Source Project: consulo   Source File: SourceScope.java    License: Apache License 2.0 5 votes vote down vote up
public static Map<Module, Collection<Module>> buildAllDependencies(final Project project) {
  Graph<Module> graph = ModuleManager.getInstance(project).moduleGraph();
  Map<Module, Collection<Module>> result = new HashMap<Module, Collection<Module>>();
  for (final Module module : graph.getNodes()) {
    buildDependenciesForModule(module, graph, result);
  }
  return result;
}
 
Example 22
Source Project: consulo   Source File: SameModuleWeigher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Comparable weigh(@Nonnull final PsiElement element, @Nonnull final ProximityLocation location) {
  final Module elementModule = ModuleUtil.findModuleForPsiElement(element);
  if (location.getPositionModule() == elementModule) {
    return 2;
  }

  if (elementModule != null) {
    return 1; // in project => still not bad
  }

  return 0;
}
 
Example 23
Source Project: consulo   Source File: ModuleCompileScope.java    License: Apache License 2.0 5 votes vote down vote up
private String[] getModuleContentUrls(final Module module) {
  String[] contentRootUrls = myContentUrlsCache.get(module);
  if (contentRootUrls == null) {
    contentRootUrls = ModuleRootManager.getInstance(module).getContentRootUrls();
    myContentUrlsCache.put(module, contentRootUrls);
  }
  return contentRootUrls;
}
 
Example 24
Source Project: consulo   Source File: ModulesConfigurator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Module getModule(String name) {
  final Module moduleByName = myModuleModel.findModuleByName(name);
  if (moduleByName != null) {
    return moduleByName;
  }
  return myModuleModel.getModuleToBeRenamed(name); //if module was renamed
}
 
Example 25
Source Project: consulo   Source File: CompilerEncodingService.java    License: Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
public static Charset getPreferredModuleEncoding(Chunk<Module> chunk) {
  CompilerEncodingService service = null;
  for (Module module : chunk.getNodes()) {
    if (service == null) {
      service = getInstance(module.getProject());
    }
    final Charset charset = service.getPreferredModuleEncoding(module);
    if (charset != null) {
      return charset;
    }
  }
  return null;
}
 
Example 26
Source Project: intellij-spring-assistant   Source File: MetadataSuggestionNode.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public String getNameForDocumentation(Module module) {
  return getSuggestionNodeType(module).representsArrayOrCollection() ?
      getOriginalName() + "[]" :
      getOriginalName();
}
 
Example 27
private void addJarFiles(Module module) {
    if (jarsToAdd == null) {
        return;
    }

    for (final File fileEntry : jarsToAdd) {
        if (!fileEntry.isDirectory() && Files.getFileExtension(fileEntry.getName()).contains("jar")) {
            PsiTestUtil.addLibrary(module, fileEntry.getName(), fileEntry.getParentFile().getPath(), fileEntry.getName());
        }
    }
}
 
Example 28
public void testHibernateOrmResteasy() throws Exception {
    Module module = createMavenModule("hibernate-orm-resteasy", new File("projects/maven/hibernate-orm-resteasy"));
    MicroProfileProjectInfo info = PropertiesManager.getInstance().getMicroProfileProjectInfo(module, MicroProfilePropertiesScope.SOURCES_AND_DEPENDENCIES, ClasspathKind.SRC, PsiUtilsImpl.getInstance(), DocumentFormat.PlainText);
    File f = MavenArtifactUtil.getArtifactFile(myProjectsManager.findProject(module).getLocalRepository(), new MavenId("io.quarkus:quarkus-hibernate-orm-deployment:0.19.1"), "jar");
    assertNotNull("Test existing of quarkus-hibernate-orm-deployment*.jar", f);
    assertProperties(info,

            // io.quarkus.hibernate.orm.deployment.HibernateOrmConfig
            p("quarkus-hibernate-orm", "quarkus.hibernate-orm.dialect", "java.util.Optional<java.lang.String>",
                    "The hibernate ORM dialect class name", true,
                    "io.quarkus.hibernate.orm.deployment.HibernateOrmConfig", "dialect", null,
                    CONFIG_PHASE_BUILD_TIME, null));
}
 
Example 29
public void testScalaRunnerAddressInvoked() {

    ApplicationManager.getApplication().runWriteAction(() -> {
      HashSet<String> address1 = Sets.newHashSet("x:x");
      HashSet<String> address2 = Sets.newHashSet("y:y");
      HashSet<String> address3 = Sets.newHashSet("z:z");
      Module module1 = createModuleWithSerializedAddresses("a", address1);
      Module module2 = createModuleWithSerializedAddresses("b", address2);
      Module module3 = createModuleWithSerializedAddresses("c", address3);

      // Make module1 depend on module2 and module3
      ModifiableRootModel model = ModuleRootManager.getInstance(module1).getModifiableModel();
      model.addModuleOrderEntry(module2);
      model.addModuleOrderEntry(module3);
      model.commit();

      assertTrue(ModuleManager.getInstance(myProject).isModuleDependent(module1, module2));
      assertTrue(ModuleManager.getInstance(myProject).isModuleDependent(module1, module3));

      // Make Scala run configuration for that module.
      ScalaTestRunConfiguration configuration =
        new ScalaTestRunConfiguration(
          myProject,
          new ScalaTestRunConfigurationFactory(new ScalaTestConfigurationType()),
          "dummy"
        );
      configuration.setModule(module1);

      // Make sure there is only one and the only address that gets passed to Pants.
      PantsMakeBeforeRun run = new PantsMakeBeforeRun(myProject);
      Set<String> addressesToCompile = run.getTargetAddressesToCompile(configuration);
      assertEquals(address1, addressesToCompile);
    });
  }
 
Example 30
Source Project: consulo   Source File: ProjectRootsUtil.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static ContentFolder findContentFolderForDirectory(@Nonnull ProjectFileIndex projectFileIndex, @Nonnull VirtualFile virtualFile) {
  final Module module = projectFileIndex.getModuleForFile(virtualFile);
  if (module == null) {
    return null;
  }

  ContentFolder contentFolder = projectFileIndex.getContentFolder(virtualFile);
  if (contentFolder == null) {
    return null;
  }
  return virtualFile.equals(contentFolder.getFile()) ? contentFolder : null;
}