mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-13071: (refactoring) RegExpPropertiesProvider iface merged into RegExpLanguageHost
This commit is contained in:
@@ -4,7 +4,13 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
final class DefaultRegExpPropertiesProvider implements RegExpPropertiesProvider {
|
||||
public final class DefaultRegExpPropertiesProvider {
|
||||
private static final DefaultRegExpPropertiesProvider INSTANCE = new DefaultRegExpPropertiesProvider();
|
||||
|
||||
public static DefaultRegExpPropertiesProvider getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final String[][] myPropertyNames = {
|
||||
{ "Cn", "UNASSIGNED" },
|
||||
{ "Lu", "UPPERCASE_LETTER" },
|
||||
@@ -98,10 +104,9 @@ final class DefaultRegExpPropertiesProvider implements RegExpPropertiesProvider
|
||||
{"e", "escape character ('\\u001B')"}
|
||||
};
|
||||
|
||||
public DefaultRegExpPropertiesProvider() {
|
||||
private DefaultRegExpPropertiesProvider() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidCategory(@NotNull String category) {
|
||||
if (category.startsWith("In")) {
|
||||
try {
|
||||
@@ -121,7 +126,6 @@ final class DefaultRegExpPropertiesProvider implements RegExpPropertiesProvider
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getPropertyDescription(@Nullable final String name) {
|
||||
if (StringUtil.isEmptyOrSpaces(name)) {
|
||||
@@ -135,14 +139,12 @@ final class DefaultRegExpPropertiesProvider implements RegExpPropertiesProvider
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String[][] getAllKnownProperties() {
|
||||
return myPropertyNames;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[][] getKnownCharacterClasses() {
|
||||
return myCharacterClasses;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class RegExpCompletionContributor extends CompletionContributor {
|
||||
public void addCompletions(@NotNull final CompletionParameters parameters,
|
||||
final ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result) {
|
||||
for (String[] stringArray : getProvider(parameters).getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpLanguageHosts.getInstance().getAllKnownProperties(parameters.getPosition())) {
|
||||
result.addElement(
|
||||
TailTypeDecorator.withTail(createLookupElement(stringArray[0], null, emptyIcon), TailType.createSimpleTailType('}')));
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public final class RegExpCompletionContributor extends CompletionContributor {
|
||||
public void addCompletions(@NotNull final CompletionParameters parameters,
|
||||
final ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result) {
|
||||
for (String[] stringArray : getProvider(parameters).getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpLanguageHosts.getInstance().getAllKnownProperties(parameters.getPosition())) {
|
||||
addLookupElement(result, "{" + stringArray[0] + "}", stringArray.length > 1 ? stringArray[1]:null, PlatformIcons.PROPERTY_ICON);
|
||||
}
|
||||
}
|
||||
@@ -114,19 +114,13 @@ public final class RegExpCompletionContributor extends CompletionContributor {
|
||||
final ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result)
|
||||
{
|
||||
final RegExpPropertiesProvider provider = getProvider(parameters);
|
||||
for (final String[] completion : provider.getKnownCharacterClasses()) {
|
||||
for (final String[] completion : RegExpLanguageHosts.getInstance().getKnownCharacterClasses(parameters.getPosition())) {
|
||||
addLookupElement(result, completion[0], completion[1], emptyIcon);
|
||||
}
|
||||
|
||||
for (String[] stringArray : provider.getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpLanguageHosts.getInstance().getAllKnownProperties(parameters.getPosition())) {
|
||||
addLookupElement(result, "p{" + stringArray[0] + "}", stringArray.length > 1? stringArray[1]:null, PlatformIcons.PROPERTY_ICON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static RegExpPropertiesProvider getProvider(@NotNull final CompletionParameters parameters) {
|
||||
return RegExpPropertiesProviders.getInstance().forLanguage(parameters.getOriginalFile().getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class RegExpDocumentationProvider extends AbstractDocumentationProv
|
||||
final RegExpProperty prop = (RegExpProperty)element;
|
||||
final ASTNode node = prop.getCategoryNode();
|
||||
if (node != null) {
|
||||
final String description = RegExpPropertiesProviders.forNode(node).getPropertyDescription(node.getText());
|
||||
final String description = RegExpLanguageHosts.getInstance().getPropertyDescription(node.getPsi(), node.getText());
|
||||
if (description != null) {
|
||||
if (prop.isNegated()) {
|
||||
return "Property block stands for characters not matching " + description;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package org.intellij.lang.regexp;
|
||||
|
||||
import org.intellij.lang.regexp.psi.RegExpGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -26,4 +28,12 @@ public interface RegExpLanguageHost {
|
||||
boolean supportsPossessiveQuantifiers();
|
||||
boolean supportsPythonConditionalRefs();
|
||||
boolean supportsNamedGroupSyntax(RegExpGroup group);
|
||||
|
||||
boolean isValidCategory(@NotNull String category);
|
||||
@NotNull
|
||||
String[][] getAllKnownProperties();
|
||||
@Nullable
|
||||
String getPropertyDescription(@Nullable final String name);
|
||||
@NotNull
|
||||
String[][] getKnownCharacterClasses();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public final class RegExpLanguageHosts extends ClassExtension<RegExpLanguageHost> {
|
||||
private static final RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts();
|
||||
private final DefaultRegExpPropertiesProvider myDefaultProvider;
|
||||
|
||||
public static RegExpLanguageHosts getInstance() {
|
||||
return INSTANCE;
|
||||
@@ -39,6 +40,7 @@ public final class RegExpLanguageHosts extends ClassExtension<RegExpLanguageHost
|
||||
|
||||
private RegExpLanguageHosts() {
|
||||
super("com.intellij.regExpLanguageHost");
|
||||
myDefaultProvider = DefaultRegExpPropertiesProvider.getInstance();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -90,4 +92,33 @@ public final class RegExpLanguageHosts extends ClassExtension<RegExpLanguageHost
|
||||
final RegExpLanguageHost host = findRegExpHost(quantifier);
|
||||
return host != null && host.supportsPossessiveQuantifiers();
|
||||
}
|
||||
|
||||
public boolean isValidCategory(@NotNull final PsiElement element, @NotNull String category) {
|
||||
final RegExpLanguageHost host = findRegExpHost(element);
|
||||
if (host == null) {
|
||||
return false;
|
||||
}
|
||||
return host.isValidCategory(category);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String[][] getAllKnownProperties(@NotNull final PsiElement element) {
|
||||
final RegExpLanguageHost host = findRegExpHost(element);
|
||||
if (host != null) {
|
||||
return host.getAllKnownProperties();
|
||||
}
|
||||
return myDefaultProvider.getAllKnownProperties();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
String getPropertyDescription(@NotNull final PsiElement element, @Nullable final String name) {
|
||||
final RegExpLanguageHost host = findRegExpHost(element);
|
||||
return host == null ? null : host.getPropertyDescription(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
String[][] getKnownCharacterClasses(@NotNull final PsiElement element) {
|
||||
final RegExpLanguageHost host = findRegExpHost(element);
|
||||
return host != null ? host.getKnownCharacterClasses() : myDefaultProvider.getKnownCharacterClasses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package org.intellij.lang.regexp;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface RegExpPropertiesProvider {
|
||||
boolean isValidCategory(@NotNull String category);
|
||||
|
||||
@Nullable
|
||||
String getPropertyDescription(@Nullable final String name);
|
||||
|
||||
@NotNull
|
||||
String[][] getAllKnownProperties();
|
||||
|
||||
@NotNull
|
||||
String[][] getKnownCharacterClasses();
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package org.intellij.lang.regexp;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.LanguageExtension;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class RegExpPropertiesProviders extends LanguageExtension<RegExpPropertiesProvider> {
|
||||
private static final RegExpPropertiesProviders INSTANCE = new RegExpPropertiesProviders();
|
||||
|
||||
public static RegExpPropertiesProviders getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public RegExpPropertiesProviders() {
|
||||
super("com.intellij.regExpPropertiesProvider", new DefaultRegExpPropertiesProvider());
|
||||
}
|
||||
|
||||
public static RegExpPropertiesProvider forNode(@NotNull final ASTNode node) {
|
||||
return getInstance().forLanguage(node.getPsi().getContainingFile().getLanguage());
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import org.intellij.lang.regexp.RegExpPropertiesProviders;
|
||||
import org.intellij.lang.regexp.RegExpLanguageHosts;
|
||||
import org.intellij.lang.regexp.RegExpTT;
|
||||
import org.intellij.lang.regexp.psi.RegExpElementVisitor;
|
||||
import org.intellij.lang.regexp.psi.RegExpProperty;
|
||||
@@ -106,7 +106,7 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
|
||||
if (categoryNode != null && categoryNode.getText().startsWith("In") && !categoryNode.getText().startsWith("Intelli")) {
|
||||
return UNICODE_BLOCKS;
|
||||
} else {
|
||||
final String[][] knownProperties = RegExpPropertiesProviders.forNode(getNode()).getAllKnownProperties();
|
||||
final String[][] knownProperties = RegExpLanguageHosts.getInstance().getAllKnownProperties(getElement());
|
||||
final Object[] objects = new Object[knownProperties.length];
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
final String[] prop = knownProperties[i];
|
||||
|
||||
@@ -112,8 +112,7 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
|
||||
if (category == null) {
|
||||
return;
|
||||
}
|
||||
final RegExpPropertiesProvider provider = RegExpPropertiesProviders.forNode(category);
|
||||
if(!provider.isValidCategory(category.getText())) {
|
||||
if(!myLanguageHosts.isValidCategory(category.getPsi(), category.getText())) {
|
||||
final Annotation a = myHolder.createErrorAnnotation(category, "Unknown character category");
|
||||
if (a != null) {
|
||||
// IDEA-9381
|
||||
|
||||
@@ -19,8 +19,7 @@ import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.intellij.lang.regexp.RegExpLanguage;
|
||||
import org.intellij.lang.regexp.RegExpPropertiesProviders;
|
||||
import org.intellij.lang.regexp.DefaultRegExpPropertiesProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -60,7 +59,7 @@ public class RegExpCompletionTest extends CodeInsightFixtureTestCase {
|
||||
private void doBackSlashVariantsTest() throws Throwable {
|
||||
java.util.List<String> nameList = new ArrayList<String>(Arrays.asList("d", "D", "s", "S", "w", "W", "b", "B", "A", "G", "Z", "z", "Q", "E",
|
||||
"t", "n", "r", "f", "a", "e"));
|
||||
for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(RegExpLanguage.INSTANCE).getAllKnownProperties()) {
|
||||
for (String[] stringArray : DefaultRegExpPropertiesProvider.getInstance().getAllKnownProperties()) {
|
||||
nameList.add("p{" + stringArray[0] + "}");
|
||||
}
|
||||
myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));
|
||||
@@ -68,7 +67,7 @@ public class RegExpCompletionTest extends CodeInsightFixtureTestCase {
|
||||
|
||||
public void testPropertyVariants() throws Throwable {
|
||||
java.util.List<String> nameList = new ArrayList<String>();
|
||||
for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(RegExpLanguage.INSTANCE).getAllKnownProperties()) {
|
||||
for (String[] stringArray : DefaultRegExpPropertiesProvider.getInstance().getAllKnownProperties()) {
|
||||
nameList.add("{" + stringArray[0] + "}");
|
||||
}
|
||||
myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));
|
||||
|
||||
@@ -16,18 +16,28 @@
|
||||
package com.intellij.psi.impl;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
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.DefaultRegExpPropertiesProvider;
|
||||
import org.intellij.lang.regexp.RegExpLanguageHost;
|
||||
import org.intellij.lang.regexp.psi.RegExpGroup;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class JavaRegExpHost implements RegExpLanguageHost {
|
||||
|
||||
private final DefaultRegExpPropertiesProvider myPropertiesProvider;
|
||||
|
||||
public JavaRegExpHost() {
|
||||
myPropertiesProvider = DefaultRegExpPropertiesProvider.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean characterNeedsEscaping(char c) {
|
||||
return c == ']' || c == '}';
|
||||
@@ -51,7 +61,7 @@ public class JavaRegExpHost implements RegExpLanguageHost {
|
||||
@Override
|
||||
public boolean supportsNamedGroupSyntax(RegExpGroup group) {
|
||||
if (group.isRubyNamedGroup()) {
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(group);
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(group);
|
||||
if (module != null) {
|
||||
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
|
||||
@@ -62,4 +72,27 @@ public class JavaRegExpHost implements RegExpLanguageHost {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidCategory(@NotNull String category) {
|
||||
return myPropertiesProvider.isValidCategory(category);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[][] getAllKnownProperties() {
|
||||
return myPropertiesProvider.getAllKnownProperties();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPropertyDescription(@Nullable String name) {
|
||||
return myPropertiesProvider.getPropertyDescription(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[][] getKnownCharacterClasses() {
|
||||
return myPropertiesProvider.getKnownCharacterClasses();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user