mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RegExp: use stream
This commit is contained in:
+9
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user