[regexp] Add RegExpAdvertiser

GitOrigin-RevId: b5e2f23b08579044dfc4e79526a5da89340a83ae
This commit is contained in:
Louis Vignier
2023-10-24 01:39:34 +02:00
committed by intellij-monorepo-bot
parent 14259dc0e0
commit 3ce785825d
5 changed files with 39 additions and 5 deletions

View File

@@ -30,6 +30,7 @@
<lang.syntaxHighlighterFactory language="JSRegexp" <lang.syntaxHighlighterFactory language="JSRegexp"
implementationClass="org.intellij.lang.regexp.ecmascript.EcmaScriptRegExpSyntaxHighlighterFactory"/> implementationClass="org.intellij.lang.regexp.ecmascript.EcmaScriptRegExpSyntaxHighlighterFactory"/>
<inspectionProfileActionProvider implementation="org.intellij.lang.regexp.inspection.custom.RegExpProfileActionProvider" /> <inspectionProfileActionProvider implementation="org.intellij.lang.regexp.inspection.custom.RegExpProfileActionProvider" />
<inspectionTreeAdvertiser implementation="org.intellij.lang.regexp.inspection.custom.RegExpAdvertiser" />
<intentionAction> <intentionAction>
<className>org.intellij.lang.regexp.intention.CheckRegExpIntentionAction</className> <className>org.intellij.lang.regexp.intention.CheckRegExpIntentionAction</className>

View File

@@ -123,6 +123,9 @@ inspection.warning.redundant.class.element=Redundant ''{0}'' in RegExp
inspection.warning.redundant.nested.character.class=Redundant nested character class inspection.warning.redundant.nested.character.class=Redundant nested character class
inspection.warning.single.character.alternation.in.regexp=Single character alternation in RegExp inspection.warning.single.character.alternation.in.regexp=Single character alternation in RegExp
inspection.warning.unnecessary.non.capturing.group=Unnecessary non-capturing group <code>{0}</code> inspection.warning.unnecessary.non.capturing.group=Unnecessary non-capturing group <code>{0}</code>
inspection.tree.create.inspection=Using a RegExp\u2026
inspection.tree.group.description=Use the + button in the toolbar to create a new RegExp inspection.<br>\
RegExp inspections highlight code snippets matching the specified regular expression. A quick-fix can be provided by adding a second regular expression.
intention.family.name.replace=Replace intention.family.name.replace=Replace
intention.name.check.regexp=Check RegExp intention.name.check.regexp=Check RegExp
label.any=Any label.any=Any

View File

@@ -47,6 +47,7 @@ import java.util.List;
*/ */
public class CustomRegExpFakeInspection extends LocalInspectionTool { public class CustomRegExpFakeInspection extends LocalInspectionTool {
private static final String GROUP = "RegExp";
@NotNull private final RegExpInspectionConfiguration myConfiguration; @NotNull private final RegExpInspectionConfiguration myConfiguration;
public CustomRegExpFakeInspection(@NotNull RegExpInspectionConfiguration configuration) { public CustomRegExpFakeInspection(@NotNull RegExpInspectionConfiguration configuration) {
@@ -107,15 +108,19 @@ public class CustomRegExpFakeInspection extends LocalInspectionTool {
return CustomRegExpInspection.SHORT_NAME; return CustomRegExpInspection.SHORT_NAME;
} }
public static String[] getGroup() {
return new String[] {InspectionsBundle.message("group.names.user.defined"), GROUP};
}
@Nls(capitalization = Nls.Capitalization.Sentence) @Nls(capitalization = Nls.Capitalization.Sentence)
@Override @Override
public @NotNull String getGroupDisplayName() { public @NotNull String getGroupDisplayName() {
return "RegExp"; return GROUP;
} }
@Override @Override
public @Nls(capitalization = Nls.Capitalization.Sentence) String @NotNull [] getGroupPath() { public @Nls(capitalization = Nls.Capitalization.Sentence) String @NotNull [] getGroupPath() {
return new String[] {InspectionsBundle.message("group.names.user.defined"), getGroupDisplayName()}; return getGroup();
} }
@Nullable @Nullable

View File

@@ -0,0 +1,26 @@
package org.intellij.lang.regexp.inspection.custom;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.profile.codeInspection.ui.InspectionTreeAdvertiser;
import com.intellij.profile.codeInspection.ui.SingleInspectionProfilePanel;
import org.intellij.lang.regexp.RegExpBundle;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class RegExpAdvertiser extends InspectionTreeAdvertiser {
@Override
public @NotNull List<AnAction> getActions(SingleInspectionProfilePanel panel) {
return List.of(
new RegExpProfileActionProvider.AddCustomRegExpInspectionAction(panel, RegExpBundle.message("inspection.tree.create.inspection"), false)
);
}
@Override
public List<CustomGroup> getCustomGroups() {
return List.of(
new CustomGroup(CustomRegExpFakeInspection.getGroup(), RegExpBundle.message("inspection.tree.group.description"))
);
}
}

View File

@@ -5,7 +5,6 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.extensions.ExtensionPointName;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@@ -20,7 +19,7 @@ public abstract class InspectionTreeAdvertiser {
* They appear when no inspections are found after filtering the inspection tree. * They appear when no inspections are found after filtering the inspection tree.
*/ */
@NotNull @NotNull
public abstract List<AnAction> getActions(SingleInspectionProfilePanel panel); public List<AnAction> getActions(SingleInspectionProfilePanel panel) { return List.of(); }
public record CustomGroup(String[] path, String description) {} public record CustomGroup(String[] path, String description) {}
@@ -29,5 +28,5 @@ public abstract class InspectionTreeAdvertiser {
* <li>will always be displayed</li> * <li>will always be displayed</li>
* <li>can have a custom description</li> * <li>can have a custom description</li>
*/ */
public List<CustomGroup> getCustomGroups() { return new ArrayList<>(); } public List<CustomGroup> getCustomGroups() { return List.of(); }
} }