mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DevKit: revert support for resolving Language IDs via resource bundle keys (IDEA-160387)
This commit is contained in:
@@ -38,6 +38,5 @@
|
||||
<orderEntry type="module" module-name="testFramework" />
|
||||
<orderEntry type="module" module-name="dom-impl" />
|
||||
<orderEntry type="module" module-name="devkit-jps-plugin" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="java-i18n" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -11,7 +11,6 @@
|
||||
<vendor>JetBrains</vendor>
|
||||
|
||||
<depends>com.intellij.properties</depends>
|
||||
<depends>com.intellij.java-i18n</depends>
|
||||
|
||||
<resource-bundle>org.jetbrains.idea.devkit.DevKitBundle</resource-bundle>
|
||||
|
||||
|
||||
@@ -17,19 +17,14 @@ package org.jetbrains.idea.devkit.dom.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionContributorEP;
|
||||
import com.intellij.codeInspection.dataFlow.StringExpressionHelper;
|
||||
import com.intellij.codeInspection.i18n.JavaI18nUtil;
|
||||
import com.intellij.codeInspection.i18n.folding.PropertyFoldingBuilder;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.lang.DependentLanguage;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.JavaConstantExpressionEvaluator;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScopesCore;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
@@ -191,28 +186,6 @@ class LanguageResolvingUtil {
|
||||
|
||||
@Nullable
|
||||
private static String getStringConstantExpression(PsiElement psiElement) {
|
||||
if (psiElement instanceof PsiMethodCallExpression) {
|
||||
final PsiExpression[] args = ((PsiMethodCallExpression)psiElement).getArgumentList().getExpressions();
|
||||
if (args.length > 0 && args[0] instanceof PsiLiteralExpression && args[0].isValid()
|
||||
&& PropertyFoldingBuilder.isI18nProperty((PsiLiteralExpression)args[0])) {
|
||||
final int count = JavaI18nUtil.getPropertyValueParamsMaxCount(args[0]);
|
||||
if (args.length == 1 + count) {
|
||||
IProperty property = PropertyFoldingBuilder.getI18nProperty((PsiLiteralExpression)args[0]);
|
||||
String text = property != null ? property.getValue() : null;
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 1; i < count + 1; i++) {
|
||||
Object value = JavaConstantExpressionEvaluator.computeConstantExpression(args[i], false);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
text = text.replace("{" + (i - 1) + "}", value.toString());
|
||||
}
|
||||
return text == null || text.equals(psiElement.getText()) ? text : text.replace("''", "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
final Pair<PsiElement, String> pair = StringExpressionHelper.evaluateConstantExpression(psiElement);
|
||||
return pair != null ? pair.second : null;
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import org.jetbrains.annotations.PropertyKey;
|
||||
|
||||
public class MyBundle {
|
||||
public static String message(@NotNull @PropertyKey(resourceBundle = BUNDLE) String key, @NotNull Object... params) {
|
||||
return ourInstance.getMessage(key, params);
|
||||
}
|
||||
|
||||
@NonNls
|
||||
private static final String BUNDLE = "MyBundle";
|
||||
private static final MyBundle ourInstance = new MyBundle();
|
||||
|
||||
private MyBundle() {
|
||||
super(BUNDLE);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
language.name=MyAnonymousLanguageWithNameFromBundleID
|
||||
@@ -1,8 +1,6 @@
|
||||
public class MyLanguage extends com.intellij.lang.Language {
|
||||
public static final com.intellij.lang.Language ANONYMOUS_LANUAGE = new MySubLanguage("MyAnonymousLanguageID", "MyDisplayName") {
|
||||
};
|
||||
public static final MyLanguage ANONYMOUS_LANUAGE_WITH_NAME_FROM_PROPERTIES = new MyLanguage(MyBundle.message("language.name")) {
|
||||
};
|
||||
|
||||
public MyLanguage() {
|
||||
super("MyLanguageID");
|
||||
|
||||
@@ -4,14 +4,11 @@
|
||||
<extensionPoints>
|
||||
<extensionPoint name="myLanguageEP" beanClass="MyLanguageAttributeEPBean"/>
|
||||
</extensionPoints>
|
||||
|
||||
<resource-bundle>MyBundle</resource-bundle>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.myPlugin">
|
||||
|
||||
<myLanguageEP language="My<caret>LanguageID"/>
|
||||
<myLanguageEP language="MyAnonymousLanguageID"/>
|
||||
<myLanguageEP language="MyAnonymousLanguageWithNameFromBundleID"/>
|
||||
|
||||
<myLanguageEP language="<error descr="Cannot resolve language with id ''INVALID_VALUE''">INVALID_VALUE</error>"/>
|
||||
|
||||
|
||||
@@ -257,8 +257,7 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
def lookupElements = myFixture.complete(CompletionType.BASIC).sort { it.lookupString }
|
||||
assertLookupElement(lookupElements[0], "MyAnonymousLanguageID", "MyLanguage.MySubLanguage")
|
||||
assertLookupElement(lookupElements[1], "MyAnonymousLanguageWithNameFromBundleID", "MyLanguage")
|
||||
assertLookupElement(lookupElements[2], "MyLanguageID", "MyLanguage")
|
||||
assertLookupElement(lookupElements[1], "MyLanguageID", "MyLanguage")
|
||||
}
|
||||
|
||||
private static void assertLookupElement(LookupElement element, String lookupString, String typeText) {
|
||||
@@ -273,22 +272,7 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
|
||||
"public class Language { " +
|
||||
" protected Language(String id) {}" +
|
||||
"}")
|
||||
myFixture.addClass("package org.jetbrains.annotations;\n" +
|
||||
"import java.lang.annotation.Documented;\n" +
|
||||
"import java.lang.annotation.ElementType;\n" +
|
||||
"import java.lang.annotation.Retention;\n" +
|
||||
"import java.lang.annotation.RetentionPolicy;\n" +
|
||||
"import java.lang.annotation.Target;\n" +
|
||||
"\n" +
|
||||
"@Documented\n" +
|
||||
"@Retention(RetentionPolicy.CLASS)\n" +
|
||||
"@Target({ElementType.PARAMETER, ElementType.LOCAL_VARIABLE, ElementType.FIELD})\n" +
|
||||
"public @interface PropertyKey {\n" +
|
||||
" String resourceBundle();\n" +
|
||||
"}")
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyLanguage.java"))
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyBundle.java"))
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyBundle.properties"))
|
||||
}
|
||||
|
||||
public void testIconAttribute() {
|
||||
|
||||
Reference in New Issue
Block a user