Skip to content

Replacing consulo.ide.impl.idea.openapi.module.ModuleUtil with consulo.language.util.ModuleUtilCore#295

Merged
VISTALL merged 1 commit intoconsulo:masterfrom
unv-unv:eliminating-module-util
Apr 19, 2026
Merged

Replacing consulo.ide.impl.idea.openapi.module.ModuleUtil with consulo.language.util.ModuleUtilCore#295
VISTALL merged 1 commit intoconsulo:masterfrom
unv-unv:eliminating-module-util

Conversation

@unv-unv
Copy link
Copy Markdown
Contributor

@unv-unv unv-unv commented Apr 19, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes remaining usages of the legacy consulo.ide.impl.idea.openapi.module.ModuleUtil and migrates callers to consulo.language.util.ModuleUtilCore or PsiElement#getModule(), aligning module-resolution logic with the newer Consulo APIs.

Changes:

  • Replace ModuleUtil.findModuleForFile(...) with ModuleUtilCore.findModuleForFile(...) in UI + tests.
  • Replace ModuleUtil.findModuleForPsiElement(...) with PsiElement#getModule() in inspections/refactoring/reference providers.
  • Add @RequiredReadAction annotations in a few PSI-touching code paths.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
plugin/src/test/java_/com/intellij/psi/impl/cache/impl/SCR20733Test.java Update module lookup assertions to use ModuleUtilCore.findModuleForFile.
plugin/src/main/java/com/intellij/java/impl/util/xml/ui/PsiClassControl.java Switch fragment module user-data key to ModuleUtilCore.KEY_MODULE.
plugin/src/main/java/com/intellij/java/impl/refactoring/move/moveClassesOrPackages/DestinationFolderComboBox.java Use ModuleUtilCore.findModuleForFile when rendering module names for destination roots.
plugin/src/main/java/com/intellij/java/impl/refactoring/introduceparameterobject/IntroduceParameterObjectProcessor.java Replace module lookup with PsiFile#getModule() in class-generation logic.
plugin/src/main/java/com/intellij/java/impl/psi/impl/source/resolve/reference/impl/providers/FilePathReferenceProvider.java Use PsiElement#getModule() for default context root computation.
plugin/src/main/java/com/intellij/java/impl/psi/impl/file/PsiPackageImplementationHelperImpl.java Use PsiFile#getModule() and add @RequiredReadAction to directory suggestion helper.
plugin/src/main/java/com/intellij/java/impl/ig/junit/UseOfObsoleteAssertInspection.java Replace module lookup with expression.getModule() and simplify static-method check.
plugin/src/main/java/com/intellij/java/impl/codeInspection/unnecessaryModuleDependency/UnnecessaryModuleDependencyAnnotator.java Replace module lookup with PsiElement#getModule() and add @RequiredReadAction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +76 to 77
@RequiredReadAction
private static PsiDirectory[] suggestMostAppropriateDirectories(PsiJavaPackage psiPackage) {
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestMostAppropriateDirectories() is now annotated @RequiredReadAction, but its immediate caller in this class (navigate()’s ToolWindow.activate callback) isn’t obviously under a read lock. To avoid read-access violations when touching PSI here, wrap the call in ReadAction.compute/run (or drop the annotation if it’s guaranteed to be called under a read action).

Copilot uses AI. Check for mistakes.
else {
Module module = ModuleUtil.findModuleForPsiElement(containingFile);
Module module = containingFile.getModule();
directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, containingDirectory, true, true);
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

containingFile.getModule() can be null (other call sites in the refactoring codebase typically assert module != null before using it). Passing a null module into PackageUtil.findOrCreateDirectoryForPackage(...) will NPE (module.getProject() inside). Consider asserting non-null (if guaranteed in this refactoring) or handling the null case explicitly before calling PackageUtil.

Suggested change
directory = PackageUtil.findOrCreateDirectoryForPackage(module, packageName, containingDirectory, true, true);
directory = module != null ? PackageUtil.findOrCreateDirectoryForPackage(module, packageName, containingDirectory, true, true) : null;

Copilot uses AI. Check for mistakes.
@VISTALL VISTALL merged commit 08b8176 into consulo:master Apr 19, 2026
5 checks passed
@unv-unv unv-unv deleted the eliminating-module-util branch April 19, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants