RegExp: don't warn on incomplete quantifier (IJPL-101794)

in "Regular expression can be simplified" inspection"

GitOrigin-RevId: b3207ab9da853781017e5b782caaff9083d33ace
This commit is contained in:
Bas Leijdekkers
2025-04-12 16:28:13 +00:00
committed by intellij-monorepo-bot
parent 3a8dccfbc7
commit 602cb1bafd
2 changed files with 6 additions and 1 deletions
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.intellij.lang.regexp.RegExpBundle;
import org.intellij.lang.regexp.RegExpTT;
@@ -107,7 +108,7 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool {
@Override
public void visitRegExpQuantifier(RegExpQuantifier quantifier) {
if (!quantifier.isCounted()) {
if (!quantifier.isCounted() || quantifier.getLastChild() instanceof PsiErrorElement) {
return;
}
final RegExpNumber minElement = quantifier.getMin();
@@ -42,6 +42,10 @@ public class RegExpSimplifiableInspectionTest extends RegExpInspectionTestCase {
highlightTest("[\\W&&\\S]");
}
public void testIncomplete() {
highlightTest(".{<EOLError descr=\"Number expected\"></EOLError>");
}
public void testSingleElementClass() {
doTest("[a]", "a");
}