[java] remove UI for configuring groups of modules loaded together in 'Suspicious package-private access' inspection (IDEA-200047, IJPL-149126)

We got rid of such exceptions in intellij monorepo (see IJPL-149126), and it's better to remove the ability to add them back. Given that the inspection is currently visible in internal mode only, it shouldn't affect users. Moreover, since the usability of UI was questionable, after removing it we can make the inspection non-internal.

The option itself and code which reads its configuration are kept to avoid red code in older branches of the monorepo where the problems in code aren't fixed.

GitOrigin-RevId: 2bf42ade9ec35de6571a1d42889569790d0655b5
This commit is contained in:
Nikolay Chashnikov
2025-05-02 08:05:38 +00:00
committed by intellij-monorepo-bot
parent 49e5d644aa
commit aaa77e18b7
2 changed files with 8 additions and 80 deletions
@@ -1466,8 +1466,6 @@ package.with.too.few.classes.display.name=Package with too few classes
package.with.too.few.classes.problem.descriptor=Package ''{0}'' contains too few classes ({1} < {2})
package.with.too.few.classes.min.option=Minimum number of classes:
suspicious.package.private.access.display.name=Suspicious package-private access
groups.of.modules.loaded.together.label=Groups of modules that are loaded together:
groups.of.modules.loaded.together.description=Each line specifies a comma-separated list of module names which are known to be loaded by the same classloader.\nAccess to package-private members between such modules shouldn't be reported.
module.with.too.many.classes.display.name=Module with too many classes
module.with.too.many.classes.problem.descriptor=Module ''{0}'' contains too many classes ({1} > {2})
module.with.too.many.classes.max.option=Maximum number of classes:
@@ -2437,8 +2435,6 @@ logger.initialized.with.foreign.class.fix.family.name=Replace foreign class
extend.exception.fix.family.name=Make class extend 'Exception'
inspection.use.of.private.field.inner.classes.option=Ignore accesses from inner classes
refused.bequest.fix.family.name=Insert call to super method
mark.modules.as.loaded.together.fix.family.name=Mark modules as loaded together
mark.modules.as.loaded.together.fix.text=Mark ''{0}'' and ''{1}'' modules as loaded together
inspection.suspicious.package.private.access.description={0} is {1}, but declared in a different module ''{2}''
replace.case.default.with.default=Replace 'case default' with 'default'
replace.case.default.null.with.null.default=Replace 'case default, null' with 'case null, default'
@@ -2,19 +2,18 @@
package com.siyeh.ig.dependency;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.AbstractBaseUastLocalInspectionTool;
import com.intellij.codeInspection.IntentionWrapper;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.codeInspection.apiUsage.ApiUsageProcessor;
import com.intellij.codeInspection.apiUsage.ApiUsageUastVisitor;
import com.intellij.codeInspection.options.OptPane;
import com.intellij.codeInspection.options.OptionController;
import com.intellij.lang.jvm.JvmModifier;
import com.intellij.lang.jvm.actions.JvmElementActionFactories;
import com.intellij.lang.jvm.actions.MemberRequestsKt;
import com.intellij.modcommand.ModCommand;
import com.intellij.modcommand.ModCommandQuickFix;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -22,7 +21,6 @@ import com.intellij.psi.*;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.util.RefactoringUIUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ObjectUtils;
import com.intellij.util.concurrency.SynchronizedClearableLazy;
import com.intellij.util.containers.ContainerUtil;
@@ -33,7 +31,6 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.psiutils.ClassUtils;
import one.util.streamex.StreamEx;
import org.jdom.Element;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
@@ -41,8 +38,6 @@ import org.jetbrains.uast.*;
import java.util.*;
import static com.intellij.codeInspection.options.OptPane.pane;
public final class SuspiciousPackagePrivateAccessInspection extends AbstractBaseUastLocalInspectionTool {
@XCollection
public List<ModulesSet> MODULES_SETS_LOADED_TOGETHER = new ArrayList<>();
@@ -68,7 +63,7 @@ public final class SuspiciousPackagePrivateAccessInspection extends AbstractBase
);
}
private final class SuspiciousApiUsageProcessor implements ApiUsageProcessor {
private static final class SuspiciousApiUsageProcessor implements ApiUsageProcessor {
private final ProblemsHolder myProblemsHolder;
private final Map<String, ModulesSet> myModuleNameToModulesSet;
@@ -148,11 +143,8 @@ public final class SuspiciousPackagePrivateAccessInspection extends AbstractBase
StringUtil.removeHtmlTags(StringUtil.capitalize(RefactoringUIUtil.getDescription(targetElement, true)));
LocalQuickFix[] quickFixes =
IntentionWrapper.wrapToQuickFixes(fixes.toArray(IntentionAction.EMPTY_ARRAY), targetElement.getContainingFile());
myProblemsHolder.registerProblem(sourcePsi, InspectionGadgetsBundle
.message("inspection.suspicious.package.private.access.description", elementDescription, accessType, targetModule.getName()),
ArrayUtil.append(quickFixes,
new MarkModulesAsLoadedTogetherFix(sourceModule.getName(),
targetModule.getName())));
myProblemsHolder.registerProblem(sourcePsi, InspectionGadgetsBundle.message("inspection.suspicious.package.private.access.description", elementDescription, accessType, targetModule.getName()),
quickFixes);
}
}
}
@@ -174,10 +166,7 @@ public final class SuspiciousPackagePrivateAccessInspection extends AbstractBase
IntentionWrapper.wrapToQuickFixes(fixes.toArray(IntentionAction.EMPTY_ARRAY), targetElement.getContainingFile());
String problem = InspectionGadgetsBundle
.message("inspection.suspicious.package.private.access.problem", elementDescription, classDescription, targetModule.getName());
myProblemsHolder.registerProblem(nameIdentifier, problem,
ArrayUtil.append(quickFixes,
new MarkModulesAsLoadedTogetherFix(sourceModule.getName(),
targetModule.getName())));
myProblemsHolder.registerProblem(nameIdentifier, problem, quickFixes);
}
}
}
@@ -255,14 +244,6 @@ public final class SuspiciousPackagePrivateAccessInspection extends AbstractBase
public Set<String> modules = new LinkedHashSet<>();
}
@Override
public @NotNull OptPane getOptionsPane() {
return pane(
OptPane.stringList("MODULES_SETS_LOADED_TOGETHER", InspectionGadgetsBundle.message("groups.of.modules.loaded.together.label"))
.description(InspectionGadgetsBundle.message("groups.of.modules.loaded.together.description"))
);
}
@Override
public @NotNull OptionController getOptionController() {
return super.getOptionController()
@@ -284,53 +265,4 @@ public final class SuspiciousPackagePrivateAccessInspection extends AbstractBase
super.readSettings(node);
myModuleSetByModuleName.drop();
}
private final class MarkModulesAsLoadedTogetherFix extends ModCommandQuickFix {
private final String myModule1;
private final String myModule2;
private MarkModulesAsLoadedTogetherFix(String module1, String module2) {
myModule1 = module1;
myModule2 = module2;
}
@Override
public @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String getName() {
return InspectionGadgetsBundle.message("mark.modules.as.loaded.together.fix.text", myModule1, myModule2);
}
@Override
public @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String getFamilyName() {
return InspectionGadgetsBundle.message("mark.modules.as.loaded.together.fix.family.name");
}
@Override
public @NotNull ModCommand perform(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement psiElement = descriptor.getPsiElement();
return ModCommand.updateInspectionOption(psiElement, SuspiciousPackagePrivateAccessInspection.this, inspection -> {
Map<String, ModulesSet> moduleSetByModule = inspection.myModuleSetByModuleName.getValue();
ModulesSet module1Set = moduleSetByModule.get(myModule1);
ModulesSet module2Set = moduleSetByModule.get(myModule2);
if (module1Set == null) {
if (module2Set == null) {
ModulesSet modulesSet = new ModulesSet();
modulesSet.modules.add(myModule1);
modulesSet.modules.add(myModule2);
inspection.MODULES_SETS_LOADED_TOGETHER.add(modulesSet);
}
else {
module2Set.modules.add(myModule1);
}
}
else if (module2Set == null) {
module1Set.modules.add(myModule2);
}
else if (module1Set != module2Set) {
module1Set.modules.addAll(module2Set.modules);
inspection.MODULES_SETS_LOADED_TOGETHER.remove(module2Set);
}
inspection.myModuleSetByModuleName.drop();
});
}
}
}