From 2ed397510c62295dbb9e1dd9bf03f18d27fca2a8 Mon Sep 17 00:00:00 2001 From: Oleg Sukhodolsky Date: Sat, 9 Feb 2013 14:28:38 +0400 Subject: [PATCH] RUBY-13071: properties provider is taken from language ext. point --- RegExpSupport/src/META-INF/RegExpPlugin.xml | 1 + .../lang/regexp/RegExpCompletionContributor.java | 8 ++++---- .../lang/regexp/RegExpDocumentationProvider.java | 6 ++++-- .../intellij/lang/regexp/RegExpLanguageHosts.java | 2 +- .../lang/regexp/RegExpPropertiesProvider.java | 12 ++++++++++++ .../lang/regexp/RegExpPropertiesProviders.java | 15 +++++++++++++++ .../lang/regexp/RegExpPropertyNameProvider.java | 14 +++++--------- .../lang/regexp/psi/impl/RegExpPropertyImpl.java | 5 +++-- .../lang/regexp/validation/RegExpAnnotator.java | 13 ++++++++----- RegExpSupport/test/test/RegExpCompletionTest.java | 7 ++++--- 10 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java create mode 100644 RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProviders.java diff --git a/RegExpSupport/src/META-INF/RegExpPlugin.xml b/RegExpSupport/src/META-INF/RegExpPlugin.xml index ae16a2118329..ca97297ba153 100644 --- a/RegExpSupport/src/META-INF/RegExpPlugin.xml +++ b/RegExpSupport/src/META-INF/RegExpPlugin.xml @@ -1,6 +1,7 @@ + diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java index 487b3bba1289..b56cdb81db55 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java @@ -35,7 +35,7 @@ import static com.intellij.patterns.PlatformPatterns.psiElement; /** * @author vnikolaenko */ -public class RegExpCompletionContributor extends CompletionContributor { +public final class RegExpCompletionContributor extends CompletionContributor { private static final Icon emptyIcon = new EmptyIcon(PlatformIcons.PROPERTY_ICON.getIconWidth(), PlatformIcons.PROPERTY_ICON.getIconHeight()); public RegExpCompletionContributor() { @@ -90,7 +90,7 @@ public class RegExpCompletionContributor extends CompletionContributor { public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) { - for (String[] stringArray : RegExpPropertyNameProvider.getInstance().getAllKnownProperties()) { + for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(parameters.getOriginalFile().getLanguage()).getAllKnownProperties()) { result.addElement( TailTypeDecorator.withTail(createLookupElement(stringArray[0], null, emptyIcon), TailType.createSimpleTailType('}'))); } @@ -102,7 +102,7 @@ public class RegExpCompletionContributor extends CompletionContributor { public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) { - for (String[] stringArray : RegExpPropertyNameProvider.getInstance().getAllKnownProperties()) { + for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(parameters.getOriginalFile().getLanguage()).getAllKnownProperties()) { addLookupElement(result, "{" + stringArray[0] + "}", stringArray.length > 1 ? stringArray[1]:null, PlatformIcons.PROPERTY_ICON); } } @@ -125,7 +125,7 @@ public class RegExpCompletionContributor extends CompletionContributor { addLookupElement(result, completions[i], completionsTypes[i], emptyIcon); } - for (String[] stringArray : RegExpPropertyNameProvider.getInstance().getAllKnownProperties()) { + for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(parameters.getOriginalFile().getLanguage()).getAllKnownProperties()) { addLookupElement(result, "p{" + stringArray[0] + "}", stringArray.length > 1? stringArray[1]:null, PlatformIcons.PROPERTY_ICON); } } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpDocumentationProvider.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpDocumentationProvider.java index c0d3f762a6cc..0559a9abf4e4 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpDocumentationProvider.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpDocumentationProvider.java @@ -16,6 +16,7 @@ package org.intellij.lang.regexp; import com.intellij.lang.ASTNode; +import com.intellij.lang.Language; import com.intellij.lang.documentation.AbstractDocumentationProvider; import com.intellij.psi.PsiElement; import org.intellij.lang.regexp.psi.RegExpElement; @@ -26,7 +27,7 @@ import org.jetbrains.annotations.Nullable; /** * @author vnikolaenko */ -public class RegExpDocumentationProvider extends AbstractDocumentationProvider { +public final class RegExpDocumentationProvider extends AbstractDocumentationProvider { @Override @Nullable public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) { @@ -34,7 +35,8 @@ public class RegExpDocumentationProvider extends AbstractDocumentationProvider { final RegExpProperty prop = (RegExpProperty)element; final ASTNode node = prop.getCategoryNode(); if (node != null) { - final String description = RegExpPropertyNameProvider.getInstance().getPropertyDescription(node.getText()); + final Language language = node.getPsi().getContainingFile().getLanguage(); + final String description = RegExpPropertiesProviders.getInstance().forLanguage(language).getPropertyDescription(node.getText()); if (description != null) { if (prop.isNegated()) { return "Property block stands for characters not matching " + description; diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java index 0f57f33975fc..d36e7e6a009c 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java @@ -21,7 +21,7 @@ import com.intellij.openapi.util.ClassExtension; * @author yole */ public class RegExpLanguageHosts extends ClassExtension { - public static RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts(); + public static final RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts(); private RegExpLanguageHosts() { super("com.intellij.regExpLanguageHost"); diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java new file mode 100644 index 000000000000..96407f3ec994 --- /dev/null +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java @@ -0,0 +1,12 @@ +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(); +} diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProviders.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProviders.java new file mode 100644 index 000000000000..758fd80c30ae --- /dev/null +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProviders.java @@ -0,0 +1,15 @@ +package org.intellij.lang.regexp; + +import com.intellij.lang.LanguageExtension; + +public final class RegExpPropertiesProviders extends LanguageExtension { + private static final RegExpPropertiesProviders INSTANCE = new RegExpPropertiesProviders(); + + public static RegExpPropertiesProviders getInstance() { + return INSTANCE; + } + + public RegExpPropertiesProviders() { + super("com.intellij.regExpPropertiesProvider", new RegExpPropertyNameProvider()); + } +} diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertyNameProvider.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertyNameProvider.java index 4506b99d800a..f0f9cb14df4e 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertyNameProvider.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertyNameProvider.java @@ -4,7 +4,7 @@ import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public final class RegExpPropertyNameProvider { +final class RegExpPropertyNameProvider implements RegExpPropertiesProvider { private final String[][] myPropertyNames = { { "Cn", "UNASSIGNED" }, { "Lu", "UPPERCASE_LETTER" }, @@ -75,16 +75,10 @@ public final class RegExpPropertyNameProvider { { "javaMirrored", }, }; - private static RegExpPropertyNameProvider ourInstance = new RegExpPropertyNameProvider(); - - private RegExpPropertyNameProvider() { - } - - @NotNull - public static RegExpPropertyNameProvider getInstance() { - return ourInstance; + public RegExpPropertyNameProvider() { } + @Override public boolean isValidCategory(@NotNull String category) { if (category.startsWith("In")) { try { @@ -104,6 +98,7 @@ public final class RegExpPropertyNameProvider { return false; } + @Override @Nullable public String getPropertyDescription(@Nullable final String name) { if (StringUtil.isEmptyOrSpaces(name)) { @@ -117,6 +112,7 @@ public final class RegExpPropertyNameProvider { return null; } + @Override @NotNull public String[][] getAllKnownProperties() { return myPropertyNames; diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpPropertyImpl.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpPropertyImpl.java index bdef2823a5f5..d559cc771fd0 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpPropertyImpl.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpPropertyImpl.java @@ -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.RegExpPropertyNameProvider; +import org.intellij.lang.regexp.RegExpPropertiesProviders; import org.intellij.lang.regexp.RegExpTT; import org.intellij.lang.regexp.psi.RegExpElementVisitor; import org.intellij.lang.regexp.psi.RegExpProperty; @@ -106,7 +106,8 @@ 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 = RegExpPropertyNameProvider.getInstance().getAllKnownProperties(); + final String[][] knownProperties = RegExpPropertiesProviders + .getInstance().forLanguage(getNode().getPsi().getContainingFile().getLanguage()).getAllKnownProperties(); final Object[] objects = new Object[knownProperties.length]; for (int i = 0; i < objects.length; i++) { final String[] prop = knownProperties[i]; diff --git a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java index af4894ab54ae..b3bbb13c1cca 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java @@ -18,6 +18,7 @@ package org.intellij.lang.regexp.validation; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.ProblemHighlightType; import com.intellij.lang.ASTNode; +import com.intellij.lang.Language; import com.intellij.lang.annotation.Annotation; import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.lang.annotation.Annotator; @@ -26,10 +27,7 @@ import com.intellij.psi.PsiComment; 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.RegExpPropertyNameProvider; -import org.intellij.lang.regexp.RegExpTT; +import org.intellij.lang.regexp.*; import org.intellij.lang.regexp.psi.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -135,7 +133,12 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot public void visitRegExpProperty(RegExpProperty property) { final ASTNode category = property.getCategoryNode(); - if (category != null && !RegExpPropertyNameProvider.getInstance().isValidCategory(category.getText())) { + if (category == null) { + return; + } + final Language language = category.getPsi().getContainingFile().getLanguage(); + final RegExpPropertiesProvider provider = RegExpPropertiesProviders.getInstance().forLanguage(language); + if(!provider.isValidCategory(category.getText())) { final Annotation a = myHolder.createErrorAnnotation(category, "Unknown character category"); if (a != null) { // IDEA-9381 diff --git a/RegExpSupport/test/test/RegExpCompletionTest.java b/RegExpSupport/test/test/RegExpCompletionTest.java index 1cb4705a7328..6d2fd262d7c9 100644 --- a/RegExpSupport/test/test/RegExpCompletionTest.java +++ b/RegExpSupport/test/test/RegExpCompletionTest.java @@ -19,7 +19,8 @@ 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.RegExpPropertyNameProvider; +import org.intellij.lang.regexp.RegExpLanguage; +import org.intellij.lang.regexp.RegExpPropertiesProviders; import java.io.File; import java.util.ArrayList; @@ -59,7 +60,7 @@ public class RegExpCompletionTest extends CodeInsightFixtureTestCase { private void doBackSlashVariantsTest() throws Throwable { java.util.List nameList = new ArrayList(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 : RegExpPropertyNameProvider.getInstance().getAllKnownProperties()) { + for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(RegExpLanguage.INSTANCE).getAllKnownProperties()) { nameList.add("p{" + stringArray[0] + "}"); } myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList)); @@ -67,7 +68,7 @@ public class RegExpCompletionTest extends CodeInsightFixtureTestCase { public void testPropertyVariants() throws Throwable { java.util.List nameList = new ArrayList(); - for (String[] stringArray : RegExpPropertyNameProvider.getInstance().getAllKnownProperties()) { + for (String[] stringArray : RegExpPropertiesProviders.getInstance().forLanguage(RegExpLanguage.INSTANCE).getAllKnownProperties()) { nameList.add("{" + stringArray[0] + "}"); } myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));