IDEA-241963 Devkit: support <separator> "key" in plugin.xml

GitOrigin-RevId: de4ca65ae6fb8b717a40b95ebd861e58302eda33
This commit is contained in:
Yann Cébron
2020-05-28 14:56:46 +03:00
committed by intellij-monorepo-bot
parent d992c5b59e
commit 2bf945f71c
6 changed files with 42 additions and 3 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.idea.devkit.dom;
import com.intellij.ide.presentation.Presentation;
@@ -13,4 +13,7 @@ public interface Separator extends GenericDomValue<String> {
@NotNull
@Stubbed
GenericAttributeValue<String> getText();
@NotNull
GenericAttributeValue<String> getKey();
}
@@ -22,11 +22,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.devkit.dom.Extension;
import org.jetbrains.idea.devkit.dom.ExtensionPoint;
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
import org.jetbrains.idea.devkit.dom.Separator;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import static com.intellij.patterns.XmlPatterns.xmlAttributeValue;
import static com.intellij.patterns.XmlPatterns.xmlTag;
public class I18nReferenceContributor extends PsiReferenceContributor {
@@ -34,6 +36,8 @@ public class I18nReferenceContributor extends PsiReferenceContributor {
private static final String INTENTION_ACTION_TAG = "intentionAction";
private static final String INTENTION_ACTION_BUNDLE_TAG = "bundleName";
private static final String SEPARATOR_TAG = "separator";
private static class Holder {
private static final String CONFIGURABLE_EP = ConfigurableEP.class.getName();
private static final String INSPECTION_EP = InspectionEP.class.getName();
@@ -58,6 +62,12 @@ public class I18nReferenceContributor extends PsiReferenceContributor {
Holder.TYPE_NAME_EP),
new PropertyKeyReferenceProvider(false, "resourceKey", "resourceBundle"));
final XmlAttributeValuePattern separatorKeyPattern =
xmlAttributeValue("key")
.withSuperParent(2, DomPatterns.tagWithDom(SEPARATOR_TAG, Separator.class));
registrar.registerReferenceProvider(separatorKeyPattern,
new PropertyKeyReferenceProvider(false, null, null));
final XmlTagPattern.Capture intentionActionKeyTagPattern =
xmlTag().withLocalName("categoryKey").
withParent(DomPatterns.tagWithDom(INTENTION_ACTION_TAG, Extension.class));
@@ -95,7 +105,7 @@ public class I18nReferenceContributor extends PsiReferenceContributor {
private static XmlAttributeValuePattern extensionAttributePattern(String[] attributeNames,
String... extensionPointClassNames) {
//noinspection deprecation
return XmlPatterns.xmlAttributeValue(attributeNames)
return xmlAttributeValue(attributeNames)
.inFile(DomPatterns.inDomFile(IdeaPlugin.class))
.withSuperParent(2, xmlTag()
.and(DomPatterns.withDom(DomPatterns.domElement(Extension.class).with(new PatternCondition<Extension>("relevantEP") {
@@ -43,6 +43,9 @@ public class PluginXmlCapitalizationInspection extends DevKitPluginXmlInspection
else if (element instanceof OverrideText) {
checkOverrideText((OverrideText)element, holder);
}
else if (element instanceof Separator) {
checkSeparator((Separator)element, holder);
}
else if (element instanceof Extension) {
checkExtension((Extension)element, holder);
}
@@ -51,6 +54,10 @@ public class PluginXmlCapitalizationInspection extends DevKitPluginXmlInspection
}
}
private static void checkSeparator(Separator separator, DomElementAnnotationHolder holder) {
checkPropertyCapitalization(holder, separator.getKey(), Nls.Capitalization.Title, separator.getKey().getStringValue(), false);
}
private static void checkOverrideText(OverrideText overrideText, DomElementAnnotationHolder holder) {
if (checkCapitalization(holder, overrideText.getText(), Nls.Capitalization.Title)) return;
@@ -75,4 +75,12 @@
<myCustomInspection groupKey="<error descr="Cannot resolve property key">INVALID_KEY</error>" groupBundle="INVALID_BUNDLE"
key="<error descr="Cannot resolve property key">INVALID_KEY</error>" bundle="<error descr="Cannot resolve property bundle">INVALID_BUNDLE</error>"/>
</extensions>
<actions>
<group id="separatorGroup">
<separator key="my.key"/>
<separator key="<error descr="Cannot resolve property key">INVALID_KEY</error>"/>
</group>
</actions>
</idea-plugin>
@@ -10,4 +10,7 @@ action.BundleGroupWrongCasing.text=group lower case text
action.BundleGroupWrongCasing.description=group lower case description
action.OverrideBundleAction.ViaBundle.text=Action Text Override Via Bundle
action.OverrideBundleAction.ViaBundleWrongCase.text=Action Text Override Via Bundle lower case
action.OverrideBundleAction.ViaBundleWrongCase.text=Action Text Override Via Bundle lower case
titleCaseKey=My Text
sentenceCaseKey=My key
@@ -48,5 +48,13 @@
<<warning descr="String 'Action Text Override Via Bundle lower case' is not properly capitalized. It should have title capitalization">override-text</warning> place="ViaBundleWrongCase"/>
<<warning descr="Missing resource bundle key 'action.OverrideBundleAction.ViaBundleMissingKey.text'">override-text</warning> place="ViaBundleMissingKey"/>
</action>
<!-- separator -->
<group id="separatorGroup">
<separator key="titleCaseKey"/>
<separator key="<warning descr="String 'My key' is not properly capitalized. It should have title capitalization">sentenceCaseKey</warning>"/>
</group>
</actions>
</idea-plugin>