DevKit: support "bundle"|"groupBundle" resolving for supported extensions

This commit is contained in:
Yann Cébron
2013-05-23 21:18:08 +02:00
parent ea04cb1287
commit c439e415ca
@@ -15,10 +15,22 @@
*/
package org.jetbrains.idea.devkit.dom.impl;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.lang.properties.PropertiesFileProcessor;
import com.intellij.lang.properties.PropertiesReferenceManager;
import com.intellij.lang.properties.ResourceBundleReference;
import com.intellij.lang.properties.psi.PropertiesFile;
import com.intellij.openapi.util.Iconable;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.XmlPatterns;
import com.intellij.psi.PsiReferenceContributor;
import com.intellij.psi.PsiReferenceRegistrar;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.ProcessingContext;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* User: anna
@@ -33,11 +45,40 @@ public class InspectionsPropertiesReferenceProviderContributor extends PsiRefere
@Override
public void registerReferenceProviders(PsiReferenceRegistrar registrar) {
ElementPattern pattern = XmlPatterns.xmlAttributeValue()
.withParent(XmlPatterns.xmlAttribute().withLocalName("key", "groupKey")
.withParent(XmlPatterns.xmlTag().withName(EXTENSION_TAG_NAMES)
.withSuperParent(2, XmlPatterns.xmlTag().withName("idea-plugin"))));
ElementPattern pattern = createPattern("key", "groupKey");
registrar.registerReferenceProvider(pattern, new InspectionsKeyPropertiesReferenceProvider(false),
PsiReferenceRegistrar.DEFAULT_PRIORITY);
ElementPattern bundlePattern = createPattern("bundle", "groupBundle");
registrar.registerReferenceProvider(bundlePattern, new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
ResourceBundleReference reference = new ResourceBundleReference(element, false) {
@NotNull
@Override
public Object[] getVariants() {
PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(myElement.getProject());
final List<LookupElement> variants = new ArrayList<LookupElement>();
referenceManager.processPropertiesFiles(GlobalSearchScope.projectScope(myElement.getProject()), new PropertiesFileProcessor() {
public boolean process(String baseName, PropertiesFile propertiesFile) {
variants.add(LookupElementBuilder.create(propertiesFile, baseName)
.withIcon(propertiesFile.getContainingFile().getIcon(Iconable.ICON_FLAG_READ_STATUS)));
return true;
}
}, this);
return variants.toArray(new LookupElement[variants.size()]);
}
};
return new PsiReference[]{reference};
}
}, PsiReferenceRegistrar.DEFAULT_PRIORITY);
}
private static ElementPattern createPattern(String... attributeNames) {
return XmlPatterns.xmlAttributeValue()
.withParent(XmlPatterns.xmlAttribute().withLocalName(attributeNames)
.withParent(XmlPatterns.xmlTag().withName(EXTENSION_TAG_NAMES)
.withSuperParent(2, XmlPatterns.xmlTag().withName("idea-plugin"))));
}
}