mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 09:12:22 +07:00
Pattern variable can be used mass cleanup
GitOrigin-RevId: 55839bf0deca5f81d0f7eb5b1c190145a5ea0037
This commit is contained in:
committed by
intellij-monorepo-bot
parent
daaa8e8930
commit
f456ed0604
@@ -15,8 +15,7 @@ public final class RegExpDocumentationProvider extends AbstractDocumentationProv
|
||||
@Nullable
|
||||
@Nls
|
||||
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
|
||||
if (element instanceof RegExpProperty) {
|
||||
final RegExpProperty prop = (RegExpProperty)element;
|
||||
if (element instanceof RegExpProperty prop) {
|
||||
final ASTNode node = prop.getCategoryNode();
|
||||
if (node != null) {
|
||||
final String description = RegExpLanguageHosts.getInstance().getPropertyDescription(node.getPsi(), node.getText());
|
||||
@@ -35,8 +34,7 @@ public final class RegExpDocumentationProvider extends AbstractDocumentationProv
|
||||
@Override
|
||||
@Nullable
|
||||
public @Nls String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
|
||||
if (element instanceof RegExpGroup) {
|
||||
final RegExpGroup group = (RegExpGroup)element;
|
||||
if (element instanceof RegExpGroup group) {
|
||||
return StringUtil.escapeXmlEntities(group.getUnescapedText());
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -41,8 +41,7 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
private void checkForDuplicates(RegExpClassElement element, Set<Object> seen) {
|
||||
if (element instanceof RegExpChar) {
|
||||
final RegExpChar regExpChar = (RegExpChar)element;
|
||||
if (element instanceof RegExpChar regExpChar) {
|
||||
final int value = regExpChar.getValue();
|
||||
if (value != -1 && !seen.add(value)) {
|
||||
myHolder.registerProblem(regExpChar,
|
||||
@@ -50,8 +49,7 @@ public class DuplicateCharacterInClassInspection extends LocalInspectionTool {
|
||||
new DuplicateCharacterInClassFix(regExpChar));
|
||||
}
|
||||
}
|
||||
else if (element instanceof RegExpSimpleClass) {
|
||||
final RegExpSimpleClass regExpSimpleClass = (RegExpSimpleClass)element;
|
||||
else if (element instanceof RegExpSimpleClass regExpSimpleClass) {
|
||||
final RegExpSimpleClass.Kind kind = regExpSimpleClass.getKind();
|
||||
if (!seen.add(kind)) {
|
||||
final String text = regExpSimpleClass.getText();
|
||||
|
||||
@@ -65,14 +65,12 @@ public class ReDoSInspection extends LocalInspectionTool {
|
||||
|
||||
private static boolean isAtomic(RegExpAtom element) {
|
||||
while (element != null) {
|
||||
if (element instanceof RegExpClosure) {
|
||||
final RegExpClosure closure = (RegExpClosure)element;
|
||||
if (element instanceof RegExpClosure closure) {
|
||||
if (closure.getQuantifier().isPossessive()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (element instanceof RegExpGroup) {
|
||||
final RegExpGroup group = (RegExpGroup)element;
|
||||
else if (element instanceof RegExpGroup group) {
|
||||
if (group.getType() == RegExpGroup.Type.ATOMIC) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class RedundantNestedCharacterClassInspection extends LocalInspectionTool
|
||||
// JDK 9: [^a&&b] is the intersection of [a] and [b] (which is nothing), inverted, which equals everything.
|
||||
// see https://bugs.openjdk.org/browse/JDK-8189343
|
||||
// and http://mail.openjdk.org/pipermail/core-libs-dev/2011-June/006957.html
|
||||
if (parent instanceof RegExpClass) {
|
||||
final RegExpClass parentClass = (RegExpClass)parent;
|
||||
if (parent instanceof RegExpClass parentClass) {
|
||||
if (!parentClass.isNegated() && !regExpClass.isNegated()) {
|
||||
myHolder.registerProblem(regExpClass.getFirstChild(), RegExpBundle.message("inspection.warning.redundant.nested.character.class"),
|
||||
new RedundantNestedCharacterClassFix());
|
||||
@@ -52,8 +51,7 @@ public class RedundantNestedCharacterClassInspection extends LocalInspectionTool
|
||||
}
|
||||
else if (parent instanceof RegExpIntersection) {
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
if (grandParent instanceof RegExpClass) {
|
||||
final RegExpClass grandparentClass = (RegExpClass)grandParent;
|
||||
if (grandParent instanceof RegExpClass grandparentClass) {
|
||||
if (!grandparentClass.isNegated() && !regExpClass.isNegated()) {
|
||||
myHolder.registerProblem(regExpClass.getFirstChild(), RegExpBundle.message("inspection.warning.redundant.nested.character.class"),
|
||||
new RedundantNestedCharacterClassFix());
|
||||
@@ -72,8 +70,7 @@ public class RedundantNestedCharacterClassInspection extends LocalInspectionTool
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement().getParent();
|
||||
if (element instanceof RegExpClass) {
|
||||
final RegExpClass regExpClass = (RegExpClass)element;
|
||||
if (element instanceof RegExpClass regExpClass) {
|
||||
final RegExpClassElement[] elements = regExpClass.getElements();
|
||||
final PsiElement parent = regExpClass.getParent();
|
||||
for (RegExpClassElement classElement : elements) {
|
||||
|
||||
@@ -35,8 +35,7 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool {
|
||||
super.visitRegExpClass(regExpClass);
|
||||
final RegExpClassElement[] elements = regExpClass.getElements();
|
||||
for (RegExpClassElement element : elements) {
|
||||
if (element instanceof RegExpCharRange) {
|
||||
final RegExpCharRange range = (RegExpCharRange)element;
|
||||
if (element instanceof RegExpCharRange range) {
|
||||
final int from = range.getFrom().getValue();
|
||||
final RegExpChar to = range.getTo();
|
||||
if (from != -1 && to != null && from == to.getValue()) {
|
||||
@@ -48,8 +47,7 @@ public class RegExpSimplifiableInspection extends LocalInspectionTool {
|
||||
if (regExpClass.isNegated()) {
|
||||
if (elements.length == 1) {
|
||||
final RegExpClassElement element = elements[0];
|
||||
if (element instanceof RegExpSimpleClass) {
|
||||
final RegExpSimpleClass simpleClass = (RegExpSimpleClass)element;
|
||||
if (element instanceof RegExpSimpleClass simpleClass) {
|
||||
final String text = getInverseSimpleClassText(simpleClass);
|
||||
if (text != null) {
|
||||
// [^\d] -> \D
|
||||
|
||||
@@ -79,10 +79,9 @@ public class RepeatedSpaceInspection extends LocalInspectionTool {
|
||||
}
|
||||
|
||||
private static boolean isSpace(PsiElement element) {
|
||||
if (!(element instanceof RegExpChar)) {
|
||||
if (!(element instanceof RegExpChar aChar)) {
|
||||
return false;
|
||||
}
|
||||
final RegExpChar aChar = (RegExpChar)element;
|
||||
return aChar.getType() == RegExpChar.Type.CHAR && aChar.getValue() == ' ';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,9 @@ public class SingleCharAlternationInspection extends LocalInspectionTool {
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
if (!(element instanceof RegExpPattern)) {
|
||||
if (!(element instanceof RegExpPattern pattern)) {
|
||||
return;
|
||||
}
|
||||
final RegExpPattern pattern = (RegExpPattern)element;
|
||||
final PsiElement parent = pattern.getParent();
|
||||
final PsiElement victim =
|
||||
(parent instanceof RegExpGroup && ((RegExpGroup)parent).getType() == RegExpGroup.Type.NON_CAPTURING) ? parent : pattern;
|
||||
@@ -96,10 +95,9 @@ public class SingleCharAlternationInspection extends LocalInspectionTool {
|
||||
final StringBuilder text = new StringBuilder("[");
|
||||
for (RegExpBranch branch : pattern.getBranches()) {
|
||||
for (PsiElement child : branch.getChildren()) {
|
||||
if (!(child instanceof RegExpChar)) {
|
||||
if (!(child instanceof RegExpChar ch)) {
|
||||
return null;
|
||||
}
|
||||
final RegExpChar ch = (RegExpChar)child;
|
||||
final IElementType type = ch.getNode().getFirstChildNode().getElementType();
|
||||
if (type == RegExpTT.REDUNDANT_ESCAPE) {
|
||||
final int value = ch.getValue();
|
||||
|
||||
@@ -84,16 +84,13 @@ public class UnexpectedAnchorInspection extends LocalInspectionTool {
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
else if (sibling instanceof RegExpClosure) {
|
||||
final RegExpClosure closure = (RegExpClosure)sibling;
|
||||
else if (sibling instanceof RegExpClosure closure) {
|
||||
return isUnexpectedSibling(element, next, closure.getAtom());
|
||||
}
|
||||
else if (sibling instanceof RegExpGroup) {
|
||||
final RegExpGroup group = (RegExpGroup)sibling;
|
||||
else if (sibling instanceof RegExpGroup group) {
|
||||
return isUnexpectedSibling(element, next, group.getPattern());
|
||||
}
|
||||
else if (sibling instanceof RegExpPattern) {
|
||||
final RegExpPattern pattern = (RegExpPattern)sibling;
|
||||
else if (sibling instanceof RegExpPattern pattern) {
|
||||
for (RegExpBranch branch : pattern.getBranches()) {
|
||||
if (isUnexpectedSibling(element, next, branch)) {
|
||||
return true;
|
||||
|
||||
@@ -87,10 +87,9 @@ public class UnnecessaryNonCapturingGroupInspection extends LocalInspectionTool
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement element = descriptor.getPsiElement().getParent();
|
||||
if (!(element instanceof RegExpGroup)) {
|
||||
if (!(element instanceof RegExpGroup group)) {
|
||||
return;
|
||||
}
|
||||
final RegExpGroup group = (RegExpGroup)element;
|
||||
RegExpReplacementUtil.replaceInContext(group, group.getPattern().getUnescapedText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,8 +366,7 @@ public final class CheckRegExpForm {
|
||||
PsiElement element = regExpFile.findElementAt(offset);
|
||||
RegExpGroup group = null;
|
||||
while (element != null) {
|
||||
if (element instanceof RegExpGroup) {
|
||||
final RegExpGroup g = (RegExpGroup)element;
|
||||
if (element instanceof RegExpGroup g) {
|
||||
if (g.isCapturing()) {
|
||||
group = g;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user