/platform/lang-impl/src/com/intellij/refactoring/move/moveClassesOrPackages/CommonMoveUtil.java

https://bitbucket.org/nbargnesi/idea · Java · 46 lines · 40 code · 6 blank · 0 comment · 7 complexity · f5a0ad5181d04ff7c3eef71d09d3156e MD5 · raw file

  1. package com.intellij.refactoring.move.moveClassesOrPackages;
  2. import com.intellij.openapi.diagnostic.Logger;
  3. import com.intellij.psi.PsiElement;
  4. import com.intellij.psi.PsiReference;
  5. import com.intellij.refactoring.util.MoveRenameUsageInfo;
  6. import com.intellij.refactoring.util.NonCodeUsageInfo;
  7. import com.intellij.usageView.UsageInfo;
  8. import com.intellij.util.IncorrectOperationException;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.Map;
  12. public class CommonMoveUtil {
  13. private CommonMoveUtil() {
  14. }
  15. private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.move.moveClassesOrPackages.CommonMoveUtil");
  16. public static NonCodeUsageInfo[] retargetUsages(final UsageInfo[] usages, final Map<PsiElement, PsiElement> oldToNewElementsMapping)
  17. throws IncorrectOperationException {
  18. List<NonCodeUsageInfo> nonCodeUsages = new ArrayList<NonCodeUsageInfo>();
  19. for (UsageInfo usage : usages) {
  20. if (usage instanceof NonCodeUsageInfo) {
  21. nonCodeUsages.add((NonCodeUsageInfo)usage);
  22. }
  23. else if (usage instanceof MoveRenameUsageInfo) {
  24. final MoveRenameUsageInfo moveRenameUsage = (MoveRenameUsageInfo)usage;
  25. final PsiElement oldElement = moveRenameUsage.getReferencedElement();
  26. final PsiElement newElement = oldToNewElementsMapping.get(oldElement);
  27. LOG.assertTrue(newElement != null);
  28. final PsiReference reference = moveRenameUsage.getReference();
  29. if (reference != null) {
  30. try {
  31. reference.bindToElement(newElement);
  32. }
  33. catch (IncorrectOperationException e) {//
  34. }
  35. }
  36. }
  37. }
  38. return nonCodeUsages.toArray(new NonCodeUsageInfo[nonCodeUsages.size()]);
  39. }
  40. }