From 1d05c617d299f61062aaff45aaeeffbea58ca41e Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Wed, 12 Apr 2017 09:29:46 +0200 Subject: [PATCH] RegExp: use stream --- .../SingleCharAlternationInspection.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/inspection/SingleCharAlternationInspection.java b/RegExpSupport/src/org/intellij/lang/regexp/inspection/SingleCharAlternationInspection.java index ef981cea5c37..2027351f6fd1 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/inspection/SingleCharAlternationInspection.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/inspection/SingleCharAlternationInspection.java @@ -28,6 +28,8 @@ import org.intellij.lang.regexp.psi.*; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; +import java.util.stream.Stream; + /** * @author Bas Leijdekkers */ @@ -60,17 +62,19 @@ public class SingleCharAlternationInspection extends LocalInspectionTool { if (branches.length < 2) { return; } - for (RegExpBranch branch : branches) { - final RegExpAtom[] atoms = branch.getAtoms(); - if (atoms.length != 1 || !(atoms[0] instanceof RegExpChar)) { - return; - } + if (!Stream.of(branches).allMatch(SingleCharAlternationVisitor::isSingleChar)) { + return; } final String text = buildReplacementText(pattern); //noinspection DialogTitleCapitalization myHolder.registerProblem(pattern, "Single character alternation in RegExp", new SingleCharAlternationFix(text)); } + private static boolean isSingleChar(RegExpBranch branch) { + final RegExpAtom[] atoms = branch.getAtoms(); + return atoms.length == 1 && atoms[0] instanceof RegExpChar; + } + private static class SingleCharAlternationFix implements LocalQuickFix { private final String myText;