mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
don't highlight named groups in Java 1.7 regular expressions as errors (IDEA-80456)
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
<orderEntry type="module" module-name="xml" />
|
||||
<orderEntry type="module" module-name="testFramework" scope="TEST" />
|
||||
<orderEntry type="library" name="Jaxen" level="project" />
|
||||
<orderEntry type="module" module-name="dom-impl" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="relaxng" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="spellchecker" scope="RUNTIME" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<idea-plugin>
|
||||
<extensionPoints>
|
||||
<extensionPoint name="regExpLanguageHost" beanClass="com.intellij.openapi.util.ClassExtensionPoint"/>
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<lang.documentationProvider language="RegExp" implementationClass="org.intellij.lang.regexp.RegExpDocumentationProvider"/>
|
||||
<completion.contributor language="RegExp" implementationClass="org.intellij.lang.regexp.RegExpCompletionContributor"/>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<RegExpLanguageHost> {
|
||||
public static RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts();
|
||||
|
||||
private RegExpLanguageHosts() {
|
||||
super("com.intellij.regExpLanguageHost");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
|
||||
<orderEntry type="module" module-name="java-psi-impl" exported="" />
|
||||
<orderEntry type="module" module-name="RegExpSupport" />
|
||||
</component>
|
||||
<component name="copyright">
|
||||
<Base>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1209,6 +1209,9 @@
|
||||
<wizardMode implementation="com.intellij.ide.util.newProjectWizard.modes.CreateProjectFromSourcesMode" id="CreateProjectFromSourcesMode" order="after CreateFromScratchMode"/>
|
||||
<wizardMode implementation="com.intellij.ide.util.newProjectWizard.modes.CreateModuleFromSourcesMode" id="CreateModuleFromSourcesMode" order="after CreateProjectFromSourcesMode"/>
|
||||
<projectStructureDetector implementation="com.intellij.ide.util.projectWizard.importSources.impl.JavaProjectStructureDetector" order="first"/>
|
||||
|
||||
<regExpLanguageHost forClass="com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl"
|
||||
implementationClass="com.intellij.psi.impl.JavaRegExpHost"/>
|
||||
</extensions>
|
||||
|
||||
<actions>
|
||||
|
||||
Reference in New Issue
Block a user