WI-52566 allow duplicated named subpatterns when J modifier is present

GitOrigin-RevId: 02644c6d0da294dd333c374cbe6d81eafe7c4ca8
This commit is contained in:
Kirill Smelov
2021-08-04 09:55:31 +03:00
committed by intellij-monorepo-bot
parent 751c792a09
commit aad83a3f2e
3 changed files with 9 additions and 1 deletions

View File

@@ -17,6 +17,9 @@ public interface RegExpLanguageHost {
boolean characterNeedsEscaping(char c);
boolean supportsPerl5EmbeddedComments();
boolean supportsPossessiveQuantifiers();
default boolean isDuplicateGroupNamesAllowed(@NotNull RegExpGroup group) {
return false;
}
/**
* @return true, if this dialects support conditionals, i.e. the following construct: {@code (?(1)then|else)}

View File

@@ -111,6 +111,11 @@ public final class RegExpLanguageHosts extends ClassExtension<RegExpLanguageHost
return host != null && host.isValidGroupName(name, group);
}
public boolean isDuplicateGroupNamesAllowed(@NotNull final RegExpGroup group) {
final RegExpLanguageHost host = findRegExpHost(group);
return host != null && host.isDuplicateGroupNamesAllowed(group);
}
public boolean supportsPerl5EmbeddedComments(@Nullable final PsiComment comment) {
final RegExpLanguageHost host = findRegExpHost(comment);
return host != null && host.supportsPerl5EmbeddedComments();

View File

@@ -270,7 +270,7 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
final AnnotationSession session = myHolder.getCurrentAnnotationSession();
final Map<String, RegExpGroup> namedGroups = NAMED_GROUP_MAP.get(session, new HashMap<>());
if (namedGroups.isEmpty()) session.putUserData(NAMED_GROUP_MAP, namedGroups);
if (namedGroups.put(name, group) != null) {
if (namedGroups.put(name, group) != null && !myLanguageHosts.isDuplicateGroupNamesAllowed(group)) {
final ASTNode node = group.getNode().findChildByType(RegExpTT.NAME);
if (node != null) myHolder.newAnnotation(HighlightSeverity.ERROR,
RegExpBundle.message("error.group.with.name.0.already.defined", name)).range(node).create();