コード例 #1
0
  private void processUsagesPerFile(UsageInfo[] usages) {
    Map<PsiFile, List<EncapsulateFieldUsageInfo>> usagesInFiles =
        new HashMap<PsiFile, List<EncapsulateFieldUsageInfo>>();
    for (UsageInfo usage : usages) {
      PsiElement element = usage.getElement();
      if (element == null) continue;
      final PsiFile file = element.getContainingFile();
      List<EncapsulateFieldUsageInfo> usagesInFile = usagesInFiles.get(file);
      if (usagesInFile == null) {
        usagesInFile = new ArrayList<EncapsulateFieldUsageInfo>();
        usagesInFiles.put(file, usagesInFile);
      }
      usagesInFile.add(((EncapsulateFieldUsageInfo) usage));
    }

    for (List<EncapsulateFieldUsageInfo> usageInfos : usagesInFiles.values()) {
      // this is to avoid elements to become invalid as a result of processUsage
      final EncapsulateFieldUsageInfo[] infos =
          usageInfos.toArray(new EncapsulateFieldUsageInfo[usageInfos.size()]);
      CommonRefactoringUtil.sortDepthFirstRightLeftOrder(infos);

      for (EncapsulateFieldUsageInfo info : infos) {
        EncapsulateFieldHelper helper =
            EncapsulateFieldHelper.getHelper(info.getElement().getLanguage());
        helper.processUsage(
            info,
            myDescriptor,
            myNameToSetter.get(info.getFieldDescriptor().getSetterName()),
            myNameToGetter.get(info.getFieldDescriptor().getGetterName()));
      }
    }
  }
コード例 #2
0
  @NotNull
  protected UsageInfo[] findUsages() {
    ArrayList<EncapsulateFieldUsageInfo> array = ContainerUtil.newArrayList();
    for (FieldDescriptor fieldDescriptor : myFieldDescriptors) {
      for (final PsiReference reference : ReferencesSearch.search(fieldDescriptor.getField())) {
        final PsiElement element = reference.getElement();
        if (element == null) continue;

        final EncapsulateFieldHelper helper =
            EncapsulateFieldHelper.getHelper(element.getLanguage());
        if (helper != null) {
          EncapsulateFieldUsageInfo usageInfo =
              helper.createUsage(myDescriptor, fieldDescriptor, reference);
          if (usageInfo != null) {
            array.add(usageInfo);
          }
        }
      }
    }
    EncapsulateFieldUsageInfo[] usageInfos =
        array.toArray(new EncapsulateFieldUsageInfo[array.size()]);
    return UsageViewUtil.removeDuplicatedUsages(usageInfos);
  }