diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpGroup.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpGroup.java
index 7770f6ad4376..8bd66654790f 100644
--- a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpGroup.java
+++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpGroup.java
@@ -19,6 +19,8 @@ import org.jetbrains.annotations.Nullable;
public interface RegExpGroup extends RegExpAtom {
boolean isCapturing();
+
+ boolean isSimple();
@Nullable
RegExpPattern getPattern();
diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java
index 9b8fa67ece98..368dd0fd7bb4 100644
--- a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java
+++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java
@@ -37,6 +37,11 @@ public class RegExpGroupImpl extends RegExpElementImpl implements RegExpGroup {
return node != null && node.getElementType() == RegExpTT.GROUP_BEGIN;
}
+ public boolean isSimple() {
+ final ASTNode node = getNode().getFirstChildNode();
+ return node != null && (node.getElementType() == RegExpTT.GROUP_BEGIN || node.getElementType() == RegExpTT.NON_CAPT_GROUP);
+ }
+
public RegExpPattern getPattern() {
final ASTNode node = getNode().findChildByType(RegExpElementTypes.PATTERN);
return node != null ? (RegExpPattern)node.getPsi() : null;
diff --git a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java
index 52307d1cd58d..4ddc4fbb0855 100644
--- a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java
+++ b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java
@@ -155,7 +155,12 @@ 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) {
- myHolder.createWarningAnnotation(group, "Redundant group nesting");
+ if (group.isSimple()) {
+ final RegExpGroup innerGroup = (RegExpGroup)atoms[0];
+ if (group.isCapturing() == innerGroup.isCapturing()) {
+ myHolder.createWarningAnnotation(group, "Redundant group nesting");
+ }
+ }
}
}
}
diff --git a/RegExpSupport/testData/RETest.xml b/RegExpSupport/testData/RETest.xml
index e0c7c3163d86..2316463a0863 100644
--- a/RegExpSupport/testData/RETest.xml
+++ b/RegExpSupport/testData/RETest.xml
@@ -990,4 +990,11 @@
OK
+
+
+
+ (^|\.)\*(?=(\.|$))
+ OK
+
+