diff --git a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java index b55984cde60d..b71544545bd8 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java @@ -30,7 +30,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.StringEscapesTokenTypes; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import org.intellij.lang.regexp.*; import org.intellij.lang.regexp.psi.*; @@ -124,7 +123,7 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot } @Override - public void visitRegExpChar(final RegExpChar ch) { + public void visitRegExpChar(RegExpChar ch) { final PsiElement child = ch.getFirstChild(); final IElementType type = child.getNode().getElementType(); if (type == RegExpTT.CHARACTER) { @@ -184,15 +183,15 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot final String propertyName = category.getText(); final ASTNode next = category.getTreeNext(); if (next == null || next.getElementType() != RegExpTT.EQ) { - if(!myLanguageHosts.isValidCategory(category.getPsi(), propertyName)) { + if (!myLanguageHosts.isValidCategory(property, propertyName)) { myHolder.newAnnotation(HighlightSeverity.ERROR, RegExpBundle.message("error.unknown.character.category")).range(category) - .highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL).create(); + .highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL).create(); } } else { - if(!myLanguageHosts.isValidPropertyName(category.getPsi(), propertyName)) { + if (!myLanguageHosts.isValidPropertyName(category.getPsi(), propertyName)) { myHolder.newAnnotation(HighlightSeverity.ERROR, RegExpBundle.message("error.unknown.property.name")).range(category) - .highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL).create(); + .highlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL).create(); return; } final ASTNode valueNode = property.getValueNode(); @@ -219,7 +218,7 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot } @Override - public void visitRegExpBackref(final RegExpBackref backref) { + public void visitRegExpBackref(RegExpBackref backref) { final RegExpGroup group = backref.resolve(); if (group == null) { myHolder.newAnnotation(HighlightSeverity.ERROR, RegExpBundle.message("error.unresolved.back.reference")) @@ -236,14 +235,11 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot @Override public void visitRegExpGroup(RegExpGroup group) { if (RegExpGroupImpl.isPcreConditionalGroup(group.getNode())) { - if (RegExpGroupImpl.isPcreDefine(group.getNode())) { - RegExpConditional conditional = ObjectUtils.tryCast(group.getParent(), RegExpConditional.class); - if (conditional != null) { - RegExpBranch[] branches = PsiTreeUtil.getChildrenOfType(conditional, RegExpBranch.class); - if (branches != null && branches.length > 1) { - myHolder.newAnnotation(HighlightSeverity.ERROR, - RegExpBundle.message("error.define.subpattern.contains.more.than.one.branch")).create(); - } + if (RegExpGroupImpl.isPcreDefine(group.getNode()) && group.getParent() instanceof RegExpConditional conditional) { + final RegExpBranch[] branches = PsiTreeUtil.getChildrenOfType(conditional, RegExpBranch.class); + if (branches != null && branches.length > 1) { + myHolder.newAnnotation(HighlightSeverity.ERROR, + RegExpBundle.message("error.define.subpattern.contains.more.than.one.branch")).create(); } } return; @@ -256,10 +252,9 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot } else if (branches.length == 1) { final RegExpAtom[] atoms = branches[0].getAtoms(); - if (atoms.length == 1 && atoms[0] instanceof RegExpGroup) { + if (atoms.length == 1 && atoms[0] instanceof RegExpGroup innerGroup) { final RegExpGroup.Type type = group.getType(); if (type == RegExpGroup.Type.CAPTURING_GROUP || type == RegExpGroup.Type.ATOMIC || type == RegExpGroup.Type.NON_CAPTURING) { - final RegExpGroup innerGroup = (RegExpGroup)atoms[0]; if (group.isCapturing() == innerGroup.isCapturing()) { myHolder.newAnnotation(HighlightSeverity.WARNING, RegExpBundle.message("error.redundant.group.nesting")).create(); }