/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jetbrains.idea.devkit.dom.impl;

import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.XmlPatterns;
import com.intellij.psi.PsiReferenceContributor;
import com.intellij.psi.PsiReferenceRegistrar;

/**
 * User: anna
 * Date: 10/7/11
 */
public class InspectionsPropertiesReferenceProviderContributor extends PsiReferenceContributor {

  private static final String[] EXTENSION_TAG_NAMES = new String[]{
    "localInspection", "globalInspection",
    "configurable", "applicationConfigurable", "projectConfigurable"
  };

  @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"))));
    registrar.registerReferenceProvider(pattern, new InspectionsKeyPropertiesReferenceProvider(false),
                                        PsiReferenceRegistrar.DEFAULT_PRIORITY);
  }
}
@@ -663,169 +663,688 @@
 lij.
-patterns.ElementPattern;%0Aimport com.intellij.patterns.XmlPatterns;%0Aimport com.intellij.psi.PsiReferenceContributor;%0Aimport com.intellij.psi.PsiReferenceRegistrar
+codeInsight.lookup.LookupElement;%0Aimport com.intellij.codeInsight.lookup.LookupElementBuilder;%0Aimport com.intellij.lang.properties.PropertiesFileProcessor;%0Aimport com.intellij.lang.properties.PropertiesReferenceManager;%0Aimport com.intellij.lang.properties.ResourceBundleReference;%0Aimport com.intellij.lang.properties.psi.PropertiesFile;%0Aimport com.intellij.openapi.util.Iconable;%0Aimport com.intellij.patterns.ElementPattern;%0Aimport com.intellij.patterns.XmlPatterns;%0Aimport com.intellij.psi.*;%0Aimport com.intellij.psi.search.GlobalSearchScope;%0Aimport com.intellij.util.ProcessingContext;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List
 ;%0A%0A/
@@ -1786,103 +1786,283 @@
 n = 
-Xml
+create
 Pattern
-s.xmlAttributeValue()%0A      .withParent(XmlPatterns.xmlAttribute().withLocalName(%22key
+(%22key%22, %22groupKey%22);%0A    registrar.registerReferenceProvider(pattern, new InspectionsKeyPropertiesReferenceProvider(false),%0A                                        PsiReferenceRegistrar.DEFAULT_PRIORITY);%0A%0A    ElementPattern bundlePattern = createPattern(%22bundle
 %22, %22
@@ -2070,317 +2070,1194 @@
 roup
-Key
+Bundle
 %22)
+;
 %0A    
-                .withParent(XmlPatterns.xmlTag().withName(EXTENSION_TAG_NAMES)%0A                                  .withSuperParent(2, XmlPatterns.xmlTag().withName(%22idea-plugin%22))));%0A    registrar.registerReferenceProvider(pattern, new InspectionsKeyPropertiesReferenceProvider(false),%0A              
+registrar.registerReferenceProvider(bundlePattern, new PsiReferenceProvider() %7B%0A      @NotNull%0A      @Override%0A      public PsiReference%5B%5D getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) %7B%0A        ResourceBundleReference reference = new ResourceBundleReference(element, false) %7B%0A          @NotNull%0A          @Override%0A          public Object%5B%5D getVariants() %7B%0A            PropertiesReferenceManager referenceManager = PropertiesReferenceManager.getInstance(myElement.getProject());%0A            final List%3CLookupElement%3E variants = new ArrayList%3CLookupElement%3E();%0A            referenceManager.processPropertiesFiles(GlobalSearchScope.projectScope(myElement.getProject()), new PropertiesFileProcessor() %7B%0A              public boolean process(String baseName, PropertiesFile propertiesFile) %7B%0A                variants.add(LookupElementBuilder.create(propertiesFile, baseName)%0A                               .withIcon(propertiesFile.getContainingFile().getIcon(Iconable.ICON_FLAG_READ_STATUS)));%0A                return true;%0A              %7D%0A            %7D, this);%0A            return variants.toArray(new LookupElement%5Bvariants.size()%5D);%0A
     
@@ -3258,32 +3258,34 @@
 ;%0A          
+%7D%0A
         
         PsiR
@@ -3268,32 +3268,35 @@
   %7D%0A        
+%7D;%0A
         
 PsiReference
@@ -3287,46 +3287,482 @@
     
-PsiReferenceRegistrar.DEFAULT_PRIORITY
+return new PsiReference%5B%5D%7Breference%7D;%0A      %7D%0A    %7D, PsiReferenceRegistrar.DEFAULT_PRIORITY);%0A  %7D%0A%0A  private static ElementPattern createPattern(String... attributeNames) %7B%0A    return XmlPatterns.xmlAttributeValue()%0A      .withParent(XmlPatterns.xmlAttribute().withLocalName(attributeNames)%0A                    .withParent(XmlPatterns.xmlTag().withName(EXTENSION_TAG_NAMES)%0A                                  .withSuperParent(2, XmlPatterns.xmlTag().withName(%22idea-plugin%22)))
 );%0A 

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