mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
Allow user defined inspections to be cleanup inspections (IDEA-299455)
GitOrigin-RevId: 58616c5699a80f60b3fdbfcfaa2c88162112adad
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a46fa5169d
commit
3b7ea8c076
@@ -26,6 +26,7 @@ import com.intellij.ui.LayeredIcon;
|
||||
import com.intellij.ui.ToolbarDecorator;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -76,6 +77,14 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCleanup() {
|
||||
return isCleanupAllowed() && myConfiguration.isCleanup();
|
||||
}
|
||||
|
||||
private boolean isCleanupAllowed() {
|
||||
return ContainerUtil.exists(myConfiguration.getPatterns(), p -> p.replacement() != null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getID() {
|
||||
@@ -161,11 +170,14 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
private void performEditMetaData(@NotNull Component context) {
|
||||
final Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(context));
|
||||
final InspectionProfileModifiableModel profile = getInspectionProfile(context);
|
||||
if (profile == null) {
|
||||
if (profile == null || project == null) {
|
||||
return;
|
||||
}
|
||||
final CustomRegExpInspection inspection = getRegExpInspection(profile);
|
||||
final InspectionMetaDataDialog dialog = inspection.createMetaDataDialog(project, myConfiguration);
|
||||
if (isCleanupAllowed()) {
|
||||
dialog.showCleanupOption(myConfiguration.isCleanup());
|
||||
}
|
||||
if (!dialog.showAndGet()) {
|
||||
return;
|
||||
}
|
||||
@@ -173,6 +185,7 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
|
||||
myConfiguration.setDescription(dialog.getDescription());
|
||||
myConfiguration.setSuppressId(dialog.getSuppressId());
|
||||
myConfiguration.setProblemDescriptor(dialog.getProblemDescriptor());
|
||||
myConfiguration.setCleanup(dialog.isCleanup());
|
||||
|
||||
inspection.updateConfiguration(myConfiguration);
|
||||
profile.setModified(true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.intellij.lang.regexp.inspection.custom;
|
||||
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
@@ -30,4 +30,9 @@ public class CustomRegExpInspectionToolWrapper extends LocalInspectionToolWrappe
|
||||
RegExpInspectionConfiguration configuration = inspection.getConfiguration();
|
||||
return new CustomRegExpInspectionToolWrapper(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCleanupTool() {
|
||||
return ((CustomRegExpFakeInspection)myTool).isCleanup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
|
||||
private String uuid;
|
||||
private String suppressId;
|
||||
private String problemDescriptor;
|
||||
private boolean cleanup;
|
||||
|
||||
public RegExpInspectionConfiguration(@NotNull String name) {
|
||||
this.name = name;
|
||||
@@ -44,6 +45,7 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
|
||||
uuid = other.uuid;
|
||||
suppressId = other.suppressId;
|
||||
problemDescriptor = other.problemDescriptor;
|
||||
cleanup = other.cleanup;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,6 +126,14 @@ public class RegExpInspectionConfiguration implements Comparable<RegExpInspectio
|
||||
this.problemDescriptor = problemDescriptor;
|
||||
}
|
||||
|
||||
public boolean isCleanup() {
|
||||
return cleanup;
|
||||
}
|
||||
|
||||
public void setCleanup(boolean cleanup) {
|
||||
this.cleanup = cleanup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull RegExpInspectionConfiguration o) {
|
||||
int result = name.compareToIgnoreCase(o.name);
|
||||
|
||||
Reference in New Issue
Block a user