IDEA-52291

This commit is contained in:
sweinreuter
2010-02-25 15:01:07 +01:00
parent c9a180abf7
commit 357517bc71
4 changed files with 20 additions and 1 deletions
@@ -19,6 +19,8 @@ import org.jetbrains.annotations.Nullable;
public interface RegExpGroup extends RegExpAtom {
boolean isCapturing();
boolean isSimple();
@Nullable
RegExpPattern getPattern();
@@ -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;
@@ -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");
}
}
}
}
}
+7
View File
@@ -990,4 +990,11 @@
<expected>OK</expected>
</test>
</bug>
<bug id="IDEA-52291">
<test>
<pattern>(^|\.)\*(?=(\.|$))</pattern>
<expected>OK</expected>
</test>
</bug>
</tests>