From efaad40cbbf9cd5bc93a7fa71dd2cb3da883418a Mon Sep 17 00:00:00 2001 From: Oleg Sukhodolsky Date: Sat, 9 Feb 2013 16:09:50 +0400 Subject: [PATCH] RUBY-12899: \h and \H added to completion list for ruby #RUBY-12899 fixed --- .../DefaultRegExpPropertiesProvider.java | 29 +++++++++++++++++++ .../regexp/RegExpCompletionContributor.java | 26 +++++++---------- .../lang/regexp/RegExpPropertiesProvider.java | 5 ++++ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/DefaultRegExpPropertiesProvider.java b/RegExpSupport/src/org/intellij/lang/regexp/DefaultRegExpPropertiesProvider.java index a62820832efc..5c88ac26106c 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/DefaultRegExpPropertiesProvider.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/DefaultRegExpPropertiesProvider.java @@ -75,6 +75,29 @@ final class DefaultRegExpPropertiesProvider implements RegExpPropertiesProvider { "javaMirrored", }, }; + private final String[][] myCharacterClasses = { + {"d", "digit: [0-9]"}, + {"D", "nondigit: [^0-9]"}, + {"s", "whitespace [ \\t\\n\\x0B\\f\\r]"}, + {"S", "non-whitespace [^\\s]"}, + {"w", "word character [a-zA-Z_0-9]"}, + {"W", "nonword character [^\\w]"}, + {"b", "word boundary"}, + {"B", "non-word boundary"}, + {"A", "beginning of the input"}, + {"G", "end of the previous match"}, + {"Z", "end of the input but for the final terminator, if any"}, + {"z", "end of input"}, + {"Q", "Nothing, but quotes all characters until \\E"}, + {"E", " \tNothing, but ends quoting started by \\Q"}, + {"t", "tab character ('\\u0009')"}, + {"n", "newline (line feed) character ('\\u000A')"}, + {"r", "carriage-return character ('\\u000D')"}, + {"f", "form-feed character ('\\u000C')"}, + {"a", "alert (bell) character ('\\u0007')"}, + {"e", "escape character ('\\u001B')"} + }; + public DefaultRegExpPropertiesProvider() { } @@ -117,4 +140,10 @@ final class DefaultRegExpPropertiesProvider implements RegExpPropertiesProvider public String[][] getAllKnownProperties() { return myPropertyNames; } + + @NotNull + @Override + public String[][] getKnownCharacterClasses() { + return myCharacterClasses; + } } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java index 52bd84b7874f..158f4a90534f 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java @@ -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 : getAllKnownProperties(parameters)) { + for (String[] stringArray : getProvider(parameters).getAllKnownProperties()) { 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 : getAllKnownProperties(parameters)) { + for (String[] stringArray : getProvider(parameters).getAllKnownProperties()) { addLookupElement(result, "{" + stringArray[0] + "}", stringArray.length > 1 ? stringArray[1]:null, PlatformIcons.PROPERTY_ICON); } } @@ -112,27 +112,21 @@ public final class RegExpCompletionContributor extends CompletionContributor { public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, - @NotNull final CompletionResultSet result) { - @NonNls String[] completions = {"d", "D", "s", "S", "w", "W", "b", "B", "A", "G", "Z", "z", "Q", "E", "t", "n", "r", "f", "a", "e"}; - @NonNls String[] completionsTypes = {"digit: [0-9]", "nondigit: [^0-9]", "whitespace [ \\t\\n\\x0B\\f\\r]", "non-whitespace [^\\s]", - "word character [a-zA-Z_0-9]", "nonword character [^\\w]", "word boundary", "non-word boundary", "beginning of the input", - "end of the previous match", "end of the input but for the final terminator, if any", "end of input", - "Nothing, but quotes all characters until \\E", " \tNothing, but ends quoting started by \\Q", "tab character ('\\u0009')", - "newline (line feed) character ('\\u000A')", "carriage-return character ('\\u000D')", "form-feed character ('\\u000C')", - "alert (bell) character ('\\u0007')", "escape character ('\\u001B')"}; - - for (int i = 0; i < completions.length; ++i) { - addLookupElement(result, completions[i], completionsTypes[i], emptyIcon); + @NotNull final CompletionResultSet result) + { + final RegExpPropertiesProvider provider = getProvider(parameters); + for (final String[] completion : provider.getKnownCharacterClasses()) { + addLookupElement(result, completion[0], completion[1], emptyIcon); } - for (String[] stringArray : getAllKnownProperties(parameters)) { + for (String[] stringArray : provider.getAllKnownProperties()) { addLookupElement(result, "p{" + stringArray[0] + "}", stringArray.length > 1? stringArray[1]:null, PlatformIcons.PROPERTY_ICON); } } } @NotNull - private static String[][] getAllKnownProperties(CompletionParameters parameters) { - return RegExpPropertiesProviders.getInstance().forLanguage(parameters.getOriginalFile().getLanguage()).getAllKnownProperties(); + private static RegExpPropertiesProvider getProvider(@NotNull final CompletionParameters parameters) { + return RegExpPropertiesProviders.getInstance().forLanguage(parameters.getOriginalFile().getLanguage()); } } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java index 96407f3ec994..6c7bfac3d43d 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpPropertiesProvider.java @@ -5,8 +5,13 @@ 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(); }