mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DevKit: show class name as a type text of language
This commit is contained in:
@@ -42,7 +42,7 @@ class LanguageResolvingConverter extends ResolvingConverter<LanguageResolvingUti
|
||||
return LookupElementBuilder.create(o.clazz, o.id)
|
||||
.withIcon(o.icon)
|
||||
.withTailText(o.displayName == null ? null : " (" + o.displayName + ")")
|
||||
.withTypeText(o.clazz.getQualifiedName(), true);
|
||||
.withTypeText(o.type, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -268,10 +268,14 @@ class LanguageResolvingUtil {
|
||||
final PsiClass clazz;
|
||||
final Icon icon;
|
||||
final String displayName;
|
||||
final String type;
|
||||
|
||||
LanguageDefinition(@NotNull String id, @NotNull PsiClass clazz, @Nullable Icon icon, @Nullable String displayName) {
|
||||
this.id = id;
|
||||
this.clazz = clazz;
|
||||
this.type = clazz instanceof PsiAnonymousClass
|
||||
? ((PsiAnonymousClass)clazz).getBaseClassReference().getQualifiedName()
|
||||
: clazz.getQualifiedName();
|
||||
this.icon = icon;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
public class MyLanguage extends com.intellij.lang.Language {
|
||||
public static final MyLanguage ANONYMOUS_LANUAGE = new MyLanguage("MyAnonymousLanguageID") {};
|
||||
public static final MyLanguage ANONYMOUS_LANUAGE_WITH_NAME_FROM_PROPERTIES = new MyLanguage(MyBundle.message("language.name")) {};
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
public MyLanguage(String ID) {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
private static class MySubLanguage extends com.intellij.lang.Language {
|
||||
private final String myName;
|
||||
|
||||
public MySubLanguage(final String id, @NotNull String name) {
|
||||
super(id);
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return myName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.myPlugin">
|
||||
|
||||
<myLanguageEP language="MyLanguageID"/>
|
||||
<myLanguageEP language="My<caret>LanguageID"/>
|
||||
<myLanguageEP language="MyAnonymousLanguageID"/>
|
||||
<myLanguageEP language="MyAnonymousLanguageWithNameFromBundleID"/>
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package org.jetbrains.idea.devkit.codeInsight
|
||||
import com.intellij.codeInsight.TargetElementUtil
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.codeInspection.xml.DeprecatedClassUsageInspection
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.PluginPathManager
|
||||
@@ -35,9 +37,7 @@ import com.intellij.util.xmlb.annotations.AbstractCollection
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.jetbrains.idea.devkit.inspections.PluginXmlDomInspection
|
||||
import org.jetbrains.idea.devkit.util.PsiUtil
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
|
||||
@TestDataPath("\$CONTENT_ROOT/testData/codeInsight")
|
||||
public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
|
||||
|
||||
@@ -233,7 +233,31 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
|
||||
myFixture.testHighlighting("extensionWithInnerTags.xml", "ExtBeanWithInnerTags.java");
|
||||
}
|
||||
|
||||
public void testLanguageAttribute() {
|
||||
public void testLanguageAttributeHighlighting() {
|
||||
configureLanguageAttributeTest()
|
||||
myFixture.testHighlighting("languageAttribute.xml", "MyLanguageAttributeEPBean.java")
|
||||
}
|
||||
|
||||
public void testLanguageAttributeCompletion() {
|
||||
configureLanguageAttributeTest()
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyLanguageAttributeEPBean.java"));
|
||||
myFixture.configureByFile("languageAttribute.xml")
|
||||
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
private static void assertLookupElement(LookupElement element, String lookupString, String typeText) {
|
||||
def presentation = new LookupElementPresentation()
|
||||
element.renderElement(presentation)
|
||||
assert presentation.itemText == lookupString
|
||||
assert presentation.typeText == typeText
|
||||
}
|
||||
|
||||
private void configureLanguageAttributeTest() {
|
||||
myFixture.addClass("package com.intellij.lang; " +
|
||||
"public class Language { " +
|
||||
" protected Language(String id) {}" +
|
||||
@@ -253,10 +277,7 @@ public class PluginXmlFunctionalTest extends JavaCodeInsightFixtureTestCase {
|
||||
"}")
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyLanguage.java"))
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyBundle.java"))
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyBundle.properties"));
|
||||
|
||||
myFixture.testHighlighting("languageAttribute.xml",
|
||||
"MyLanguageAttributeEPBean.java")
|
||||
myFixture.allowTreeAccessForFile(myFixture.copyFileToProject("MyBundle.properties"))
|
||||
}
|
||||
|
||||
public void testIconAttribute() {
|
||||
|
||||
Reference in New Issue
Block a user