RegExp: warn about duplicate char in character class with intersection (IJPL-193556)

for "Duplicate character in character class" inspection

GitOrigin-RevId: 455aff90e2c52c735df582fced65225b5ecbb2f0
This commit is contained in:
Bas Leijdekkers
2025-06-24 17:51:53 +00:00
committed by intellij-monorepo-bot
parent 9744fab524
commit 0498719d54
2 changed files with 13 additions and 2 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2025 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;
import com.intellij.codeInspection.LocalInspectionTool;
@@ -63,6 +63,12 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
new DuplicateCharacterInClassFix(regExpSimpleClass));
}
}
else if (element instanceof RegExpIntersection intersection) {
final HashSet<Object> visited = new HashSet<>();
for (RegExpClassElement operand : intersection.getOperands()) {
checkForDuplicates(operand, visited);
}
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2025 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;
import com.intellij.codeInspection.LocalInspectionTool;
@@ -8,6 +8,7 @@ import org.jetbrains.annotations.NotNull;
/**
* @author Bas Leijdekkers
*/
@SuppressWarnings("RegExpDuplicateCharacterInClass")
public class DuplicateCharacterInClassInspectionTest extends RegExpInspectionTestCase {
public void testPredefinedCharacterClass() {
@@ -34,6 +35,10 @@ public class DuplicateCharacterInClassInspectionTest extends RegExpInspectionTes
public void testNestedClass() {
highlightTest("[<[^<>]*>]*<[^<>]*");
}
public void testIntersection() {
highlightTest("[\\w<warning descr=\"Duplicate predefined character class '\\w' inside character class\">\\w</warning>&&[^_]]");
}
@Override
protected @NotNull LocalInspectionTool getInspection() {