mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
regex: fix false positive in case of nested classes
GitOrigin-RevId: c73091ff46baa78354ff8cea8455b5bb874ea57f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e0895e2a54
commit
cbd19c935f
@@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports duplicate characters inside a RegExp character class. For example <code>[++]</code>.
|
||||
Duplicate characters are unnecessary and can be removed without changing the semantics of the regex.
|
||||
<!-- tooltip end -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -34,8 +34,9 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
|
||||
|
||||
@Override
|
||||
public void visitRegExpClass(RegExpClass regExpClass) {
|
||||
if (!(regExpClass.getParent() instanceof RegExpClass)) {
|
||||
checkForDuplicates(regExpClass, new HashSet<>());
|
||||
final HashSet<Object> seen = new HashSet<>();
|
||||
for (RegExpClassElement element : regExpClass.getElements()) {
|
||||
checkForDuplicates(element, seen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,12 +60,6 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
|
||||
new DuplicateCharacterInClassFix(regExpSimpleClass));
|
||||
}
|
||||
}
|
||||
else if (element instanceof RegExpClass) {
|
||||
final RegExpClass regExpClass = (RegExpClass)element;
|
||||
for (RegExpClassElement classElement : regExpClass.getElements()) {
|
||||
checkForDuplicates(classElement, seen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,14 @@ public class DuplicateCharacterInClassInspectionTest extends RegExpInspectionTes
|
||||
public void testSpace() {
|
||||
quickfixAllTest("[ <warning descr=\"Duplicate character ' ' inside character class\"><caret> </warning><warning descr=\"Duplicate character ' ' inside character class\"> </warning>]", "[ ]");
|
||||
}
|
||||
|
||||
public void testNegatedClass() {
|
||||
highlightTest("[^a<warning descr=\"Duplicate character 'a' inside character class\">a</warning>]");
|
||||
}
|
||||
|
||||
public void testNestedClass() {
|
||||
highlightTest("[<[^<>]*>]*<[^<>]*");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull LocalInspectionTool getInspection() {
|
||||
|
||||
Reference in New Issue
Block a user