/*
 * Copyright 2000-2010 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 com.intellij.refactoring.rename;

import com.intellij.openapi.extensions.Extensions;
import com.intellij.pom.PomTarget;
import com.intellij.pom.PomTargetPsiElement;
import com.intellij.pom.references.PomService;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiTarget;
import com.intellij.psi.targets.AliasingPsiTarget;
import com.intellij.psi.targets.AliasingPsiTargetMapper;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class RenameAliasingPomTargetProcessor extends RenamePsiElementProcessor {

  @Override
  public boolean canProcessElement(@Nullable PsiElement element) {
    return element instanceof PomTargetPsiElement;
  }

  @Override
  public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
    if (element instanceof PomTargetPsiElement) {
      for (AliasingPsiTargetMapper mapper : Extensions.getExtensions(AliasingPsiTargetMapper.EP_NAME)) {
        for (AliasingPsiTarget psiTarget : mapper.getTargets(((PomTargetPsiElement)element).getTarget())) {
          allRenames.put(PomService.convertToPsi(psiTarget), psiTarget.getNameAlias(newName));
        }
      }
    }
  }
}

@@ -854,43 +854,8 @@
 nt;%0A
-import com.intellij.psi.PsiTarget;%0A
 impo
@@ -1197,16 +1197,48 @@
   return
+ element instanceof PomTarget %7C%7C
  element
@@ -1387,24 +1387,53 @@
 lRenames) %7B%0A
+    PomTarget target = null;%0A
     if (elem
@@ -1466,24 +1466,202 @@
 iElement) %7B%0A
+      target = ((PomTargetPsiElement)element).getTarget();%0A    %7D%0A    else if (element instanceof PomTarget) %7B%0A      target = (PomTarget)element;%0A    %7D%0A%0A    if (target != null) %7B%0A
       for (A
@@ -1818,50 +1818,14 @@
 ets(
-((PomTargetPsiElement)element).getT
+t
 arget
-()
 )) %7B
@@ -1839,23 +1839,32 @@
     
-allRenames.put(
+PsiElement psiElement = 
 PomS
@@ -1893,17 +1893,41 @@
 iTarget)
-,
+;%0A          String name =
  psiTarg
@@ -1950,18 +1950,265 @@
 newName)
-)
 ;
+%0A%0A          String definedName = allRenames.put(psiElement, name);%0A          if (definedName != null) %7B%0A            assert definedName.equals(name);%0A          %7D%0A          else %7B%0A            prepareRenaming(psiElement, name, allRenames);%0A          %7D
 %0A       

Rename grails-fields with injected Spring bean on renaming spring bean.