// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.groovy.refactoring.rename;

import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiMember;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.transformations.impl.DefaultRenameHelper;

public interface GrRenameHelper {

  ExtensionPointName<GrRenameHelper> EP_NAME = ExtensionPointName.create("org.intellij.groovy.renameHelper");

  /**
   * GrReferenceExpression may resolve to member generated by some AST Transformation from original member.
   * <p>
   * Example:
   * <pre>
   *   class A {
   *     def foo
   *   }
   *   new A().getFoo()
   * </pre>
   * {@code getFoo} references accessor method generated from original <i>foo</i> field.
   * Suppose we are renaming the field to <i>bar</i>.
   * Then {@code member} will be the referenced accessor method and {@code newOriginalName} is the new name of the field, i.e. <i>bar</i>.
   * Given this information {@link DefaultRenameHelper} returns the name of the new accessor
   * that will be generated after rename, i.e. <i>getBar</i>.
   *
   * @param member          currently resolved member.
   * @param newOriginalName new name of original member.
   * @return name of new member which will be generated after original member changes its name to {@code newOriginalName}.
   * @see DefaultRenameHelper
   */
  default @Nullable String getNewMemberName(@NotNull PsiMember member, @NotNull String newOriginalName) {
    return null;
  }

  /**
   * @param before element to which the reference resolved before rename
   * @param after  element to which the reference resolves after rename
   */
  default boolean isQualificationNeeded(@NotNull PsiManager manager, @NotNull PsiElement before, @NotNull PsiElement after) {
    return false;
  }
}
