mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RUBY-13071: properties provider is taken from language ext. point
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<idea-plugin>
|
||||
<extensionPoints>
|
||||
<extensionPoint name="regExpLanguageHost" beanClass="com.intellij.openapi.util.ClassExtensionPoint"/>
|
||||
<extensionPoint name="regExpPropertiesProvider" beanClass="com.intellij.lang.LanguageExtensionPoint"/>
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<lang.documentationProvider language="RegExp" implementationClass="org.intellij.lang.regexp.RegExpDocumentationProvider"/>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.intellij.openapi.util.ClassExtension;
|
||||
* @author yole
|
||||
*/
|
||||
public class RegExpLanguageHosts extends ClassExtension<RegExpLanguageHost> {
|
||||
public static RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts();
|
||||
public static final RegExpLanguageHosts INSTANCE = new RegExpLanguageHosts();
|
||||
|
||||
private RegExpLanguageHosts() {
|
||||
super("com.intellij.regExpLanguageHost");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.intellij.lang.regexp;
|
||||
|
||||
import com.intellij.lang.LanguageExtension;
|
||||
|
||||
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 RegExpPropertyNameProvider());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<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 : 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<String> nameList = new ArrayList<String>();
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user