コード例 #1
0
  @NotNull
  @Override
  public Collection<PsiReference> findReferences(final PsiElement element) {
    if (element instanceof GrField) {
      ArrayList<PsiReference> refs = new ArrayList<PsiReference>();

      GrField field = (GrField) element;
      PsiMethod setter = GroovyPropertyUtils.findSetterForField(field);
      GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
      if (setter != null && setter instanceof GrAccessorMethod) {
        refs.addAll(
            RenameAliasedUsagesUtil.filterAliasedRefs(
                MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter));
      }
      GrAccessorMethod[] getters = field.getGetters();
      for (GrAccessorMethod getter : getters) {
        refs.addAll(
            RenameAliasedUsagesUtil.filterAliasedRefs(
                MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter));
      }
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              ReferencesSearch.search(field, projectScope, true).findAll(), field));
      return refs;
    }
    return super.findReferences(element);
  }
コード例 #2
0
  @NotNull
  @Override
  public Collection<PsiReference> findReferences(PsiElement element) {
    assert element instanceof GrField;

    ArrayList<PsiReference> refs = new ArrayList<>();

    GrField field = (GrField) element;
    GlobalSearchScope projectScope = GlobalSearchScope.projectScope(element.getProject());
    PsiMethod setter = field.getSetter();
    if (setter != null) {
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              MethodReferencesSearch.search(setter, projectScope, true).findAll(), setter));
    }
    GrAccessorMethod[] getters = field.getGetters();
    for (GrAccessorMethod getter : getters) {
      refs.addAll(
          RenameAliasedUsagesUtil.filterAliasedRefs(
              MethodReferencesSearch.search(getter, projectScope, true).findAll(), getter));
    }
    refs.addAll(
        RenameAliasedUsagesUtil.filterAliasedRefs(
            ReferencesSearch.search(field, projectScope, false).findAll(), field));
    return refs;
  }