IDEA-268982 Devkit: fallback to including plugin.xml's <resource-bundle>

GitOrigin-RevId: 1ea87c7b82aec98b88c7692fa06c0d35786a6640
This commit is contained in:
Yann Cébron
2021-05-10 13:58:01 +02:00
committed by intellij-monorepo-bot
parent 03ab9c17b7
commit df4f3f82da
4 changed files with 49 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2021 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.impl;
import com.intellij.lang.properties.BundleNameEvaluator;
@@ -10,13 +10,17 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.impl.include.FileIncludeManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.NullableFunction;
import com.intellij.util.ObjectUtils;
@@ -29,6 +33,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.dom.Actions;
import org.jetbrains.idea.devkit.dom.IdeaPlugin;
import org.jetbrains.idea.devkit.util.DescriptorI18nUtil;
import org.jetbrains.idea.devkit.util.DescriptorUtil;
import java.util.ArrayList;
import java.util.Collections;
@@ -122,7 +127,6 @@ class PropertyKeyReferenceProvider extends PsiReferenceProvider {
myFallbackBundleName = fallbackBundleName;
}
@Nullable
@Override
protected List<PropertiesFile> getPropertiesFiles() {
return retrievePropertyFilesByBundleName(myBundleName, getElement());
@@ -172,7 +176,21 @@ class PropertyKeyReferenceProvider extends PsiReferenceProvider {
if (DescriptorI18nUtil.canFallbackToCoreActionsBundle(actions)) {
return DescriptorI18nUtil.CORE_ACTIONS_BUNDLE;
}
return null;
// for single xi:include, use including descriptor's <resource-bundle>
final IdeaPlugin includingDescriptor = getSingleIncludingDescriptor(element);
return includingDescriptor == null ? null : includingDescriptor.getResourceBundle().getStringValue();
}
@Nullable
private static IdeaPlugin getSingleIncludingDescriptor(PsiElement element) {
final VirtualFile[] includingFiles =
FileIncludeManager.getManager(element.getProject()).getIncludingFiles(element.getContainingFile().getVirtualFile(), false);
if (includingFiles.length != 1) return null;
final PsiFile psiFile = element.getManager().findFile(includingFiles[0]);
if (!(psiFile instanceof XmlFile)) return null;
return DescriptorUtil.getIdeaPlugin(((XmlFile)psiFile));
}
}
}

View File

@@ -0,0 +1,6 @@
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude">
<resource-bundle>MyBundle</resource-bundle>
<xi:include href="/META-INF/messageBundleViaIncluding.xml"/>
</idea-plugin>

View File

@@ -0,0 +1,15 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<!-- bundle via messageBundleIncluding.xml -->
<intentionAction>
<categoryKey>my.key</categoryKey>
<className>com.intellij.codeInsight.intention.IntentionAction</className>
</intentionAction>
<intentionAction>
<categoryKey><error descr="Cannot resolve property key">INVALID_KEY</error></categoryKey>
<className>com.intellij.codeInsight.intention.IntentionAction</className>
</intentionAction>
</extensions>
</idea-plugin>

View File

@@ -111,6 +111,13 @@ class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
"MyBundle.properties", "AnotherBundle.properties")
}
void testMessageBundleViaIncluding() {
myFixture.copyFileToProject("messageBundleIncluding.xml", "META-INF/messageBundleIncluding.xml")
myFixture.copyFileToProject("messageBundleViaIncluding.xml", "META-INF/messageBundleViaIncluding.xml")
doHighlightingTest("META-INF/messageBundleViaIncluding.xml",
"MyBundle.properties")
}
void testExtensionsHighlighting() {
final String root = "idea_core"
addPluginXml(root, """