diff --git a/RegExpSupport/RegExpSupport.iml b/RegExpSupport/RegExpSupport.iml
index b9b3142c9ce2..4597318e7885 100644
--- a/RegExpSupport/RegExpSupport.iml
+++ b/RegExpSupport/RegExpSupport.iml
@@ -15,6 +15,9 @@
+
+
+
diff --git a/RegExpSupport/src/META-INF/RegExpPlugin.xml b/RegExpSupport/src/META-INF/RegExpPlugin.xml
index 3c37bbbac875..a245a2eae7cd 100644
--- a/RegExpSupport/src/META-INF/RegExpPlugin.xml
+++ b/RegExpSupport/src/META-INF/RegExpPlugin.xml
@@ -1,4 +1,7 @@
+
+
+
diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java
index 37dcc6c527b1..c283f19e87af 100644
--- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java
+++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java
@@ -15,6 +15,8 @@
*/
package org.intellij.lang.regexp;
+import org.intellij.lang.regexp.psi.RegExpGroup;
+
/**
* @author yole
*/
@@ -22,7 +24,6 @@ public interface RegExpLanguageHost {
boolean characterNeedsEscaping(char c);
boolean supportsPerl5EmbeddedComments();
boolean supportsPossessiveQuantifiers();
- boolean supportsPythonNamedGroups();
boolean supportsPythonConditionalRefs();
- boolean supportsRubyNamedGroups();
+ boolean supportsNamedGroupSyntax(RegExpGroup group);
}
diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java
new file mode 100644
index 000000000000..0f57f33975fc
--- /dev/null
+++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.intellij.lang.regexp;
+
+import com.intellij.openapi.util.ClassExtension;
+
+/**
+ * @author yole
+ */
+public class RegExpLanguageHosts extends ClassExtension {
+ public static RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts();
+
+ private RegExpLanguageHosts() {
+ super("com.intellij.regExpLanguageHost");
+ }
+}
diff --git a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java
index 359849287d83..359a4871acf6 100644
--- a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java
+++ b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java
@@ -27,6 +27,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.util.PsiTreeUtil;
import org.intellij.lang.regexp.RegExpLanguageHost;
+import org.intellij.lang.regexp.RegExpLanguageHosts;
import org.intellij.lang.regexp.RegExpTT;
import org.intellij.lang.regexp.psi.*;
import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
@@ -124,6 +125,9 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
if (host instanceof RegExpLanguageHost) {
return (RegExpLanguageHost)host;
}
+ if (host != null) {
+ return RegExpLanguageHosts.INSTANCE.forClass(host.getClass());
+ }
return null;
}
@@ -174,8 +178,7 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
}
if (group.isPythonNamedGroup() || group.isRubyNamedGroup()) {
RegExpLanguageHost host = findRegExpHost(group);
- if (host == null || (group.isPythonNamedGroup() && !host.supportsPythonNamedGroups()) ||
- (group.isRubyNamedGroup() && !host.supportsRubyNamedGroups())) {
+ if (host == null || !host.supportsNamedGroupSyntax(group)) {
myHolder.createErrorAnnotation(group, "This named group syntax is not supported");
}
}
@@ -183,11 +186,13 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
@Override
public void visitRegExpPyNamedGroupRef(RegExpPyNamedGroupRef groupRef) {
+ /* the named group itself will be highlighted as unsupported; no need to highlight reference as well
RegExpLanguageHost host = findRegExpHost(groupRef);
if (host == null || !host.supportsPythonNamedGroups()) {
myHolder.createErrorAnnotation(groupRef, "This named group reference syntax is not supported");
return;
}
+ */
final RegExpGroup group = groupRef.resolve();
if (group == null) {
final Annotation a = myHolder.createErrorAnnotation(groupRef, "Unresolved backreference");
diff --git a/java/java-impl/java-impl.iml b/java/java-impl/java-impl.iml
index 934740800fe9..20ad95d8d9bb 100644
--- a/java/java-impl/java-impl.iml
+++ b/java/java-impl/java-impl.iml
@@ -31,6 +31,7 @@
+
diff --git a/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java b/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java
new file mode 100644
index 000000000000..a86bb91455dc
--- /dev/null
+++ b/java/java-impl/src/com/intellij/psi/impl/JavaRegExpHost.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.psi.impl;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleUtil;
+import com.intellij.openapi.projectRoots.JavaSdk;
+import com.intellij.openapi.projectRoots.JavaSdkVersion;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.ModuleRootManager;
+import org.intellij.lang.regexp.RegExpLanguageHost;
+import org.intellij.lang.regexp.psi.RegExpGroup;
+
+/**
+ * @author yole
+ */
+public class JavaRegExpHost implements RegExpLanguageHost {
+ @Override
+ public boolean characterNeedsEscaping(char c) {
+ return c == ']' || c == '}';
+ }
+
+ @Override
+ public boolean supportsPerl5EmbeddedComments() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsPossessiveQuantifiers() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsPythonConditionalRefs() {
+ return false;
+ }
+
+ @Override
+ public boolean supportsNamedGroupSyntax(RegExpGroup group) {
+ if (group.isRubyNamedGroup()) {
+ final Module module = ModuleUtil.findModuleForPsiElement(group);
+ if (module != null) {
+ final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
+ if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
+ final JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
+ return version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7);
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml
index bec0cf45f755..adb4c5cd8e46 100644
--- a/resources/src/META-INF/IdeaPlugin.xml
+++ b/resources/src/META-INF/IdeaPlugin.xml
@@ -1209,6 +1209,9 @@
+
+