mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-13071: (refactoring) RegExpPropertyNameProvider introduced.
This commit is contained in:
@@ -25,7 +25,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -91,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 : RegExpPropertyImpl.getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpPropertyNameProvider.getAllKnownProperties()) {
|
||||
result.addElement(
|
||||
TailTypeDecorator.withTail(createLookupElement(stringArray[0], null, emptyIcon), TailType.createSimpleTailType('}')));
|
||||
}
|
||||
@@ -103,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 : RegExpPropertyImpl.getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpPropertyNameProvider.getAllKnownProperties()) {
|
||||
addLookupElement(result, "{" + stringArray[0] + "}", stringArray.length > 1 ? stringArray[1]:null, PlatformIcons.PROPERTY_ICON);
|
||||
}
|
||||
}
|
||||
@@ -126,7 +125,7 @@ public class RegExpCompletionContributor extends CompletionContributor {
|
||||
addLookupElement(result, completions[i], completionsTypes[i], emptyIcon);
|
||||
}
|
||||
|
||||
for (String[] stringArray : RegExpPropertyImpl.getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpPropertyNameProvider.getAllKnownProperties()) {
|
||||
addLookupElement(result, "p{" + stringArray[0] + "}", stringArray.length > 1? stringArray[1]:null, PlatformIcons.PROPERTY_ICON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.psi.PsiElement;
|
||||
import org.intellij.lang.regexp.psi.RegExpElement;
|
||||
import org.intellij.lang.regexp.psi.RegExpGroup;
|
||||
import org.intellij.lang.regexp.psi.RegExpProperty;
|
||||
import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -35,7 +34,7 @@ public class RegExpDocumentationProvider extends AbstractDocumentationProvider {
|
||||
final RegExpProperty prop = (RegExpProperty)element;
|
||||
final ASTNode node = prop.getCategoryNode();
|
||||
if (node != null) {
|
||||
final String description = RegExpPropertyImpl.getPropertyDescription(node.getText());
|
||||
final String description = RegExpPropertyNameProvider.getPropertyDescription(node.getText());
|
||||
if (description != null) {
|
||||
if (prop.isNegated()) {
|
||||
return "Property block stands for characters not matching " + description;
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
package org.intellij.lang.regexp;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class RegExpPropertyNameProvider {
|
||||
private static final String[][] PROPERTY_NAMES = {
|
||||
{ "Cn", "UNASSIGNED" },
|
||||
{ "Lu", "UPPERCASE_LETTER" },
|
||||
{ "Ll", "LOWERCASE_LETTER" },
|
||||
{ "Lt", "TITLECASE_LETTER" },
|
||||
{ "Lm", "MODIFIER_LETTER" },
|
||||
{ "Lo", "OTHER_LETTER" },
|
||||
{ "Mn", "NON_SPACING_MARK" },
|
||||
{ "Me", "ENCLOSING_MARK" },
|
||||
{ "Mc", "COMBINING_SPACING_MARK" },
|
||||
{ "Nd", "DECIMAL_DIGIT_NUMBER" },
|
||||
{ "Nl", "LETTER_NUMBER" },
|
||||
{ "No", "OTHER_NUMBER" },
|
||||
{ "Zs", "SPACE_SEPARATOR" },
|
||||
{ "Zl", "LINE_SEPARATOR" },
|
||||
{ "Zp", "PARAGRAPH_SEPARATOR" },
|
||||
{ "Cc", "CNTRL" },
|
||||
{ "Cf", "FORMAT" },
|
||||
{ "Co", "PRIVATE USE" },
|
||||
{ "Cs", "SURROGATE" },
|
||||
{ "Pd", "DASH_PUNCTUATION" },
|
||||
{ "Ps", "START_PUNCTUATION" },
|
||||
{ "Pe", "END_PUNCTUATION" },
|
||||
{ "Pc", "CONNECTOR_PUNCTUATION" },
|
||||
{ "Po", "OTHER_PUNCTUATION" },
|
||||
{ "Sm", "MATH_SYMBOL" },
|
||||
{ "Sc", "CURRENCY_SYMBOL" },
|
||||
{ "Sk", "MODIFIER_SYMBOL" },
|
||||
{ "So", "OTHER_SYMBOL" },
|
||||
{ "L", "LETTER" },
|
||||
{ "M", "MARK" },
|
||||
{ "N", "NUMBER" },
|
||||
{ "Z", "SEPARATOR" },
|
||||
{ "C", "CONTROL" },
|
||||
{ "P", "PUNCTUATION" },
|
||||
{ "S", "SYMBOL" },
|
||||
{ "LD", "LETTER_OR_DIGIT" },
|
||||
{ "L1", "Latin-1" },
|
||||
{ "all", "ALL" },
|
||||
{ "ASCII", "ASCII" },
|
||||
{ "Alnum", "Alphanumeric characters" },
|
||||
{ "Alpha", "Alphabetic characters" },
|
||||
{ "Blank", "Space and tab characters" },
|
||||
{ "Cntrl", "Control characters" },
|
||||
{ "Digit", "Numeric characters" },
|
||||
{ "Graph", "printable and visible" },
|
||||
{ "Lower", "Lower-case alphabetic" },
|
||||
{ "Print", "Printable characters" },
|
||||
{ "Punct", "Punctuation characters" },
|
||||
{ "Space", "Space characters" },
|
||||
{ "Upper", "Upper-case alphabetic" },
|
||||
{ "XDigit", "hexadecimal digits" },
|
||||
{ "javaLowerCase", },
|
||||
{ "javaUpperCase", },
|
||||
{ "javaTitleCase", },
|
||||
{ "javaDigit", },
|
||||
{ "javaDefined", },
|
||||
{ "javaLetter", },
|
||||
{ "javaLetterOrDigit", },
|
||||
{ "javaJavaIdentifierStart", },
|
||||
{ "javaJavaIdentifierPart", },
|
||||
{ "javaUnicodeIdentifierStart", },
|
||||
{ "javaUnicodeIdentifierPart", },
|
||||
{ "javaIdentifierIgnorable", },
|
||||
{ "javaSpaceChar", },
|
||||
{ "javaWhitespace", },
|
||||
{ "javaISOControl", },
|
||||
{ "javaMirrored", },
|
||||
};
|
||||
|
||||
private RegExpPropertyNameProvider() {
|
||||
}
|
||||
|
||||
|
||||
public static boolean isValidCategory(@NotNull String category) {
|
||||
if (category.startsWith("In")) {
|
||||
try {
|
||||
return Character.UnicodeBlock.forName(category.substring(2)) != null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (category.startsWith("Is")) {
|
||||
category = category.substring(2);
|
||||
}
|
||||
for (String[] name : PROPERTY_NAMES) {
|
||||
if (name[0].equals(category)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getPropertyDescription(@Nullable final String name) {
|
||||
if (StringUtil.isEmptyOrSpaces(name)) {
|
||||
return null;
|
||||
}
|
||||
for (String[] stringArray : PROPERTY_NAMES) {
|
||||
if (stringArray[0].equals(name)) {
|
||||
return stringArray.length > 1 ? stringArray[1] : stringArray[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String[][] getAllKnownProperties() {
|
||||
return PROPERTY_NAMES;
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,12 @@ import com.intellij.codeInsight.lookup.LookupValueWithPriority;
|
||||
import com.intellij.codeInsight.lookup.LookupValueWithUIHint;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
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.RegExpTT;
|
||||
import org.intellij.lang.regexp.psi.RegExpElementVisitor;
|
||||
import org.intellij.lang.regexp.psi.RegExpProperty;
|
||||
@@ -63,44 +63,7 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
|
||||
visitor.visitRegExpProperty(this);
|
||||
}
|
||||
|
||||
public static boolean isValidCategory(String category) {
|
||||
if (category.startsWith("In")) {
|
||||
try {
|
||||
return Character.UnicodeBlock.forName(category.substring(2)) != null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (category.startsWith("Is")) {
|
||||
category = category.substring(2);
|
||||
}
|
||||
for (String[] name : PROPERTY_NAMES) {
|
||||
if (name[0].equals(category)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getPropertyDescription(@Nullable final String name) {
|
||||
if (StringUtil.isEmptyOrSpaces(name)) {
|
||||
return null;
|
||||
}
|
||||
for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
|
||||
if (stringArray[0].equals(name)) {
|
||||
return stringArray.length > 1 ? stringArray[1] : stringArray[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String[][] getAllKnownProperties() {
|
||||
return RegExpPropertyImpl.PROPERTY_NAMES;
|
||||
}
|
||||
|
||||
private class MyPsiReference implements PsiReference {
|
||||
private class MyPsiReference implements PsiReference {
|
||||
public PsiElement getElement() {
|
||||
return RegExpPropertyImpl.this;
|
||||
}
|
||||
@@ -143,9 +106,10 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
|
||||
if (categoryNode != null && categoryNode.getText().startsWith("In") && !categoryNode.getText().startsWith("Intelli")) {
|
||||
return UNICODE_BLOCKS;
|
||||
} else {
|
||||
final Object[] objects = new Object[PROPERTY_NAMES.length];
|
||||
final String[][] knownProperties = RegExpPropertyNameProvider.getAllKnownProperties();
|
||||
final Object[] objects = new Object[knownProperties.length];
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
final String[] prop = PROPERTY_NAMES[i];
|
||||
final String[] prop = knownProperties[i];
|
||||
objects[i] = new MyLookupValue(prop);
|
||||
|
||||
}
|
||||
@@ -211,73 +175,4 @@ public class RegExpPropertyImpl extends RegExpElementImpl implements RegExpPrope
|
||||
}
|
||||
UNICODE_BLOCKS = ArrayUtil.toStringArray(unicodeBlocks);
|
||||
}
|
||||
private static final String[][] PROPERTY_NAMES = {
|
||||
{ "Cn", "UNASSIGNED" },
|
||||
{ "Lu", "UPPERCASE_LETTER" },
|
||||
{ "Ll", "LOWERCASE_LETTER" },
|
||||
{ "Lt", "TITLECASE_LETTER" },
|
||||
{ "Lm", "MODIFIER_LETTER" },
|
||||
{ "Lo", "OTHER_LETTER" },
|
||||
{ "Mn", "NON_SPACING_MARK" },
|
||||
{ "Me", "ENCLOSING_MARK" },
|
||||
{ "Mc", "COMBINING_SPACING_MARK" },
|
||||
{ "Nd", "DECIMAL_DIGIT_NUMBER" },
|
||||
{ "Nl", "LETTER_NUMBER" },
|
||||
{ "No", "OTHER_NUMBER" },
|
||||
{ "Zs", "SPACE_SEPARATOR" },
|
||||
{ "Zl", "LINE_SEPARATOR" },
|
||||
{ "Zp", "PARAGRAPH_SEPARATOR" },
|
||||
{ "Cc", "CNTRL" },
|
||||
{ "Cf", "FORMAT" },
|
||||
{ "Co", "PRIVATE USE" },
|
||||
{ "Cs", "SURROGATE" },
|
||||
{ "Pd", "DASH_PUNCTUATION" },
|
||||
{ "Ps", "START_PUNCTUATION" },
|
||||
{ "Pe", "END_PUNCTUATION" },
|
||||
{ "Pc", "CONNECTOR_PUNCTUATION" },
|
||||
{ "Po", "OTHER_PUNCTUATION" },
|
||||
{ "Sm", "MATH_SYMBOL" },
|
||||
{ "Sc", "CURRENCY_SYMBOL" },
|
||||
{ "Sk", "MODIFIER_SYMBOL" },
|
||||
{ "So", "OTHER_SYMBOL" },
|
||||
{ "L", "LETTER" },
|
||||
{ "M", "MARK" },
|
||||
{ "N", "NUMBER" },
|
||||
{ "Z", "SEPARATOR" },
|
||||
{ "C", "CONTROL" },
|
||||
{ "P", "PUNCTUATION" },
|
||||
{ "S", "SYMBOL" },
|
||||
{ "LD", "LETTER_OR_DIGIT" },
|
||||
{ "L1", "Latin-1" },
|
||||
{ "all", "ALL" },
|
||||
{ "ASCII", "ASCII" },
|
||||
{ "Alnum", "Alphanumeric characters" },
|
||||
{ "Alpha", "Alphabetic characters" },
|
||||
{ "Blank", "Space and tab characters" },
|
||||
{ "Cntrl", "Control characters" },
|
||||
{ "Digit", "Numeric characters" },
|
||||
{ "Graph", "printable and visible" },
|
||||
{ "Lower", "Lower-case alphabetic" },
|
||||
{ "Print", "Printable characters" },
|
||||
{ "Punct", "Punctuation characters" },
|
||||
{ "Space", "Space characters" },
|
||||
{ "Upper", "Upper-case alphabetic" },
|
||||
{ "XDigit", "hexadecimal digits" },
|
||||
{ "javaLowerCase", },
|
||||
{ "javaUpperCase", },
|
||||
{ "javaTitleCase", },
|
||||
{ "javaDigit", },
|
||||
{ "javaDefined", },
|
||||
{ "javaLetter", },
|
||||
{ "javaLetterOrDigit", },
|
||||
{ "javaJavaIdentifierStart", },
|
||||
{ "javaJavaIdentifierPart", },
|
||||
{ "javaUnicodeIdentifierStart", },
|
||||
{ "javaUnicodeIdentifierPart", },
|
||||
{ "javaIdentifierIgnorable", },
|
||||
{ "javaSpaceChar", },
|
||||
{ "javaWhitespace", },
|
||||
{ "javaISOControl", },
|
||||
{ "javaMirrored", },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ 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.psi.*;
|
||||
import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -135,7 +135,7 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
|
||||
|
||||
public void visitRegExpProperty(RegExpProperty property) {
|
||||
final ASTNode category = property.getCategoryNode();
|
||||
if (category != null && !RegExpPropertyImpl.isValidCategory(category.getText())) {
|
||||
if (category != null && !RegExpPropertyNameProvider.isValidCategory(category.getText())) {
|
||||
final Annotation a = myHolder.createErrorAnnotation(category, "Unknown character category");
|
||||
if (a != null) {
|
||||
// IDEA-9381
|
||||
|
||||
@@ -19,7 +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.psi.impl.RegExpPropertyImpl;
|
||||
import org.intellij.lang.regexp.RegExpPropertyNameProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -59,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 : RegExpPropertyImpl.getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpPropertyNameProvider.getAllKnownProperties()) {
|
||||
nameList.add("p{" + stringArray[0] + "}");
|
||||
}
|
||||
myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));
|
||||
@@ -67,7 +67,7 @@ public class RegExpCompletionTest extends CodeInsightFixtureTestCase {
|
||||
|
||||
public void testPropertyVariants() throws Throwable {
|
||||
java.util.List<String> nameList = new ArrayList<String>();
|
||||
for (String[] stringArray : RegExpPropertyImpl.getAllKnownProperties()) {
|
||||
for (String[] stringArray : RegExpPropertyNameProvider.getAllKnownProperties()) {
|
||||
nameList.add("{" + stringArray[0] + "}");
|
||||
}
|
||||
myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));
|
||||
|
||||
Reference in New Issue
Block a user